I'm making a script with PHP 7.1 to send SMS with the Huawei E3531 usb modem. There is no documenation and I have a lot of difficulties to find the solution. This is the script to send the sms but I get an error 100002. First, I recuperate the token and the sessionid with curl and then I use curl again to post the sms
<?php
//send Sms
$curl = curl_init();
$url = "http://192.168.8.1/api/webserver/SesTokInfo";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($curl);
$xml = new simpleXMLElement($content);
$sess_id = $xml->SesInfo;
// echo $sess_id;
$tokInfo= $xml->TokInfo;
curl_close($curl);
$curl2 = curl_init('http://192.168.8.1/api/send-sms/');
$headers = array(
"X-Requested-With: XMLHttpRequest",
'Cookie:'. $sess_id,
'__RequestVerificationToken:'. $tokInfo,
'"Content-Type:text/xml"',
);
$data ="<request><Index>-1</Index><Phones><Phone>7777777</Phone></Phones><Sca/><Content>hello</Content><Length></Length><Reserved>1</Reserved><Date></Date></request" ;
//print_r($headers);
curl_setopt($curl2, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl2, CURLOPT_POST, true);
curl_setopt($curl2, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
echo $content = curl_exec($curl2);
curl_close($curl2);
However I've made another script to get the sms already sent and it does work. Here is the code:
<?php
//get session_id and token
$curl = curl_init();
$url = "http://192.168.8.1/api/webserver/SesTokInfo";
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($curl);
$xml = new simpleXMLElement($content);
$sess_id = $xml->SesInfo;
// echo $sess_id;
$tokInfo= $xml->TokInfo;
curl_close($curl);
//set boxtype to 2 for retrieve sent sms
$data="<request><PageIndex>1</PageIndex><ReadCount>10</ReadCount><BoxType>2</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>";
$curl2 = curl_init('http://192.168.8.1/api/sms/sms-list/');// A compléter
$headers = array(
'Cookie:'. $sess_id,
'__RequestVerificationToken:'. $tokInfo,
'Content-Type: application/x-www-form-urlencoded; charset=UTF-8',
);
//fetch sent sms
curl_setopt($curl2, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl2, CURLOPT_POST, true);
curl_setopt($curl2, CURLOPT_POSTFIELDS,$data);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($curl2);
echo $content;
curl_close($curl2);
$xml = new simpleXMLElement($content);
The 3 three steps used on this link (Sending and receiving SMS by command line with Huawei E3131 and HiLink on a debian system) to post sms on command line with the e3131 model (mine is e3531) worked for me but this is with command line. I can't answer on this thread because I'm new on this forum.
How can I fix this code?