Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用txtlocal api检查消息的状态_Php - Fatal编程技术网

Php 使用txtlocal api检查消息的状态

Php 使用txtlocal api检查消息的状态,php,Php,这是使用txtlocal发送消息的代码 $message = urlencode($message); $data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test; $ch = curl_init('http://api.txtlocal.com/send/?'

这是使用txtlocal发送消息的代码

$message = urlencode($message);
    $data = "username=".$username."&hash=".$hash."&message=".$message."&sender=".$sender."&numbers=".$numbers."&test=".$test;
    $ch = curl_init('http://api.txtlocal.com/send/?');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $result = curl_exec($ch); // This is the result from the API
    echo $result;
    curl_close($ch);
但是我怎样才能检查一些错误呢。我正在使用

echo $result;
打印输出结果的步骤

它给了我这样的东西

{"balance":94.5,"batch_id":309268453,"cost":0.5,"num_messages":1,"message":{"num_parts":1,"sender":"Audrey","content":"This is a test message from the PHP API script."},"receipt_url":"","custom":"","messages":[{"id":"1356746460","recipient":639000000000}],"status":"success"}
我可以获取成功消息的最后一个字符串。但如果结果不是成功呢

但如果结果不是成功呢

这取决于你来决定

声明如下:

每个响应将包含一个“状态”字段,可以是“成功”或“失败”。此字段可用于确定您的请求是否成功

因此,如果要检查,可以执行以下操作:

$result = json_decode($result);
if ($result->status == 'success') {
    echo 'It worked...';
} else {
    echo "It didn't work.";
}