This article mainly introduces the relevant information about the example code of PHP sending AT command. It is very good and has reference value. Friends who need it can take a look.
Requirement: Send SMS to The user enters his mobile phone and is required to customize the message content
Problem: There is no telecom mode, and the free api interface cannot be used to customize the text message content
Solution: Connect to the server through a 4G network card, operate the network card through AT commands, and send text messages
After checking, it was found that AT quality sending requires multiple encoding of the information, and the sending times out. , but the actual sending was successful, the problem has not been completely solved
The code is as follows:
<?php send_message('', '您好, 你正在申请注册服务平台, 您的验证码是: '); function send_message($phone, $message) { $phone = decode_phone($phone); $message_center = decode_message_center('+'); //此步骤似乎没用 $message = decode_message($message); $length = get_message_length($phone, $message); set_time_limit(); //根据情况选择COM口, 此处为COM, 在管理设备中, 查看网络解调器的COM口 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()是回车, chr()是Ctrl+Z dio_write($fd, "AT+CMGF=" . chr()); //设置发送模式为PDU dio_write($fd, "AT+CMGS=" . $length . chr()); //发送信息长度 dio_write($fd, 'D' . $phone . '' . $message . chr() . chr()); //发送短信息 sleep(); dio_close($fd); } 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, ); } return $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) > ) { //两个字节的文字 $str .= base_convert(ord($c), , ) . str_pad(base_convert(ord($c), , ), , , STR_PAD_LEFT); } else { $str .= str_pad(base_convert(ord($c), , ), , , STR_PAD_LEFT); } } $str = strtoupper($str); //转换为大写 return $str; } function get_message_length($phone, $message) { $str = 'D' . $phone . '' . $message; $length = strlen($str) / ; if ($length < ) { $length = '' . $length; } return $length; }
Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHP Learning Record Array Function
PHP Implementation of Exporting Styled Excel Example Sharing
PHP implements the method of forcing the specified callback type based on Callable
The above is the detailed content of Methods and example codes for sending AT commands in PHP. For more information, please follow other related articles on the PHP Chinese website!

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version
Recommended: Win version, supports code prompts!

Dreamweaver Mac version
Visual web development tools
