我正在使用 curl 向 GCM 中的多个用户发送通知。在某种情况下,如果任何用户从设备上取消注册/卸载应用程序,我会收到来自 curl 响应的失败消息“未注册”。任何其他解决方案来检查 registerationid 是否有效并向用户发送通知。
卷曲代码:
$url = 'https://android.googleapis.com/gcm/send';
$fields = array(
'registration_ids' => $registatoin_ids,
'data' => array( "message" => $message )
);
$headers = array(
'Authorization: key=' . GOOGLE_API_KEY,
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
$res = json_decode($result, true);
// Close connection
curl_close($ch);