Beim Senden der Benachrichtigung von der Firebase-Konsole funktioniert die Benachrichtigung einwandfrei.
Ich erhalte Push-Benachrichtigungen auf dem iOS-Gerät.
Hier ist der Code, den ich verwende, um Push-Benachrichtigungen mit FCM in PHP an das iPhone zu senden.
<?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; ?>
Und es gibt die folgende Antwort zurück:
{"multicast_id":7847791275395796141,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1473926169782959%51b989d251b989d2"}]}
Bitte schlagen Sie mir vor, was ich falsch mache. Ich verwende den gleichen Code auch für Android mit dem Server-Schlüssel und dem Geräte-Token und es funktioniert einwandfrei ...
Danke Shubank .. Ihre Antwort funktioniert ... Das einzige, was ich hinzufügen muss, ist Priorität hoch ... Hier ist der aktualisierte Code ... Kann es auch jemandem helfen :)
$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;
hier ist der code von mir getestet und funktioniert einwandfrei. Stellen Sie sicher, dass Sie das FCM-Token übergeben
$path_to_firebase_cm = 'https://fcm.googleapis.com/fcm/send';
$token=array($token);
$fields = array(
'registration_ids' => $token,
'priority' => 10,
'data'=>$send_notification ,
'notification' => array('title' => $type_of_notification, 'body' => $title ,'sound'=>'Default'),
);
$headers = array(
'Authorization:key=' .'your server key' ,
'Content-Type:application/json'
);
// Open connection
$ch = curl_init('https://fcm.googleapis.com/fcm/send');
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $path_to_firebase_cm);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
return $result;
Scheint einen Erfolg zurückzugeben. Überprüfen Sie möglicherweise den Registrierungscode Ihrer App, um festzustellen, ob sich das Token für das Telefon geändert hat. Manchmal wird ein neues Token generiert.