Sample GP SMS API Use With PHP

Below there is a sample code of using GP SMS Api with PHP.

<?php
function send_sms($mobile_no, $text) {
//creating a soap client
$soap=new SoapClient(“SMS WSDL.wsdl”);
//setting the variables of SendSMSRequest type
$req_vars=array(
“registrationID”    =>  “YOUR USER ID”,
“password”          =>  “YOUR PASSWORD”,
“sourceMsisdn”      =>  “88017********”,
“destinationMsisdn” =>  “88”.$mobile_no,
“smsPort”           =>  7424,
“msgType”           =>  4,
“charge”            =>  0.00,//If you want you can give some value, but if you are charged, I’m not responsible for that 😛
“chargedParty”      =>  “88017********”,
“contentArea”       =>  “gpgp_psms”,
“msgContent”        =>  $text,
);
//The request variable
$request=array(“SendSMSRequest”=>$req_vars);
//requesting now to send sms
$response=$soap->sendSMS($request);
return $response;
}

?>
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>GP SMS Api Testing</title>
</head>
<body>
<pre>
<?php
//calling the function
$phone_no=”017********”;
$text=”Hi people! Just testing out! :-)”;
$response=send_sms($phone_no, $text);
print_r($response);
?>
</pre>
</body>
</html>

P.S. : If you get any SSL related error, go to your php.ini file,find out

“;extension=php_openssl.dll”

then delete the ; from the beginning

Update : A new updated post (with updated code) in this link: http://blog.muktosource.com/enzam/send-sms-example-with-gp-aloashbei-api-php.html

Advertisements

How To Make GP API Calls From Java Using Netbeans

How To Make GP API Calls From JAVA (Netbeans)

IDE : Netbeans 6.8(Will work on 6.7+ i hope)

1. First Create A New Java Desktop Application(File -> New Project -> Java -> Java Desktop Application). click next, give it a suitable name (eg Test), click finish.

Adding The WSDL:

1. Goto https://www.aloashbei.com.bd/API/GP.ADP.BizTalk.LBS.Orchestration/WebService_GP_ADP_BizTalk_LBS_Orchestration.asmx?wsdl. Save the page locally.

2. Then edit the 86th & 89th line. The new lines will be –

Line 86 :

<soap:address location=”https://www.aloashbei.com.bd/API/GP.ADP.BizTalk.LBS.Orchestration/WebService_GP_ADP_BizTalk_LBS_Orchestration.asmx”/&gt;

Line 89 :

<soap12:address location=”https://www.aloashbei.com.bd/API/GP.ADP.BizTalk.LBS.Orchestration/WebService_GP_ADP_BizTalk_LBS_Orchestration.asmx”/&gt;

3. Now go to Netbeans. In the Projects explorer(If you can’t find it, press Ctrl+1 or Window->Projects), select the new Project, right click it. Go to New->Other. Select Web Services from categories, select Web Service Client. Press Next. Select Local File: and set the locally saved file as the location. Click Finish

You are done adding the WSDL :-).

2. Design view will come up. Take a label from the Pallete(if you can’t find pallete you can press ctrl+shift+8 or go to Window->Pallete) and put it in the form. Then take a textfield and put it beside it. Now the view should be something like this

3. Change the jLabel1 text to “Please Enter The Mobile No: 017” and jTextField1’s Text to “xxxxxxxx”.

4. Select jTextField1, press right button, goto Events->Action->actionPerformed.

5. Write this code in the actionPerformed function:

WebServiceGPADPBizTalkLBSOrchestration service = new WebServiceGPADPBizTalkLBSOrchestration();

WebServiceGPADPBizTalkLBSOrchestrationSoap port = service.getWebServiceGPADPBizTalkLBSOrchestrationSoap();

LBSRequest req = new LBSRequest();

req.setRegistrationID(“YOUR ID”);

req.setPassword(“YOUR PASS”);

req.setMsisdn(“88017″+jTextField1.getText());

LBSResponse res = port.requestLocation(req);

String response =

“Status = ” + res.getStatus()+”\n”+

“Latitude = ” + res.getLatitude()+”\n”+

“Longitude = ” + res.getLongitude()+”\n”+

“Time = ” + res.getTimestamp()+”\n”;

System.out.print(response);

JOptionPane.showMessageDialog(null, response);

6. Import these classes:

import
com.grameenphone.playground.WebServiceGPADPBizTalkLBSOrchestration;

import
com.grameenphone.playground.WebServiceGPADPBizTalkLBSOrchestrationSoap;

import
lbsresponse.schemas.lbs.biztalk.adp.gp.LBSResponse;

import
lbsrequest.schemas.lbs.biztalk.adp.gp.LBSRequest;

import javax.swing.JOptionPane;

7. Now execute with F6. This should show a prompt for mobile no, write it down, and press Enter.

8. Hopefully after some time you will get the result printed on console and in a dialog.

Happy coding 🙂