簡體   English   中英

調用SMS API的Ajax中沒有php curl(GET / POST)/ file_get_content / wget響應

[英]no php curl(GET/POST)/file_get_content/wget response in ajax calling an SMS API

在這里,我嘗試使用vicidial(星號撥號程序)命中用於短信集成服務的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> 

調用您的短信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;

make需要發布數據並放在$ postdata中,如果您的api有標頭,也可以這樣做!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM