SI-PHP Application
For using SI API PHP client in your project, you have to add the following file to your project file:, (*1)
src/main/php/api/Sms.php
or recommended to use composer to install the library., (*2)
$ composer require si/si-api-php
The first thing that needs to be done is to include Sms.php
and to initialize the messaging client. Before you start any of the examples, you have to populate specific data (API Key, SenderID, Base Url) by instantiate Sms rest client class object., (*3)
require_once '<PATH-TO-FOLDER>/Sms.php'; $smsObj = new Sms(<Api_key>, <sender_id>, <base_url>);
After including Sms.php
and to initialize the messaging client you need to follow the function below:, (*4)
The first step is to prepare the message:, (*5)
$msg = <your_message_comes_here>;
Then next step is to prepare your contact list:, (*6)
$receivers = <receiver_number1,receiver_number2>;
Receiver Mobile number to which SMS needs to be sent. It can be with or without 91. Also provide multiple numbers in comma separated format., (*7)
Now you are ready to send the message:, (*8)
$response = $smsObj->sendSms($receivers, $msg);
We can give optional parameter for different kinds of functionality, has explained below:, (*9)
Schedule Sms :- We have to provide Date and time for scheduling an SMS, (*10)
$response = $smsObj->sendSms($receivers , $msg , [ 'time' => '2017-05-19 11:17:55 AM', ]);
Unicode Messgae :- To specify that the message to be sent is in unicode format. Also can be used for automatic detection of unicode SMS., (*11)
$response = $smsObj->sendSms($receivers , $msg , [ 'unicode' => '1', ]);
Flash Message :- To specify that the message is to be sent in the flash format, (*12)
$response = $smsObj->sendSms($receivers , $msg , [ 'flash' => '1', ]);
Receive Delivery Report Url :- The encoded URL to receive delivery reports. Spiffing custom in the DLR url is mandatory., (*13)
$drl_url = 'http://exapmle.com?sent={sent}&delivered={delivered}&msgid={msgid}&sid={sid}&status={status}&reference={reference}&custom1={custom1}&custom2={custom2}'; $response = $smsObj->sendSms($receivers , $msg , [ 'dlr_url' => $dlr_url, ]);
Format :- Output format should be as specified by this variable ex.-XML/JSON/JSONP. Default response will be in JSON, (*14)
$response = $smsObj->sendSms($receivers , $msg , [ 'format' => 'json', ]);
Custom1 & Custom2 :- Custom reference fields., (*15)
$response = $smsObj->sendSms($receivers , $msg , [ 'custom1' => 'xxxxxxx', 'custom2' => 'xxxxxxx' ]);
Port :- Port number to which SMS has to be sent. Valid integer port number above 2000, (*16)
$response = $smsObj->sendSms($receivers , $msg , [ 'port' => '8223', ]);
SMS can be sent using the JSON Data by posting values to the preceding URL by the POST method with urlencoded json data., (*17)
Sample json data, (*18)
$jsonData = {"sms": [ { "to": "9xxxxxxxx", "custom": 9xxxxxxxx, "message": "Message from json api node 1" }, { "to": "91xxxxxxxx", "custom": 34, "message": "Message from json api node 2" } ] } $response = $smsObj->sendSmsUsingJsonApi($jsonData,['formate'=>'json']);
JSON Optional Parameters, (*19)
Sending to multiple numbers with same message, (*20)
$jsonData = { "message": "test json", "sms":[ { "to": "95XXXXXXXX", "msgid": "1", "message": "test sms", "custom1": "11", "custom2": "22", "sender": "AAAAAA" }, { "to": "99XXXXXXXX", "msgid": "2", "custom1": "1", "custom2": "2" }], "unicode": 1, "flash": 1, "dlrurl": "http://www.example.com/dlr.php" }
Sending to multiple numbers with different message, (*21)
$jsonData = { "message": "test json", "sms":[ { "to": "95XXXXXXXX", "msgid": "1", "message": "test sms", "custom1": "11", "custom2": "22", "sender": "AAAAAA" }, { "to": "99XXXXXXXX", "msgid": "2", "message": "json test sms", "custom1": "1", "custom2": "2" }], "unicode": 1, "flash": 1, "dlrurl": "http://www.example.com/dlr.php" }
SMS can be sent using the XML values by posting values to the preceding functions., (*22)
$xml = <?xml version="1.0" encoding="UTF-8"?> <xmlapi> <sender>AAAAAA</sender> <message>xml test</message> <unicode>1</unicode> <flash>1</flash> <campaign>xml test</campaign> <dlrurl> <![CDATA[http://domain.com/receive?sent={sent}&delivered={delivered}&msgid={msgid}&sid={sid}&status={status}&reference={reference} &custom1={custom1}&custom2={custom2}&credits={credits}]]> </dlrurl> <sms> <to>95xxxxxxxx</to> <custom>22</custom> <custom1>99</custom1> </sms> <sms> <to>99xxxxxxxx</to> <custom>229</custom> <custom1>995</custom1> </sms> </xmlapi> $response = $smsObj->sendSmsUsingXmlApi($xml,['formate'=>'json']);
Sending to multiple numbers with same message, (*23)
$xml = <?xml version="1.0" encoding="UTF-8"?> <api> <campaign>campaign</campaign> <dlrurl> <![CDATA[http://domain.com/receive?msgid={msgid}&sid={sid}&status={status}&custom1={custom1}]]> </dlrurl> <time>2014-12-26 04:00pm</time> <unicode>0</unicode> <flash>0</flash> <sender>senderid</sender> <message><![CDATA[smstext]]></message> <sms> <to>9190********</to> </sms> <sms> <to>9191********</to> </sms> </api>
Sending to multiple numbers with different message, (*24)
$xml = <api> <campaign>campaign</campaign> <time>2014-12-26 04:00pm</time> <unicode>0</unicode> <flash>0</flash> <sms> <to>9190********</to> <sender>senderid</sender> <message>smstext</message> <custom>2</custom> <dlrurl> <![CDATA[http://domain.com/receive?msgid={msgid}&sid={sid}&status={status}&custom1={custom1}]]> </dlrurl> </sms> <sms> <to>9191********</to> <sender>senderid</sender> <message><![CDATA[smstext]]></message> <custom>2</custom> <dlrurl> <![CDATA[http://domain.com/receive?msgid={msgid}&sid={sid}&status={status}&custom1={custom1}]]> </dlrurl> </sms> </api>
To check status of any sent SMS campaign, you must have message id only (not group ID) of the respective message(s). You can only check status for messages which have been sent on the same day. If using POST method for pulling messages status, then statuses for maximum 500 messages can be pulled at a time. Here is a function for checking the status of an SMS in the following format:, (*25)
$statusResponse = $smsObj->smsStatusPull("fe5a70a3-1d65-40de-93b3-e50ebdc69272:1",['formate'=>'json']);
Optional parameter, (*26)
Format :- Output format should be as specified by this variable, XML/JSON/JSONP. Default response will be in JSON., (*27)
Numberinfo :- Flag to query service provider and location data, i.e 0 or 1., (*28)
Page :- Page number to fetch status details of a pariticular page, where page is 1 or more., (*29)
To send an SMS to an optin group,one must create a optin group and keyword associated with it in your account. Also, need to add numbers for those optin keywords to a group i.e. optin group., (*30)
Mandatory Parameters, (*31)
Optional Parameters, (*32)
callback :- Callback function for JSONP response format, i.e String, (*33)
$response = $smsObj->smsToOptinGroup($msg, $optinId, ['time' => '2017-06-11 11:17:55 AM', 'unicode' => '1', 'flash' => '1', 'formate'=>'json']);, (*34)
In your account, there must be an existing group and numbers under that group to send any message to a group. API for sending a simple message to a group is in the following format., (*35)
$response = $smsObj->sendMessageToGroup($msg, $name , $group_id);
Optional Parameters, (*36)
Mandatory Parameters, (*37)
First, you need to create a group in your account only then you can add contact to an existing valid group. Function for adding contact to a group will be parameterised in the following format., (*38)
$response = $smsObj->addContactsToGroup( $name , $receiverNumber ,['fullname'=>'abc','formate'=>'json']);
Mandatory Parameters, (*39)
groups.register
Optional Parameters, (*40)
add/delete
. Add action is DefaultApplication must have a scheduled SMS campaign to further modify it and also must save a Group ID of an SMS campaign to be rescheduled. In order to edit a scheduled slot, there should a minimum gap of 5mins before its execution. Parameter for an Edit schedule sms slot will be in the following format:, (*41)
$response = $smsObj->editSchedule( $new_time , $group_id ,['formate'=>'json']);
Mandatory Parameters, (*42)
sms.schedule
modify
Optional Parameters, (*43)
Expected API Error Codes, (*44)
A431 Invalid Group ID A434 Campaign within next 5 minutes cannot be modified/cancelled.
Application must have a scheduled SMS campaign to further modify it and also must save a Group ID of an SMS campaign to be deleted. In order to delete a scheduled slot, there should a minimum gap of 5mins before its execution. Parameter for deleting an SMS campaign that is already scheduled is in the following format:, (*45)
$response = $smsObj->deleteScheduledSms($group_id ,['formate'=>'json']);
Mandatory Parameters, (*46)
sms.schedule
.This function can also be used to check the credits in your our account which can be in the following format:, (*47)
$response = $smsObj->creditAvailabilityCheck(['formate'=>'json']);
Mandatory Parameters, (*48)
account.credits
Optional Parameters, (*49)
To look information about any number, one must put country code along with number. Function for performing a lookup for specific numbers is in the following format:, (*50)
$response = $smsobj->SILookup($mobile_number, ['format' => 'json']);
Mandatory Parameters, (*51)
lookup
Txtly is basically a shortened URL which can be used in text messages so that SMS would not exceed the characters. Function to create a Txtly link is as follows:, (*52)
$response = $smsObj->createtxtly("https://facebook.com/xyz/lmn/abc",['format' => 'json']);
Mandatory Parameters, (*53)
Optional Parameters, (*54)
Callback Parameters to be used in URL, (*55)
156.151.23.65
http://example.com/over/there?name=ferret
msie
11.0
English
Trident
1024*768
Android OS
5.0
phone
Motorola
XT1068
HTC Dream
12.9667° N
77.5667° E
India
Karnataka
Bangalore
1426243175
99XXXXXXXX
(AN)
for Android'Expected Error Codes, (*56)
One must have a txtly id to delete it from database. Here is a function to delete a Txtly link:, (*57)
$response = $smsObj->deletetxtly("205XXX",['format' => 'json']);
Mandatory Parameters, (*58)
txtly
delete
123XXXX
1
Optional Parameters, (*59)
Function to Pull logs for all txtly shortened links in your account:, (*60)
$response = $smsObj->txtlyReportExtract(['format' => 'json']);
Mandatory Parameters, (*61)
txtly
1
Optional Parameter, (*62)
Here is an function to pull logs for individual txtly from our account:, (*63)
$response = $smsObj->pullLogForIndividualtxtl("223XXX",['format' => 'json']);
Mandatory Parameters, (*64)
txtly.logs
1
123XXXXX
This library is licensed under the Apache License, Version 2.0, (*65)