2015-10-13 4 views
0

Ici j'essaye de frapper une API de message pour le service d'intégration de sms avec vicidial (Asterisk dialer).pas de php curl (GET/POST)/file_get_content/réponse wget dans ajax appelant une API SMS

Je reçois une réponse pour mon serveur dialer de test local ainsi que le fichier php d'ouverture du navigateur local avec succès. Mais en tapant le même code (sendsms.php) dans le serveur de numérotation en direct avec l'appel PRI je rencontre le problème de ne pas retourner une réponse html/xml désirée.

Mon approche est: i) les sendsms déployés() dans ajax_js.php ii) appeler les sendsms() de webform_js.php à Dispo_submit() avec la comparaison code de disposition.

ma fonction ajax est:

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

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

j'obtenir une réponse comme soit à l'échec:

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

ou avec succès:

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

Répondre

0

appeler votre api sms avec ceci:

$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 nécessitent des données post et placé dans postdata de $ et Si votre api a en-tête, faites-le aussi!