Execute AT commands to send sms in php

我怕爱的太早我们不能终老 提交于 2019-12-18 02:54:15

问题


I am trying to execute AT commands from PHP.

I tried exec() and shell_exec()

Please don't suggest third party SMS gateway my client doesn't want to disclose his private information and wants to send SMS from his own server.

I have a GSM modem attach to a serial port which I can access through "putty" like in fig

And I can enter AT commands to send SMS like in fig below.

I want to run those AT commands through PHP.


回答1:


Hi I am sending sms using php class on windows 8 by this php code.

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 class Link




回答2:


You just need a RS232 communication class such as this one http://www.phpclasses.org/package/3679-PHP-Communicate-with-a-serial-port.html

Alternatively you can also use fopen()

exec('mode COM1: baud=115200 data=8 stop=1 parity=n xon=on');
$fd = fopen('COM1:', O_RDWR);
fwrite($fd,chr(0).chr(1));
fclose($fd);


来源:https://stackoverflow.com/questions/15902831/execute-at-commands-to-send-sms-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!