在下面由未知第三方编写的脚本中,我所做的唯一更改就是将$to、$from和$body的值从硬编码字符串更改为$_GET元素。该项目的目的是以查询字符串的形式将一些参数传递给该脚本,然后用它编写、发送和发送短信。
<?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引导有关的人有什么想法吗?
发布于 2015-09-23 21:37:51
这个问题的解决方案不是文档的编码,也不是数据的编码,也不是这个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=hellohttps://stackoverflow.com/questions/32745395
复制相似问题