Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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
Android 验证是否正确发送GCM_Android_Push Notification_Google Cloud Messaging - Fatal编程技术网

Android 验证是否正确发送GCM

Android 验证是否正确发送GCM,android,push-notification,google-cloud-messaging,Android,Push Notification,Google Cloud Messaging,我想验证消息是否已正确发送 我有以下代码: $result = curl_exec($ch); if ($result === FALSE) { die('Curl failed: ' . curl_error($ch)); } // Close connection curl_close($ch); return $result; 我只想检查消息是否已正确发送到Google服务器(而不是目标用户),以显示类似“message sent”的消息 我必须使用结果数组,特别是succ

我想验证消息是否已正确发送

我有以下代码:

$result = curl_exec($ch);
if ($result === FALSE) {
     die('Curl failed: ' . curl_error($ch));
}

// Close connection
curl_close($ch);

return $result;
我只想检查消息是否已正确发送到Google服务器(而不是目标用户),以显示类似“message sent”的消息

我必须使用结果数组,特别是success字段(检查si是否大于1)


你将如何实现这一点?

仅仅知道
成功是不够的。您需要知道没有故障(
failure
=0),如果有任何故障,您需要检查错误代码名称,并处理错误:

$jsonArray = json_decode($result);
if ($jsonArray->failure > 0) {
  if(!empty($jsonArray->results)) {
    for($i=0; $i<count($jsonArray->results);$i++){
        if(isset($jsonArray->results[$i]->error)){
            if($jsonArray->results[$i]->error == "<SomeErrorCodeName>") {
                // handle specific error code name
            }
            // check for other error code names ...
        }
    }
  }
} else {
  // no failures
}
$jsonArray=json\u decode($result);
如果($jsonArray->failure>0){
如果(!empty($jsonArray->results)){
对于($i=0;$iresults);$i++){
如果(isset($jsonArray->results[$i]->error)){
如果($jsonArray->results[$i]->error==“”){
//句柄特定的错误代码名
}
//检查其他错误代码名称。。。
}
}
}
}否则{
//没有失败
}