验证正确发送GCM

时间:2013-09-13 19:43:39

标签: 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服务器(而不是目标用户),以显示“已发送邮件”等消息。

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

你会如何实现?

1 个答案:

答案 0 :(得分:2)

仅知道success>是不够的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
}
相关问题