在PHP中使用GSM调制解调器发送短信

时间:2013-05-22 07:19:39

标签: php gsm modem

我想从我的GSM调制解调器发送短信。我尝试使用this link作为参考来实现此功能。但我的调制解调器不会产生任何响应。任何帮助..谢谢提前.... 这是我的代码片段.. $ gsm_send_sms = new gsm_send_sms();

$ gsm_send_sms->的init();

$ status = $ gsm_send_sms-> my_send_message_function(“+ 09524566775”,“raja”);

$ gsm_send_sms->关闭();

//通过串口短信调制解调器发送短信 class gsm_send_sms {

public $port = 'COM7';
public $baud = "9600";
public $debug = true;

private $fp;
private $buffer;

//Setup COM port
public function init() {

    $this->debugmsg("Setting up port: \"{$this->port} @ \"{$this->baud}\" baud");

    exec("MODE {$this->port}: BAUD={$this->baud} PARITY=N DATA=8 STOP=1", $output, $retval);

    if ($retval != 0) {
        throw new Exception('Unable to setup COM port, check it is correct');
    }

    $this->debugmsg(implode("\n", $output));

    $this->debugmsg("Opening port");

    //Open COM port
    $this->fp = fopen($this->port . ':', 'r+');

    //Check port opened
    if (!$this->fp) {
        throw new Exception("Unable to open port \"{$this->port}\"");
    }

    $this->debugmsg("Port opened");
    $this->debugmsg("Checking for responce from modem");

    //Check modem connected
    fputs($this->fp, "AT\r");

    //Wait for ok
    $status = $this->wait_reply("OK\r\n", 5);

    if (!$status) {
        throw new Exception('Did not receive responce from modem');
    }

0 个答案:

没有答案