There have been many opportunities to access the text messaging platform in recent times. It seems that the customer's text messaging platform was developed using PHP, so I found some materials to learn about it. The Code is as follows:
<? PHP
$ Flag = 0;
// Data to be post
$ Argv = array (
'Sn '=> 'sdk-BBX-010-XXXXX ',
'Pwd' => 'xxxxxx ',
'Mobile' => '134338xxxxx', // mobile phone number of the test
'Content' => 'hello, 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", 80, $ errno, $ errstr, 10) or exit ($ errstr. "--->". $ errno );
// Construct the post Request Header
$ 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 ";
// Add the post string
$ Header. = $ params. "\ r \ n ";
// Send post data
Fputs ($ fp, $ header );
$ Inheader = 1;
While (! Feof ($ fp )){
$ Line = fgets ($ fp, 1024); // only the returned data on the page is displayed when the request packet header is removed.
If ($ inheader & ($ line = "\ n" | $ line = "\ r \ n ")){
$ Inheader = 0;
}
If ($ inheader = 0 ){
// Echo $ line;
}
}
If ($ line = 1)
{
Echo 'message sent successfully, please check the returned value '. $ line;
} Else
{
Echo 'message sending failed. Please check the returned values of related errors '. $ line;
}
Fclose ($ fp );