Ich recherchierte online und versuchte verschiedene Methoden, um dieses Problem zu beheben, aber es hat das Problem nicht gelöst. Dies ist der Fehler, den ich in meinem PHP-Skript bekommeFirebase Cloud Messaging PHP-Skript meldet ungültige Registrierung
{"multicast_id":6412971464416964071,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Ich benutze Autorisierungsschlüssel, der der Serverschlüssel ist.
push_notification.php
<?php
function send_notification ($tokens, $message)
{
$url = 'https://fcm.googleapis.com/fcm/send';
$fields = array(
'registration_ids' => $tokens,
'data' => $message
);
$headers = array(
'Authorization:key = ********',
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
$result = curl_exec($ch);
if ($result === FALSE) {
die('Curl failed: ' . curl_error($ch));
}
curl_close($ch);
return $result;
}
$conn = mysqli_connect("localhost","root","","fcm");
$sql = "Select Token From users";
$result = mysqli_query($conn,$sql);
$tokens = array();
if(mysqli_num_rows($result) > 0){
while ($row = mysqli_fetch_assoc($result)) {
$tokens[] = $row["Token"];
}
}
mysqli_close($conn);
$message = array("message" => " FCM PUSH NOTIFICATION TEST MESSAGE");
$message_status = send_notification($tokens, $message);
echo $message_status;
?>
Es gibt ein gültiges Token in meiner Datenbank. Es zeigt jedoch ungültige Registrierung an. Wie behebe ich das?
Überprüfen Sie Absender-ID in Android und Autorisierung: Schlüssel in PHP-Skript – bindal
@bindal Yup ich verifizierte meine sendor ID und Autorisierung: Schlüssel (Server-Schlüssel) und es ist korrekt. – amus