我创建了一些PHP代码,用于从数据库获取GCM注册,并向Android设备发送推送。这段代码运行正常,但当用户删除Android上的应用程序时,例如数据库中的GCM注册就会无效。如何知道GCM注册何时无效,以便使用PHP将其从数据库中删除?
这是发送推送的代码:
//Getting api key
$api_key = "....";
//Getting registration token we have to make it as array
$reg_token = array($token);
//Getting the message
$message = $versiculo;
//Creating a message array
$msg = array
(
'message' => $message,
'title' => $capitulo,
'id_versiculo' => $id,
);
//Creating a new array fileds and adding the msg array and registration token array here
$fields = array
(
'registration_ids' => $reg_token,
'data' => $msg
);
//Adding the api key in one more array header
$headers = array
(
'Authorization: key=' . $api_key,
'Content-Type: application/json'
);
//Using curl to perform http request
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
//Getting the result
$result = curl_exec($ch );
curl_close( $ch );发布于 2018-04-12 00:29:25
卸载客户端应用程序时,相应的令牌将失效,如果您向该特定令牌发送消息,它将返回NotRegistered错误,在这种情况下,您可以删除(或存档)该令牌。
正如评论中提到的,请继续将您的应用程序迁移到FCM,因为谷歌已经提供了弃用通知(参见my answer here)。
对于FCM,行为实际上是相同的。请参阅此similar/possibly duplicate post。
https://stackoverflow.com/questions/49776147
复制相似问题