I saw everyone is participating in the GrameenPhone Aloashbei API contest and it’s began and I am late :P. So why not doing something that makes other’s life easy? So I decided to make a PHP class to do that job for you. You don’t need to know how to work with SOAP. Just instantiate a class, set the parameter and send, VOILA!!!
With the Aloashbei SMS API, you can send SMS, Check the SMS status and receive SMS. You can track location of any GP mobile number with the Location Locator API. It will provide you the longitude and latitude of the phone numbers current position. You can send MMS with the MMS API. You can charge any user who buys any content through the Charging API.
So we are going to build php class that will do these thing easily. Here I will built the SMS class. We can send SMS to any number and if it’s successful, it will return us a message ID. With this message ID, we can check the status of that sent message. To make a complete Aloashbei API class, we’ll first make a basic class and will extend it for other purposes. So here is the basic class that we will extend. It’ll hold the values for setting up the variables and will set user/password initially.
The file Structure:
- class.Aloashbei.php
- class.AloashbeiSMS.php
- sms.php
- includes/WebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl
[sourcecode language=”php”]
<?php
//file: class.Aloashbei.php
/**
* Main Aloashbei class that holds the variables
*
* @author Tareq Hasan
* @example http://tareq.weDevs.com
*/
class Aloashbei
{
/**
* This will contain the SOAP object
*
* @var object
*/
protected $soap;
/**
* This array will contain setup information
*
* @var array
*/
protected $auth = array();
/**
* This ID will be created by each developer during the registration process.
*
* @var string
*/
protected $registrationID;
/**
* Developer password
*
* @var string
*/
protected $password;
/**
* In “88017xxxxxxxx” format. Always will be developers registered MSISDN.
*
* @var string
*/
protected $sourceMsisdn;
/**
* Destination MSISDN number. The number will be in “88017xxxxxxxx” format.
*
* @var string
*/
protected $destinationMsisdn;
/**
* The following value should be populated in this parameter – 7424.
*
* @var integer
*/
protected $smsPort;
/**
* Message Type accroding to content.
*
* @var integer
*/
protected $msgType;
/**
* Charge amount for sending the SMS. Only whole numbers can be charged and
* the amount must be provided in double format (i.e 2.00).
*
* @var double
*/
protected $charge;
/**
* This must be the registered number of the developer.
* @var string
*/
protected $chargedParty;
/**
* The following value should be populated in this parameter – gpgp_psms.
*
* @var string
*/
protected $contentArea;
/**
* Actual message.
*
* @var string
*/
protected $msgContent;
/**
* Set’s user’s user id and password
*
* @param string $user_id registered user id
* @param string $password registered password
*/
function __construct($user_id, $password)
{
$this->registrationID = $user_id;
$this->password = $password;
}
}
?>
[/sourcecode]
We will extend that class to send SMS. Here is the SMS class that will extend the Aloashbei class
[sourcecode language=”php”]
<?php
//file: class.AloashbeiSMS.php
include_once ‘class.Aloashbei.php’;
/**
* Send, Receive and Check SMS status through GrameenPhone’s Aloashbei API
*
* @author Tareq Hasan
* @example http://tareq.weDevs.com
*/
class AloashbeiSMS extends Aloashbei
{
/**
* Constructor for setting up the class
*
* @param string $user_id registered user id
* @param string $password registered account password
* @param string $dev_phone test phone number
*/
function __construct($user_id, $password, $dev_phone)
{
parent::__construct($user_id, $password);
$this->sourceMsisdn = $dev_phone;
$this->smsPort = 7424;
$this->chargedParty = $dev_phone;
$this->contentArea = ‘gpgp_psms’;
$this->soap = new SoapClient(‘includes/WebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl’);
}
/**
* Set’s message parameters
*
* @param string $destination message destination phone number
* @param string $msg message content
* @param integer $type type of the message. e.g: 1 = ringtone, 2 = logo, 3 = wap push, 4 = text
* @param double $charge charge amount of the message
*/
public function setSMS($destination, $msg, $type, $charge)
{
$this->destinationMsisdn = $destination;
$this->msgContent = $msg;
$this->msgType = $type;
$this->charge = $charge;
$this->auth = array(
‘registrationID’ => $this->registrationID,
‘password’ => $this->password,
‘sourceMsisdn’ => $this->sourceMsisdn,
‘destinationMsisdn’ => $this->destinationMsisdn,
‘smsPort’ => $this->smsPort,
‘msgType’ => $this->msgType,
‘charge’ => $this->charge,
‘chargedParty’ => $this->chargedParty,
‘contentArea’ => $this->contentArea,
‘msgContent’ => $this->msgContent
);
}
/**
* Sends the short message
*
* @return object send status information: status, msgID
*/
public function send()
{
$result = $this->soap->sendSMS(array(‘SendSMSRequest’ => $this->auth));
return $result;
}
/**
* Retreive SMS with message ID
*
* @param string $msg_id sent message id
* @return object received sms details: msgID, senderMSISDN, timeStamp, sourcePort, msgContent
*/
public function getSMS($msg_id)
{
$this->auth = array(
‘registrationID’ => $this->registrationID,
‘password’ => $this->password,
‘smsPort’ => $this->smsPort,
‘msgID’ => $msg_id
);
$result = $this->soap->getReceivedSMS(array(‘ReceiveSMSRequest’ => $this->auth));
return $result;
}
/**
* Retrieve the SMS’s current status
*
* @param string $msg_id sent message id
* @return object status sms details: deliveryStatus
*/
public function getStatus($msg_id)
{
$this->auth = array(
‘registrationID’ => $this->registrationID,
‘password’ => $this->password,
‘msgID’ => $msg_id
);
$result = $this->soap->getSMSDeliveryStatus(array(‘SMSStatusRequest’ => $this->auth));
return $result;
}
}
?>
[/sourcecode]
Preparing the WSDL file:
I have placed the main soap file “WebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl” to the “/includes” folder. You can grab the file from here. Be fore using that SMS WSDL file, you need to change 2 lines from that file.
- At first save the WSDL file, then go to the bottom of that file. Replace “http://192.168.100.169/API/GP.ADP.BizTalk.SMS.Orchestrations/WebService_GP_ADP_BizTalk_SMS_Orchestrations.asmx” by “https://www.aloashbei.com.bd/API/GP.ADP.BizTalk.SMS.Orchestrations/WebService_GP_ADP_BizTalk_SMS_Orchestrations.asmx“.
- Then save the file. The location of the file will be “includes/WebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl”.
So you are done to setup all the things. It’s time to send free SMS, but wait, don’t hurry, there is a limitation for sending SMS 😉
Working with the Class:
Lets create a page “sms.php”.
[sourcecode language=”php”]
//file: sms.php
include_once ‘class.AloashbeiSMS.php’;
$user_id = ‘*******’; //your registered user id
$password = ‘********’; // your account password
$dev_phone = ‘88017********’; //your registered phone number
$destination = ‘88017********’; // destination phone number
$msg = ‘Test sms message from GP Aloashbei API’; //message to send
$type = 4; //type of the message. e.g: 1 = ringtone, 2 = logo, 3 = wap push, 4 = text
$charge = 0.00; //sms charge
//setup constructor
$sms = new AloashbeiSMS($user_id, $password, $dev_phone);
//setup sms
$sms->setSMS($destination, $msg, $type, $charge);
//send sms
$result = $sms->send();
if ($result->SendSMSResponse->status == ‘OK’)
{
echo ‘<h2>Message Sent</h2>’;
echo ‘Message ID: ‘ . $result->SendSMSResponse->msgID;
echo ‘<hr>’;
}
else
{
echo "<h1>" . $result->SendSMSResponse->status . "</h1>";
}
[/sourcecode]
If you are familiar with PHP and OOP, you know whats is going, right? 😛
If we are successful to send sms, it will print the sent message ID, otherwise it will show the error message came through the API.
Now, if we need to check the status of the message, we can do it very simply. Here is the complete code –
[sourcecode language=”php”]
include_once ‘class.AloashbeiSMS.php’;
$sms = new AloashbeiSMS($user_id, $password, $dev_phone);
$status = $sms->getStatus($msg_id);
echo ‘Status: ‘ . $status->SMSStatusResponse->deliveryStatus;
[/sourcecode]
I am not clear about the receive message service usage, but yeah, although you can still do that with this class 😀
[sourcecode language=”php”]
include_once ‘class.AloashbeiSMS.php’;
$sms = new AloashbeiSMS($user_id, $password, $dev_phone);
$receive = $sms->getSMS($msg_id);
echo ‘Sender: ‘ . $receive->ReceiveSMSResponse->senderMSISDN . ‘<br>’;
echo ‘Timestamp: ‘ . $receive->ReceiveSMSResponse->timeStamp . ‘<br>’;
echo ‘Source Port: ‘ . $receive->ReceiveSMSResponse->sourcePort . ‘<br>’;
echo ‘Message: ‘ . $receive->ReceiveSMSResponse->msgContent . ‘<br>’;
[/sourcecode]
May be I’m not good to describe codes, but this post might help you 🙂
Resources:
ভালোই তো। আমার মোবাইলে একটা sms পাঠান তো দেখি। 😀
তোমার মোবাইল থেকে আমার মোবাইলে আগে একটা মেসেজ পাঠাও 😛
http://masnun.com/aloashbei/ — REST APIs.
You don’t need to know SOAP in the first place 😛
Great job, bro! Share in the AA forum if you haven’t already!
You have done a great job 🙂
Will share it to AA forum indeed
Interesting post…thanks tareq bhai…keeping it up
Thanks Tareq vai,
For these codes.
Actually i am newbie in OOP. So i have a little question. 😉
in your ‘class.Aloashbei.php’ file you have made all the properties protected.
But suppose i want to make them Private. Is there any problem if i do so ?
private: No access from outside the class, either by the script or from another class.
protected: No access from outside except from a class that is a child of the class with the protected attribute or method.
That means if you make the variable private, you can’t access them from the child class. That’s why it’s protected. Does that makes sense?
Hmm. Thanks…
ভাইয়া, এই লাইনটা সম্পর্কে একটু বিস্তারিত বলবেন?
মানে কোন অনলাইন শপিং এর জন্য এটা সেটআপ করা সম্ভব, নাকি শুধু মোবাইল কন্টেন্ট এর জন্য?
চার্জ করার পর সেই চার্জটা কিভাবে কোথায় জমা হবে?
ধন্যবাদ। সাইটটা খুব ভালো লাগলো। এখন থেকে ফলো করবো নিয়মিত। ধন্যবাদ
এইটা দিয়ে এই ধরনের কাজ করা যাবে। কিন্তু প্ব়্যাকটিকালি এখনো কিছু দেয়নি গ্রামীণফোন।
Vai
I am new in this track, i follow your steps but find the following error:
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t find in ‘G:xampphtdocssend_smsincludesWebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl’ in G:xampphtdocssend_smsclass.AloashbeiSMS.php:30 Stack trace: #0 G:xampphtdocssend_smsclass.AloashbeiSMS.php(30): SoapClient->SoapClient(‘includes/WebSer…’) #1 G:xampphtdocssend_smssms.php(14): AloashbeiSMS->__construct(‘theKamrul’, ‘******’, ‘*******’) #2 {main} thrown in G:xampphtdocssend_smsclass.AloashbeiSMS.php on line 30
1. i put the WebService_GP_ADP_BizTalk_SMS_Orchestrations.wsdl in the includes directory.
plz help me
thanks
Did you changed the wsdl file correctly?
yes i have change the two lines u said earlier, thanks for your reply
Thanks for your script.
I have a question. In where i do registered. In send.php file there have some requirement of registration related. Please give the registered website. I already registered into http://www.aloashbei.com.bd/ . But here have no user_id. Please give details info.
Finally i success to send the sms. But i need to send long sms. where have the max char limition, i didn’t find it. I tested one sms by sending long sms , give me error msg “ERROR ! SMS Content Length Exceed max char “.
How i solve this.
Thanks
Usually SMS’s are 160 character long. So you can’t send more than 160 character.
This script is only send sms into gp sim , other opertator(banglalink, airtell, citycell ..so on) it shows invalid mobile number. Is it possible using this api to send sms into all operator.
Thanks
Nope, GP doesn’t support sending SMS/MMS to other operators via this API
You have any idea that how send sms to all operator .
Thanks
I need web developer who expert in grameenphone/banglalink/warid/robi charging API.i have a product selling website where i use this charging API so that bangladeshi user can pay with their mobile, for buy product on my website.any interested developer can direct mail me to my mailbox.surely i can reaply and contact with you.
thank u.
Regards-Ankita Sarma
Ceo And founder
Outsourcerzone India Ltd.
Hello Ankita, grameenphone/banglalink/warid/robi doesn’t provide any public API for charging for contents right now. So it’s not possible without contracting the operators itself.
i am not telling you public API for general purpose.we have all legal doccument for a private company in bangladesh.but now i want to know that how can i contract with this company.our buiseness admins were contact with grameenphone by mail.but they didnot give us any reaply.our buiseness partner stay near dhaka.but they didnot get such way to get it.actually a technician person is need for this operation as well.please reaply me what can we do?
Sorry, I can’t help you this way either. I am an individual person also and I am not affiliated or connected to any operators. So nothing I can do. I just wrote the class for more easier usage according to their developer API they released.
@ ankita sarma, i hope i can help u. if u r interested plz contact with me. this needs to contact with all operators. i am in a vendor.so i think it will be easier for me. i am also interested to do such project.
[email protected]