如何在PHP中使用fcm(firebase控制台)将推送通知发送到iphone?

从Firebase控制台发送通知通知正常工作。

Firebase控制台

我正在获取iOS设备上的推送通知。

这里是我使用的发送推送通知到iPhone使用FCM在PHP中的代码..

<?php $ch = curl_init("https://fcm.googleapis.com/fcm/send"); //The device token. $token = ""; //Title of the Notification. $title = "Carbon"; //Body of the Notification. $body = "Bear island knows no king but the king in the north, whose name is stark."; //Creating the notification array. $notification = array('title' =>$title , 'text' => $body); //This array contains, the token and the notification. The 'to' attribute stores the token. $arrayToSend = array('to' => $token, 'notification' => $notification); //Generating JSON encoded string form the above array. $json = json_encode($arrayToSend); //Setup headers: $headers = array(); $headers[] = 'Content-Type: application/json'; $headers[] = 'Authorization: key= abcdgfdk'; //server key here //Setup curl, add headers and post parameters. 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 curl_close($ch); return $response; ?> 

并返回以下响应:

 {"multicast_id":7847791275395796141,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1473926169782959%51b989d251b989d2"}]} 

请告诉我我做错了什么? 我也使用相同的代码为Android的服务器密钥和设备令牌,它工作正常…

谢谢shubank ..你的答案工作…我需要添加的唯一的事情是优先级高…这里是更新的代码…可以帮助别人:)

  $ch = curl_init("https://fcm.googleapis.com/fcm/send"); //The device token. $token = ""; //token here //Title of the Notification. $title = "Carbon"; //Body of the Notification. $body = "Bear island knows no king but the king in the north, whose name is stark."; //Creating the notification array. $notification = array('title' =>$title , 'text' => $body); //This array contains, the token and the notification. The 'to' attribute stores the token. $arrayToSend = array('to' => $token, 'notification' => $notification,'priority'=>'high'); //Generating JSON encoded string form the above array. $json = json_encode($arrayToSend); //Setup headers: $headers = array(); $headers[] = 'Content-Type: application/json'; $headers[] = 'Authorization: key= $key'; // key here //Setup curl, add headers and post parameters. 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 curl_close($ch); return $response; 

似乎返回成功。 也许检查您的应用程序注册码,看看是否更改了手机令牌。 有时会生成一个新的令牌。