The recent period of time to contact the message platform more opportunities, think like the customer side of the message platform is made out of PHP, the heart itch then looked for information to learn, the code is as follows:
? Php
$flag = 0;
The data to post
$ARGV = Array (
' SN ' => ' sdk-bbx-010-xxxxx ',
' pwd ' => ' XXXXXX ',
' Mobile ' => ' 134338XXXXX ',//test cell phone number
' Content ' => ' How are you, test SMS '
);
Construct the string to post
foreach ($argv as $key => $value) {
if ($flag!=0) {
$params. = "&";
$flag = 1;
}
$params. = $key. " ="; $params. = UrlEncode ($value);
$flag = 1;
}
$length = strlen ($params);
Create a socket connection
$fp = Fsockopen ("sdk2.entinfo.cn", $errno, $errstr,) or exit ($ERRSTR.) ---> ". $errno);
To construct the header of a POST request
$header = "Post/z_send.aspx http/1.1\r\n";
$header. = "host:sdk2.entinfo.cn\r\n";
$header. = "referer:/mobile/sendpost.php\r\n";
$header. = "content-type:application/x-www-form-urlencoded\r\n";
$header. = "Content-length:". $length. " \ r \ n ";
$header. = "connection:close\r\n\r\n";
Add a Post string
$header. = $params. " \ r \ n ";
Send the Post data
Fputs ($fp, $header);
$inheader = 1;
while (!feof ($fp)) {
$line = fgets ($fp, 1024); Removing the header of the request package shows only the return data of the page
if ($inheader && ($line = "\ n" $line = = "\ r \ n")) {
$inheader = 0;
}
if ($inheader = = 0) {
Echo $line;
}
}
if ($line ==1)
{
Echo ' Message sent successfully please check the return value '. $line;
}else
{
Echo ' SMS send failed, please check the return value of the related error problem according to the returned value '. $line;
}
Fclose ($FP);