– Want to get a sms message when someone send a feedback on your website?
– Want to send a confirmation SMS when your user submit an order on your website?
– Want to send a notification SMS when your users order being delivered?
– Want to trigger an application when receive an incoming SMS message?

 

The answer to the above questions are SMS Gateway.

SMS gateway is an appliance or a software to interface with computer program or web site program, to forward the message to the users mobile phone through SMS messages.

Compare to email, SMS message is faster and more reliable way to communicate to your user.

 

sms_gateway
GT Notify SMS Gateway

HTTP API To Send Out SMS

The most simple way is using HTTP method, just a simple HTTP statement can trigger a SMS message to be sent out to the user’s mobile phone. This command can be triggered from the browser, or from a php script.

Example URL Request:

http://gtnotify_ip_address/index.php?md=smsapi&num=98764321&msg=helloworld&pass=xxxxxx
Field NameField Description
numPhone Number
msgMessage
passGT Notify password

Note: for the phone number with country code + in the url, the url needs to encode the + sign to %2B.

http://gtnotify_ip_address/index.php?md=smsapi&num=%2B6598764321&msg=helloworld&pass=xxxxxx

 

Web Hook ( Passing Incoming SMS to Other Applications)

From GT Notify system, user can configure web hook to let the GT Notify system to pass the received message information (in json format) to other applications through HTTP Post.

GT Web Hook

  • The Json data file have 3 fields: Date,  Phone,  Msg
  • The application should receive and process the Json data, following is an example php code for receiving the Json data, decode the content, and insert into the database.
  • The result will be written to system log file, so user can check the status of the transaction.

 

Sample PHP code to process the web hook Json data and insert into database.

<?php 
//define the database connection 
$host_name = ‘localhost’; 
$db_user = ‘xxxxx; 
$db_password = ‘xxxxxx’; 
$db_name = ‘xxxxxx’; 
$db_conn = mysqli_connect($host_name, $db_user, $db_password, $db_name); 

//receive the json data and decode the data into array $data 

$data = file_get_contents(“php://input”); $data = json_decode($data, True); 
//Insert $data[Date], $data[Phone], $data[Msg] into database 

$sql = “INSERT INTO gt_webhook (date, phone, msg) values (‘$data[Date]’,’$data[Phone]’,’$data[Msg]’)”; 
$ret = mysqli_query($db_conn,$sql); 
?>

API to add subscriber into GT Notify  (api_addsub_json)

Application can send the json file to GT Notify and create a GT subscriber directly.

GT Notify recognise the following json file format:

 

 

Field NameField Description
numSubscriber phone number
nameSubscriber name
gpGroup Name
fd1FD1 (flexible field)
fd2FD1 (flexible field)
fd3FD1 (flexible field)
fd4FD1 (flexible field)
noteNotes
passGT Notify Password

 

Sample code:


<?php
$url = "http://192.168.1.172/index.php?md=api_addsub_json";
$authToken = '123456';
$data = array(
 'name' => 'John Low',
 'num' => '844856230',
 'gp' => 'Retail',
 'fd1' => 'testing fd1',
 'fd2' => 'testing fd2',
 'fd3' => 'testing fd3',
 'fd4' => 'testing fd4',
 'note' => 'notes field',
 'pass' => 'Notify',
);

$data_string = json_encode($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
 'Content-Type:application/json',
 'Content-Length: ' . strlen($data_string) ,
 'API-TOKEN-KEY:'.$authToken )); // API-TOKEN-KEY is keyword so change according to ur key word. like authorization

// execute the request
//$output = curl_exec($ch);

echo $output;

// Check for errors
if($output === FALSE){
 die(curl_error($ch));
 $message = curl_error($ch);
 echo $message;
}

// close curl resource to free up system resources

curl_close($ch);
?>


API to send SMS using json file  (api_sendsms_json)

Application can send SMS through json file to GT Notify.

GT Notify recognise the following json file format:

Field NameField Description
dateScheduled Date
timeScheduled Time
numPhone Numbers separate by comma
msgMessage
intervalinterval seconds between each SMS send out
passGT Notify password

Sample code:


<?php
$url = "http://192.168.1.80/index.php?md=api_sendsms_json";
$data = array(
"date" => '',
"time" => '',
"num" => '96462561,96462562,96462563,96462564',
"msg" => 'Hello World!',
"interval" => '5',
"pass" => 'Notify');

// json encode data
$authToken = "12345678";
$data_string = json_encode($data);
// set up the curl resource
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type:application/json',
'Content-Length: ' . strlen($data_string) ,
'API-TOKEN-KEY:'.$authToken )); // API-TOKEN-KEY is keyword so change according to ur key word. like authorization

//execute the request
$output = curl_exec($ch);
//echo $output;
// Check for errors
if($output === FALSE){
die(curl_error($ch));
echo $curl_error($ch);
}
echo($output) . PHP_EOL;
// close curl resource to free up system resources
curl_close($ch);

<?php>