使用 FreePBX Bootstrap 从 PHP 脚本发送短信

Send SMS from PHP script with FreePBX Bootstrap

在下面由未知第三方编写的脚本中,我所做的唯一更改是将 $to、$from 和 $body 的值从硬编码字符串更改为 $_GET 元素。该项目的目的是在查询字符串中将一些参数传递给此脚本,然后使用它编写和发送 SMS 消息。

<?php

/**** **** **** **** **** **** **** **** **** **** **** 
 * sms.php 
 * 
 * sample PHP code to send an SMS message to a registered 
 * extension on a FreeBX 12 server 
 * 
 * version history
 *    2015-09-22   version 0 by lgaetz@sangoma.com
 **** **** **** **** **** **** **** **** **** **** ****/

// Load the FreeBPX bootstrap, requires FreePBX 12
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) {
    include_once('/etc/asterisk/freepbx.conf');
}

// The Asterisk Manager Class from the boostrap is $astman 
// If using FreePBX 13+ must set asman with 
//  $astman = new AGI_AsteriskManager( );
if ($astman) {
    // $to = "sip:#######";
    // $from = '"Caller ID Name" <#######>';
    // $body = "cats are yummy";
    $to = $_GET['to'];
    $from = $_GET['from'];
    $body = $_GET['body'];

    $result = $astman->MessageSend($to, $from, $body);

    print_r($result);   //debug

    // the variable $result will be an array of the formats
    // Array ( [Response] => Success [Message] => Message successfully sent )
    // Array ( [Response] => Error [Message] => Message failed to send. )
} else {
    echo "No Asterisk Manager Connection";
}

然而,尽管此脚本可以很好地处理那些被注释掉的硬编码值,但将这些值更改为 $_GET 元素会导致此错误消息:

Array ( [Response] => Error [Message] => Message technology not found. )

我正试图找到某种文档来向我解释这是如何工作的...任何使用过 FreePBX 的人的任何想法 bootstrap?

这个问题的解决方案不在于文档或数据的编码,或者也许这个 API 不能很好地处理查询字符串(所有这三个问题都曾在我脑海中闪过全天点),但秘密在于传递给 api.

的数据格式

答案一直在我眼皮底下:

// $to = "sip:#######";
// $from = '"Caller ID Name" <#######>';
// $body = "cats are yummy";
$to = $_GET['to'];
$from = $_GET['from'];
$body = $_GET['body'];

所以,这是问题的解决方案:

$to = 'sip:' . $_GET['to'];
$from = '"Caller ID Name" <' . $_GET['from'] . '>';
$body = $_GET['body'];

您可以像这样通过 URL 传递数据:

http://www.url.com/sms.php?to=0000000&from=0000001&body=hello