title: Huawei e3531 usb modem - send sms with a PHP script
body: <p>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</p>
  
  <pre><code>&lt;?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-&gt;SesInfo;
  // echo $sess_id;
  $tokInfo= $xml-&gt;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 ="&lt;request&gt;&lt;Index&gt;-1&lt;/Index&gt;&lt;Phones&gt;&lt;Phone&gt;7777777&lt;/Phone&gt;&lt;/Phones&gt;&lt;Sca/&gt;&lt;Content&gt;hello&lt;/Content&gt;&lt;Length&gt;&lt;/Length&gt;&lt;Reserved&gt;1&lt;/Reserved&gt;&lt;Date&gt;&lt;/Date&gt;&lt;/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);
  </code></pre>
  
  <p>However I've made another script to get the sms already sent and it does work.
  Here is the code:</p>
  
  <pre><code>&lt;?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-&gt;SesInfo;
  // echo $sess_id;
  $tokInfo= $xml-&gt;TokInfo;
  curl_close($curl);
  
  //set boxtype to 2 for retrieve sent sms
  $data="&lt;request&gt;&lt;PageIndex&gt;1&lt;/PageIndex&gt;&lt;ReadCount&gt;10&lt;/ReadCount&gt;&lt;BoxType&gt;2&lt;/BoxType&gt;&lt;SortType&gt;0&lt;/SortType&gt;&lt;Ascending&gt;0&lt;/Ascending&gt;&lt;UnreadPreferred&gt;1&lt;/UnreadPreferred&gt;&lt;/request&gt;";
  
  $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);
  </code></pre>
  
  <p>The 3 three steps used on this link (<a href="https://stackoverflow.com/questions/38016641/sending-and-receiving-sms-by-command-line-with-huawei-e3131-and-hilink-on-a-debi">Sending and receiving SMS by command line with Huawei E3131 and HiLink on a debian system</a>) 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.</p>
  
  <p>How can I fix this code?</p>