PHP send at instruction instance code _php instance

Source: Internet
Author: User
Tags chr ord strlen

requirements: send sms to user input phone, request can customize information content

problem: no telecom cat, use free API interface can not customize SMS content

Solution: through the 4G network card, connected to the server, through the AT command to operate the network card, send SMS

Lookup found that at quality sending requires multiple encodings of the information, and the send timeout, but the actual delivery succeeded, the problem has not been fully resolved

The code is as follows:

<?php send_message (', ' Hello, you are applying for registration service platform, your verification code is: '); function Send_message ($phone, $message) {$phone = Decode_phone ($phone); $message _center = decode_message_center (' + ');
/This step does not seem to be useless $message = Decode_message ($message);
$length = Get_message_length ($phone, $message);
Set_time_limit ();
Select COM port According to the situation, here is COM, in Management device, view network demodulator of COM mouth exec (' mode com:baud= data= stop= parity=n xon=on ');
$FD = Dio_open (' COM: ', O_RDWR);
$FF = Dio_stat ($FD); if (! $fd) {die ("failed open com");}//CHR () is a carriage return, Chr () is Ctrl+z dio_write ($FD, "at+cmgf=". Chr ()); Set send mode to PDU dio_write ($FD, "at+cmgs=". $length. Chr ()); Send Message length Dio_write ($fd, ' D '. $phone. '' . $message. Chr (). Chr ());
Send SMS sleep ();
Dio_close ($FD); The function Decode_phone ($phone) {$phone = Str_replace (' + ', ', $phone), if (strlen ($phone)%!==) {$phone = $phone.
' F ';
} $newPhone = '; for ($i =; $i < strlen ($phone); $i + = {$newPhone = $newPhone. substr ($phone, $i +,). substr ($phone, $i,);} RE
Turn $newPhone; } function Decode_mEssage_center ($phone) {$newPhone = '. Decode_phone ($phone); $len = Strtoupper (Dechex (strlen ($newPhone)/)); if (strlen ($len)%!==) {$len = '. $len;} $newPhone = $len.
$newPhone;
return $newPhone; function Decode_message ($message) {$newMessage = Utf_unicode ($message); $len = Strtoupper (Dechex (strlen ($newMessage)
/ )); if (strlen ($len)%!==) {$len = '. $len;} $newMessage = $len.
$newMessage;
return $newMessage;  function Utf_unicode ($name) {$name = Iconv (' utf-', ' ucs-', $name); $len = strlen ($name); $str = '; for ($i =; $i < $len-; $i = $i +) {$c = $name [$i]; $c = $name [$i +]; if (ord ($c) >) {//two bytes of text $str. = Base_convert (ord ($c),,). str_p
AD (Base_convert (Ord ($c),,),,, Str_pad_left);
else {$str. = Str_pad (Base_convert (Ord ($c),,),,, Str_pad_left);} $str = Strtoupper ($STR);
Convert to uppercase return $STR; function Get_message_length ($phone, $message) {$str = ' D '. $phone. '' .
$message;
$length = strlen ($str)/; if ($length <) {$length = '.
$length;
return $length; }

The above is a small series to introduce PHP to send at the instruction instance code, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.