在PHP中执行AT命令发送短信

7
我正在尝试从PHP执行AT命令。
我尝试了exec()和shell_exec()函数。
请不要建议使用第三方短信网关,因为我的客户不想透露他的私人信息,并且希望从自己的服务器发送短信。
我有一个连接到串口的GSM调制解调器,可以像图中的“putty”一样访问它(如下图所示)。 putty screen 1 我可以输入AT命令来发送短信,就像下面的图一样。 enter image description here 我想通过PHP运行这些AT命令。

1
你尝试过使用 plink.exe 吗? - Gerald Schneider
你能够通过Telnet进入GSM调制解调器吗?如果可以,你可以尝试使用PHP中的fsockopen函数。 http://www.php.net/manual/en/function.fsockopen.php 然后使用fwrite函数向套接字写入数据。 http://www.php.net/manual/en/function.fwrite.php - n0tiz
@GeraldSchneider 是的,我想这是我正在使用的网址 http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html 但我想通过PHP执行AT命令,在第二个图像上的黑屏幕上输入命令。 - Milind More
1
根据 php 手册上这条 10 年前的评论,您可以使用 fopen 向 com 端口写入数据。 - Gerald Schneider
哇!这个评论已经有10年了,我会试一下的! - Milind More
给我报错信息:“无法建立连接,因为目标计算机积极拒绝了连接。(10061)” - Milind More
2个回答

15

你好,我正在使用 PHP 类在 Windows 8 上发送短信,以下是我的 PHP 代码。

require "php_serial.class.php";
$serial = new phpSerial;
$serial->deviceSet("COM4");
$serial->confBaudRate(115200);

// Then we need to open it
$serial->deviceOpen();

// To write into
$serial->sendMessage("AT+CMGF=1\n\r"); 
$serial->sendMessage("AT+cmgs=\"+92234444444\"\n\r");
$serial->sendMessage("sms text\n\r");
$serial->sendMessage(chr(26));

//wait for modem to send message
sleep(7);
$read=$serial->readPort();
$serial->deviceClose();

PHP SERIAL类链接


2
嗨@xam,你能否请添加php_serial.class.php文件的链接或代码? - Milind More
1
嗨@MilindMore,我已经从Google Drive生成了链接,用于php_serial.class.php文件。 php_serial.class.php的链接 - user2377528
@xam,它出现在“端口(COM和LPT)”上。我卡在这里了 :( - Sam San
1
@JosuaMarcelChrisano 很高兴听到这个消息 :) 如果它起作用了,请点赞。 - user2377528
嗨Xam,如何读取消息?我无法使用这个$serial->sendMessage("AT+cmgr="1"\n\r");。 - Josua Marcel C
显示剩余6条评论

2

我认为你的建议将有助于你在phpclasses上提供的那个人,请检查并告诉我是否正确,这里是代码$serial->sendMessage("AT+CMGS='8149823689' ".chr(13)." hello world"); - Milind More
我还没有尝试过这个库,所以无法确认你是否做得正确 ;) - Damien Legros
1
顺便提一下:如果您的服务器运行在Windows上,我不确定使用PHP进行串行通信是否完全可行,除非使用外部应用程序/库。 - Damien Legros

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接