php firebase推送通知ios:错误InvalidRegistration

时间:2020-10-19 13:20:32

标签: php ios firebase push-notification firebase-cloud-messaging

$url = "https://fcm.googleapis.com/fcm/send";
$token = "xxx"; 
$serverKey = 'xxx';

$title = "Title";
$body = "Body of the message";

$notification = array('title' =>$title , 'text' => $body, 'body' => $body, 'sound' => 'default', 'badge' => '1');
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high', 'data' => $notification, 'content_available' => true);

$json = json_encode($arrayToSend);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: key='. $serverKey;


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);

$response = curl_exec($ch);

pre($response);

curl_close($ch);

我无法发送通知

{“ multicast_id”:2200169071930988341,“成功”:0,“失败”:1,“ canonical_ids”:0,“结果”:[{“错误”:“无效注册”}]}}

2 个答案:

答案 0 :(得分:1)

这意味着您传递的$token值未在当前Firebase项目上注册。发生这种情况的原因有很多,包括令牌已过期且不再有效。

处理此响应的通常方法是从数据库中删除过时的令牌,以便将来不再将其传递给FCM API。

答案 1 :(得分:0)

我们为Firebase提供了API控件。令牌中没有错误。通知通过具有相同令牌的Firebase发送。