我一次使用PHP在多个android设备上发送通知。所有注册ID都是唯一的,以下是我发送的CURL请求。从GCM发送多个通知
$url='https://android.googleapis.com/gcm/send';
$headers = array(
'Authorization: key=' . ANDROID_KEY,
'Content-Type: application/json'
);
$registration_ids = [];//with multiple registration ids
$notification = array(
'registration_ids' => $registration_ids,
'data' => array('notification_id' => $data['notification_id'],
'title' => $data['title'],
'message' => $data['message'])
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($notification));
$res = curl_exec($ch);
调试多次后,我找不到在同一设备上多次通知(超过10次)的任何原因。
有什么办法可以检查GCM收到的请求的日志。任何领导将不胜感激。
发送此请求后的回复是什么? –
您是否尝试通知有效负载而不是数据有效负载?请查看https://firebase.google.com/docs/cloud-messaging/concept-options –