使用PHP Curl返回SMS值

使用PHP Curl返回SMS值,php,curl,Php,Curl,使用PHP Curl返回SMS值。下面的代码用于发送SMS,但我需要能够为每个操作返回值 例如,如果sms为ok返回值成功,如果值为2904返回sms发送失败等 任何帮助都将不胜感激。 SMS网关API的返回值如下: OK=Successful 2904=SMS Sending Failed 2905=Invalid username/password combination 2906=Credit exhausted <?php $data = array(

使用PHP Curl返回SMS值。下面的代码用于发送SMS,但我需要能够为每个操作返回值 例如,如果sms为ok返回值成功,如果值为2904返回sms发送失败等

任何帮助都将不胜感激。 SMS网关API的返回值如下:

OK=Successful
2904=SMS Sending Failed
2905=Invalid username/password combination
2906=Credit exhausted




<?php


$data = array(
        'username' => $_GET['username'],
        'password' => $_GET['password'],
        'sender'  => $_GET['sender'],
        // 'sender'  => $_GET['uname'],
        'recipient'  => $_GET['recipient'],
        'message'  => $_GET['message']
);




  // Send the POST request with cURL
$ch = curl_init('http://example.com/components/com_spc/smsapi.php');
curl_setopt($ch, CURLOPT_POST, true);

$header[ ] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[ ] = "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[ ] = "Cache-Control: max-age=0";
    $header[ ] = "Connection: keep-alive";
    $header[ ] = "Keep-Alive: 300";
    $header[ ] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
    $header[ ] = "Accept-Language: en-us,en;q=0.5";
    $header[ ] = "Pragma: "; // browsers keep this blank.



// also tried $header[] = "Accept: text/html";
curl_setopt ($ch,    CURLOPT_HTTPHEADER, $header);
//curl_easy_setopt(curl, CURLOPT_USERAGENT, "Mozilla/4.0");


curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch); //This is the result from Textlocal
curl_close($ch);



if($result === false) {
//if(curl_exec($ch) === false) {//
echo '<font color=red>Message sending failed</font>';
} else {
echo '<font color=green>SMS  Message also successfully Sent.</font>';

}
print($result);

?>

编辑:它如何返回您列出的值?我更改了下面的代码,但它仍然可能不起作用,因为我猜测它返回响应代码的索引的名称:

您正在查找curl\u getinfo$ch命令。它返回一个数组,您需要查看该数组以找到存储返回值的数组键。我猜这是“http_代码”

具体而言:

if($result === false) {
echo '<font color=red>Message sending failed</font>';
echo '<br>More info:';

$curl_info = curl_getinfo($ch);

  if ($curl_info['http_code']===2906) {
    echo 'Credit exhausted';
  } elseif ($curl_info['http_code']===2905) {
    echo 'invalid username/password';
  } elseif ($curl_info['http_code']===2904) {
    echo 'SMS failed';
  }

} else {
echo '<font color=green>SMS  Message also successfully Sent.</font>';
}

您添加的代码在解析错误下面抛出错误:语法错误,在C:\xampp\htdocs\booking\u db\smsverify.php中意外出现“[”