SMS Platform PHP code a little Pass

Source: Internet
Author: User
Tags header key php code return string

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);



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.