Websterz Technology Blog

Free tutorials, Tech News, Source codes, Tweaks and Tips.

This tutorial explains calling of SOAP API with PHP code, there is also work around for the problems while accessing host URL.

This code is tested with PHP 5.6.x version and is working without any issue.

Create PHP file and paste following below code in it, save and you’re done.
In below code we are calling SMS SOAP API to send SMS’.

$opts = array(
		'ssl' => array('ciphers'=>'RC4-SHA', 'verify_peer'=>false, 'verify_peer_name'=>false)
	// SOAP 1.2 client, this is the work around for SOAP v1.2 to deal with ssl issues if you are getting unable to connect host or similar host connection error.

	$params = array ('encoding' => 'UTF-8', 'verifypeer' => false, 'verifyhost' => false, 'soap_version' => SOAP_1_2, 'trace' => 1, 'exceptions' => 1, "connection_timeout" => 180, 'stream_context' => stream_context_create($opts) ); //this is also work around for connecting with the ssl for PHP 5.6.x

	$soapClient = new SoapClient ( 'URL of the SOAP API .asmx' . "?WSDL", $params );

	//Use the functions of the client, the params of the function are in 
	////These are params available in SMS Soap api that can be sent, in your case use your own params and values.

	$params = array(
		'UserName' => 'Username of the API', 
		'Password' => 'Password of the API',
		'Message' => 'Test message by websterz.pk', 
		'Sender' => 'Websterz Web Solution', 
		'MSISDNs' => '1234567', 
		'SourceRef' => 10
	$response = json_encode($soapClient->SendSMS($params),true); // sending data to function SendSMS that is already available in SMS SOAP API, in your case you need to call your own functions and then save it into json array $response to get values for later use.

	$response = json_decode($response,true); //decode json array to get values from the array.

	$success = $response['SendSMSResult']['StatusDesc']; // this is the object extracted from the json array contains response description of the API Call.
	$statusCode = $response['SendSMSResult']['StatusCode']; //this is the object extracted from the json array contains status code of the API call.

Execute the code and you will receive response from the SOAP API in json format:

			'StatusDesc' : 'Success',
			'StatusCode' : '01'
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *