【发布时间】:2015-10-13 19:46:04
【问题描述】:
在这里,我正在尝试使用 vicidial(Asterisk 拨号器)为短信集成服务打 Message API。
我的本地测试拨号服务器以及本地浏览器成功打开 php 文件得到响应。
但是使用 PRI 调用在实时拨号服务器中访问相同的代码 (sendsms.php) 我遇到了不返回任何所需的 html/xml 响应的问题。
我的方法是: i) 在 ajax_js.php 中部署 sendms() ii) 在 Dispo_submit() 中从 webform_js.php 调用 sendms() 并比较处置代码。
我的ajax函数是:
function Sendsms(agent,customerno)
{
var rcver = customerno;
var msgtext = "We thank you for showing interest in opening AxisDirect Trading a/c. Our Sales Team" + agent+ "will contact you shortly.";
//alert(msgtext);
var xmlhttp=getAJAX();
if (xmlhttp)
{
sms_query = "&ACTION=SMSsend&format=text&stage="+"&sms_to="+rcver+"&sms_text="+msgtext;
// var theURL = "http://bulkpush.mytoday.com/BulkSms/SingleMsgApi?feedid=fid&username=uname&password=psswd&To=rcver&Text=msgtext&senderid=sender_id";
xmlhttp.open('POST', 'sendsms.php',true);
xmlhttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
xmlhttp.send(sms_query);
// xmlhttp.send();
xmlhttp.onreadystatechange = function()
{
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
var received = null;
received = xmlhttp.responseText;
var details_array = received.split(" ");
var index_tid = details_array[5].split("\'");
//alert(received);
var index_reqid = details_array[14].split("\'");
var tid = index_reqid[1].split("\'");
var reqid = index_tid[1].split("\'");
}
savevalues(reqid[0],tid[0],received);
}
}
delete xmlhttp;
}
我的sendms.php:
<?php
if (isset($_GET["sms_to"])) {$sms_to=$_GET["sms_to"];}
elseif (isset($_POST["sms_to"])) {$sms_to=$_POST["sms_to"];}
if (isset($_GET["sms_text"])) {$sms_text=$_GET["sms_text"];}
elseif (isset($_POST["sms_text"])) {$sms_text=$_POST["sms_text"];}
$postdata = http_build_query(
array(
'feedid'=>'261344',
'senderid'=>'AxisBank',
'username'=>'1234567890',
'password'=>'wdgtd',
'To'=>$sms_to,
'Text'=>$sms_text //'AxisDirect Trading a/c. Our Sales Team___________ (name - Mbl no) will contact you shortly.'
)
);
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded',
'content' => $postdata
)
);
$context = stream_context_create($opts);
$result = file_get_contents('http://bulkpush.mytoday.com/BulkSms/SingleMsgApi', true, $context);
print_r($result);
?>
我应该得到类似失败的响应:
<!DOCTYPE RESULT SYSTEM 'http://bulkpush.mytoday.com/BulkSms/BulkSmsRespV1.00.dtd'>
<RESULT>
<REQUEST-ERROR>
<ERROR>
<CODE>102</CODE>
<DESC>Client 979431 is not registered</DESC>
</ERROR>
</REQUEST-ERROR>
</RESULT>
或成功:
<!DOCTYPE RESULT SYSTEM 'http://bulkpush.mytoday.com/BulkSms/BulkSmsRespV1.00.dtd'>
<RESULT REQID ='5419521921'>
<MID SUBMITDATE='2015-10-13 11:48:27' ID='1' TAG = 'null' TID = '9841339066'>
</MID>
</RESULT>
【问题讨论】:
标签: javascript php asterisk centos5