简体   繁体   中英

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

Here I am trying to hit an Message API for sms integration service with vicidial (Asterisk dialer).

I am getting response for my local test dialer server as well as local browser opening php file with success.

But hitting the same code (sendsms.php) in live dialer server with PRI calling i am having the issue of not returning any desired html/xml response.

My approach is : i)deployed the sendsms() in ajax_js.php ii)calling the sendsms() from webform_js.php in Dispo_submit() with comparing disposition code.

my ajax function is:

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

my 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);
?>

I should get an response like either with failure:

 <!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> 

or with success:

 <!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> 

call your sms api with this :

   $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 require post data and placed in $postdata and if your api have header make that too!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM