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==“”){
//句柄特定的错误代码名
}
//检查其他错误代码名称。。。
}
}
}
}否则{
//没有失败
}