2015-10-13 70 views
0

在这里,我试图通过vicidial(Asterisk拨号程序)命中短信集成服务的消息API。在Ajax调用SMS API没有PHP curl(GET/POST)/ file_get_content/wget响应

我得到了我的本地测试拨号服务器以及本地浏览器打开php文件成功的响应。

但在PRI调用的实时拨号服务器中击中相同的代码(sendsms.php)我有问题没有返回任何所需的HTML/XML响应。

我的做法是: i)以ajax_js.php II部署的sendsms())调用从webform_js.php在Dispo_submit的sendsms()()与比较配置的代码。

我的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; 
 
    
 
     }

我sendsms.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> 
 
\t <REQUEST-ERROR> 
 
\t \t <ERROR> 
 
\t \t \t <CODE>102</CODE> 
 
\t \t \t <DESC>Client 979431 is not registered</DESC> 
 
\t \t </ERROR> 
 
\t </REQUEST-ERROR> 
 
</RESULT>

或成功:

<!DOCTYPE RESULT SYSTEM 'http://bulkpush.mytoday.com/BulkSms/BulkSmsRespV1.00.dtd'> 
 
<RESULT REQID ='5419521921'> 
 
\t <MID SUBMITDATE='2015-10-13 11:48:27' ID='1' TAG = 'null' TID = '9841339066'> 
 

 
\t </MID> 
 
</RESULT>

回答

0

打电话给你的短信API与此:

$ch = curl_init("http://bulkpush.mytoday.com/BulkSms/SingleMsgApi"); 
    curl_setopt($ch, CURLOPT_POST, 1); 

    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $response = curl_exec($ch); 
    return $response; 

化妆需要进行后期的数据,并放置在$ POSTDATA和如果你的api有header也可以!