Is there a way that I can convert the received response into an array so I can validate whether or not the message was actually received or not by the sms software or am I missing something very obvious and simpler! I want to be able to validate certain values contained in the response back from the sms server, similar to the way I have shown in red in the code below.
It is important for me to know whether or not the message was actually accepted or not, I can't just blindly submit messages the way the code is at the moment for my particular application, so I need a way to verify certain values contained in the response string!
Here is the PHP for sending the sms and receiving a response from the sms server software:
Code: Select all
<?php
########################################################
# Login information for the SMS Gateway
########################################################
$ozeki_user = "admin";
$ozeki_password = "admin";
$ozeki_url = "http://127.0.0.1:9501/api?";
########################################################
# Functions used to send the SMS message
########################################################
function httpRequest($url){
$pattern = "/http...([0-9a-zA-Z-.]*).([0-9]*).(.*)/";
preg_match($pattern,$url,$args);
$in = "";
$fp = fsockopen("$args[1]", $args[2], $errno, $errstr, 30);
if (!$fp) {
return("$errstr ($errno)");
} else {
$out = "GET /$args[3] HTTP/1.1\r\n";
$out .= "Host: $args[1]:$args[2]\r\n";
$out .= "User-agent: Ozeki PHP client\r\n";
$out .= "Accept: */*\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
while (!feof($fp)) {
$in.=fgets($fp, 128);
}
}
fclose($fp);
return($in);
}
function ozekiSend($phone, $msg, $debug=false){
global $ozeki_user,$ozeki_password,$ozeki_url;
$url = 'username='.$ozeki_user;
$url.= '&password='.$ozeki_password;
$url.= '&action=sendmessage';
$url.= '&originator=5554443333';
$url.= '&messagetype=SMS:TEXT';
$url.= '&recipient='.urlencode($phone);
$url.= '&messagedata='.urlencode($msg);
$url.= '&responseformat=urlencoded';
$urltouse = $ozeki_url.$url;
if ($debug) { echo "Request: <br>$urltouse<br><br>"; }
//Open the URL to send the message
$response = httpRequest($urltouse);
if ($debug) {
echo "Response: <br><pre>".
str_replace(array("<",">"),array("<",">"),$response).
"</pre><br>"; }
//THIS IS WHAT I WOULD LIKE TO RETRIEVE (ALL IN RED)
[color=#FF0000]if ($response['acceptreport.statusmessage'] == 'Message+accepted+for+delivery') {
//do something here;
}else{
//do something else here
}[/color]
return($response);
}
########################################################
# GET data from sendsms.html
########################################################
$phonenum = $_POST['recipient'];
$message = $_POST['message'];
$debug = true;
ozekiSend($phonenum,$message,$debug);
?>And this is what is echoed to screen for sendsms.php:
Request:
http://127.0.0.1:9501/api?username=admi ... urlencoded
Response:
HTTP/1.1 200 OK
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
Content-Length: 329
Content-Type: text/xml
Last-Modified: Sat, 07 Nov 2009 17:10:47 GMT
Server: OzekiNG/3.14.1 Microsoft-HTTPAPI/1.0
Date: Sat, 07 Nov 2009 15:10:47 GMT
Connection: close
action=sendmessage&acceptreport.statuscode=0&acceptreport.statusmessage=Message+accepted+for+delivery&acceptreport.messageid=b20e32a6-74a7-4059-bfef-99a7d3561720&acceptreport.originator=5554443333&acceptreport.recipient=2223334444&acceptreport.messagetype=SMS%3aTEXT&acceptreport.messagedata=332&acceptreport.serviceprovider=vodaphone
Here is the original article on their website explaining the usage of the http api: http://www.ozekisms.com/index.php?owpn=327
The demo software can be downloaded from the same page from the menu at the top of the page... Any help will be highly appeciated!
Thanks
Grant