FCM 推送 iOS 错误无效注册



我正在尝试通过PHP脚本通过Firebase Cloud Messaging发送到iOS应用程序发送推送通知。

目前我正在使用以下测试PHP脚本。

$url = "https://fcm.googleapis.com/fcm/send";
$token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$serverKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$title = "Title";
$body = "Body of the message";
$notification = array('title' =>$title , 'text' => $body, 'sound' => 'default', 'badge' => '1');
$arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high');
$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_CUSTOMREQUEST,"POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers);
//Send the request
$response = curl_exec($ch);
//Close request
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);

但是,当我尝试通过浏览器运行脚本时,我收到以下错误消息。

{"multicast_id":5417898622260949101,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}

但是当我从 FCM 控制台使用相同的设备令牌时,它可以正常工作。

我在互联网上尝试了许多PHP脚本,但最终得到相同的结果,这里会有什么问题?

任何帮助将不胜感激。

您使用的令牌似乎不是 FCM 的有效注册令牌,因此出现无效注册错误。

$apiKey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$title = 'Title'; 
$message = 'hello message';
$notification =[ 
"text" => "Test",
'badge' => "1",
'sound' => 'shutter.mp3',
"android_channel_id"=>"test01",
'body'=>$message,
'icon'=>'notif_icn',
'title'=>$title,
'priority'=>'high',
'vibrate'=> 1,
'alert'=> $message
];
$msg = [
'message'=> $message,
'title'=> $title
];
$fields =[
"content_available" => true,
"priority" => "high",
'registration_ids'=> $deviceToken,
'data'=> $msg
];
$headers = array('Authorization: key=' . $apiKey,'Content-Type: application/json');    
if ($headers){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://fcm.googleapis.com/fcm/send");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$response = curl_exec($ch);
if ($response === FALSE) {
die('FCM Send Error: ' . curl_error($ch));
}
curl_close($ch);
}

相关内容

  • 没有找到相关文章