<?php
ini_set('date.timezone','Asia/Taipei');
$cookie_txt = 'p:\bin\php56\sms.txt';
$curl = curl_init('http://192.168.8.1/api/webserver/SesTokInfo');
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_txt);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$r = curl_exec($curl);
curl_close($curl);
$xml = simplexml_load_string($r);
$token = $xml->TokInfo;
$session = $xml->SesInfo;
$username = 'admin';
$password = 'admin';
$data = '<?xml version "1.0" encoding="UTF-8"?><request><Username>admin</Username><Password>'.base64_encode(hash('sha256', $username.base64_encode(hash('sha256', $password, false)).$token, false)).'</Password><password_type>4</password_type></request>';
$curl = curl_init('http://192.168.8.1/api/user/login');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Cookie: '. $session,
'__requestverificationtoken: '. $token,
'x-requested-with: XMLHttpRequest',
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_HEADERFUNCTION,
function($curl, $header) use (&$headers)
{
$len = strlen($header);
$header = explode(':', $header, 2);
if (count($header) < 2) // ignore invalid headers
return $len;
$headers[strtolower(trim($header[0]))][] = trim($header[1]);
return $len;
}
);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($curl);
$info = curl_getinfo($curl);
curl_close($curl);
$content ="hello";
$lengContent = strlen($content);
$dateTime = date("Y-m-d H:i:s");
$data =<<<XML
<request>
<Index>-1</Index>
<Phones>
<Phone>0926756749</Phone>
</Phones>
<Sca></Sca>
<Content>$content</Content>
<Length>$lengContent</Length>
<Reserved>1</Reserved>
<Date>$dateTime</Date>
</request>
XML;
//connect with cURL
$curl = curl_init('http://192.168.8.1/api/sms/send-sms');
curl_setopt($curl, CURLOPT_HTTPHEADER, [
'Cookie: '. $headers['set-cookie'][0],
'__requestverificationtoken: '. $headers['__requestverificationtokenone'][0],
'x-requested-with: XMLHttpRequest',
'Content-Type: application/x-www-form-urlencoded'
]);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($curl);
$info = curl_getinfo($curl);
print_r($content);
curl_close($curl);