Send SMS Message Using Clickatell API - Part 7
After going through the first 6 parts of this tutorial, I realized I could do more to check the status of an sms message so i decided to add this part of the tutorial.
What this does is to check the status and charge of a message by your self just in case the callback url doesn’t give you the required feedback on time. Meaning this tutorial will help you to manual query the clickatell gateway to check the status of your sms message.
All you have to do is to create a page “status.php” and use the code below.
status.php
<?php
//*********************************************** //
// Send SMS Message Using Clickatell API - Part 7
// 23rd September 2007
// www.mboateng.com
// Michael Ofori Amanfo Boateng
//
//********************************************
echo “loading……”;
require_once(’settings.php’);
// auth call
$url = “http://api.clickatell.com/http/auth?user=$user”;
$url = $url.”&password=$password&api_id=$api_id”;
$ret = file($url);// split our response. return string is on first line of the data returned
$sess = split(”:”,$ret[0]);
$sess_id = trim($sess[1]);mysql_select_db($database_conn, $conn);
$result1 = mysql_query(”select * from tbl_outbox where status <> ‘004′ and dayofyear(now()) - dayofyear(dated) < 1 limit 10″,$conn);
$result2 = mysql_num_rows($result1);while ($mydata1 = mysql_fetch_array($result1)){
$messageid = $mydata1[’messageid’];
$api = trim($mydata1[’apimsgid’]);//////////////////////////////////////////////
/////////////////////////////////////////////
// check charge
$charge_url = “$baseurl/http/getmsgcharge?session_id=$sess_id”;
$charge_url = $charge_url.”&apimsgid=$api”;
$charge_return = file($charge_url);foreach($charge_return as $item){
$findapi = strpos($item, “apiMsgId:”);
$findcharge = strpos($item, “charge:”);
$findstatus = strpos($item, “status:”);$length = strlen($item);
//Find the apimsgid
$part1 = substr($item, $findapi,$findstatus );
$part2no = strpos($item, $part1);$api = trim(substr($item, $findapi,$findcharge ));
$status= trim(substr($item, $findstatus,$length ));
$charge= trim(substr($item, $findcharge, $findstatus - $findcharge ));//find charge
$ret = $charge;
$sess = split(”:”,$ret);
$charge = trim($sess[1]);//find status
$ret = $status;
$sess = split(”:”,$ret);
$status = trim($sess[1]);mysql_select_db($database_conn, $conn);
$sql = “update tbl_outbox set status = ‘$status’ , charge = ‘$charge’ where messageid =$messageid”;
$result = mysql_query($sql, $conn) or die(mysql_error());
}
}
mysql_free_result($result1);echo “Update Completed”;
?>
Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7















