PHP send at command, PHPAT instruction
Need: Send text message to user input phone, request can customize information content
Problem: No telecom cat, no custom SMS content with free API interface
Solution: Through the 4G network card, connected to the server, through the AT command to operate the network card, send SMS
Lookup found that the at quality send requires multiple encoding of the information, and the send timed out, but the actual delivery is successful, the problem is not fully resolved
The code is as follows:
1
Php2Send_message (' 8613800138000 ', ' Hello, you are applying for registration service platform, your verification code is: 97431 ');3 4 functionSend_message ($phone,$message) {5 $phone= Decode_phone ($phone);6 7 $message _center= Decode_message_center (' +8613010200500 ');//This step seems useless8 9 $message= Decode_message ($message);Ten One $length= Get_message_length ($phone,$message); A - Set_time_limit(0); - the //Select COM port as appropriate, here is COM4, in the management device, view the COM port of the network demodulator - - exec(' Mode com4:baud=115200 data=8 stop=1 parity=n xon=on '); - + $FD= Dio_open (' COM4: ',o_rdwr); - + $ff= Dio_stat ($FD); A at if(!$FD) { - die("Failed open COM4"); - } - - //Chr (13) is the carriage return, Chr (16) is CTRL + Z - inDio_write ($FD, "At+cmgf=0".CHR(13));//set the Send mode to PDU - toDio_write ($FD, "at+cmgs=".$length.CHR(13));//Send Message length + -Dio_write ($FD, ' 11000d91 '.$phone. ' 000800 '.$message.CHR(26).CHR(13));//Send SMS the * Sleep(2); $ Panax NotoginsengDio_close ($FD); - } the + functionDecode_phone ($phone) { A $phone=Str_replace('+', '',$phone); the + if(strlen($phone)% 2!== 0) { - $phone=$phone. F; $ } $ - $newPhone= ''; - for($i= 0;$i<strlen($phone);$i+ = 2) { the $newPhone=$newPhone.substr($phone,$i+ 1, 1).substr($phone,$i, 1); - }Wuyi the return $newPhone; - } Wu - functionDecode_message_center ($phone) { About $newPhone= ' 91 '. Decode_phone ($phone); $ - $len=Strtoupper(Dechex(strlen($newPhone)/2)); - - if(strlen($len)% 2!== 0) { A $len= ' 0 '.$len; + } the - $newPhone=$len.$newPhone; $ the return $newPhone; the } the the functionDecode_message ($message) { - $newMessage= Utf8_unicode ($message); in the $len=Strtoupper(Dechex(strlen($newMessage)/2)); the About if(strlen($len)% 2!== 0) { the $len= ' 0 '.$len; the } the + $newMessage=$len.$newMessage; - the return $newMessage;Bayi } the the functionUtf8_unicode ($name) { - $name=Iconv(' UTF-8 ', ' UCS-2 ',$name); - $len=strlen($name); the $str= ''; the the for($i= 0;$i<$len-1;$i=$i+ 2) { the $c=$name[$i]; - $c 2=$name[$i+ 1]; the if(Ord($c) > 0) {//two bytes of text the $str.=Base_convert(Ord($c), 10, 16).Str_pad(Base_convert(Ord($c 2), 10, 16), 2, 0,str_pad_left); the}Else {94 $str.=Str_pad(Base_convert(Ord($c 2), 10, 16), 4, 0,str_pad_left); the } the } the 98 $str=Strtoupper($str);//Convert to uppercase About return $str; - }101 102 functionGet_message_length ($phone,$message) {103 $str= ' 11000d91 '.$phone. ' 000800 '.$message;104 the $length=strlen($str)/2;106 107 if($length< 10) {108 $length= ' 0 '.$length;109 } the 111 return $length; the}
http://www.bkjia.com/PHPjc/1129314.html www.bkjia.com true http://www.bkjia.com/PHPjc/1129314.html techarticle php send at command, phpat command demand: Send SMS to user input phone, request can customize information content problem: No telecom cat, use free API interface cannot customize SMS content ...