Firebase通知MismatchSenderID

时间:2017-06-29 14:13:24

标签: php firebase firebase-cloud-messaging

Phonegap,Android(以及后来的IOS)。 Firebase推送通知。这个文件php在服务器中。不知道如何解决它。一直在寻找几个小时,并没有解决这个问题。 我尝试过创建多个新项目console.firebase.google.com,但似乎没有任何效果。 错误:

{"multicast_id":4891894711706729720,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

<?php

define('SERVER_KEY', '(actualkeyIinserted');
$registrationIds = "";

(connected here, deleted line so I dont show info)

/* check connection */
if ($mysqli->connect_errno) {
    $result = "Connect failed: " . $mysqli->connect_error;
}

$sql = "SELECT * FROM tb_devices ORDER BY id DESC LIMIT 1";
$result = $mysqli->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["id"]. " - Name: " . $row["device"] . "<br>";
        $registrationIds = $row["device"];
    }
} else {
    echo "0 results";
}

$mysqli->close();

if($registrationIds != ""){

    $msg = array
          (
        'body'  => 'Prato em encomenda',
        'title' => 'Alerta',
                'icon'  => 'myicon',/*Default Icon*/
                'sound' => 'mySound'/*Default sound*/
          );

    $fields = array
            (
                'to'        => $registrationIds,
                'notification'  => $msg
            );


    $headers = array
            (
                'Authorization: key=' . SERVER_KEY,
                'Content-Type: application/json'
            );

    #Send Reponse To FireBase Server
    $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_RETURNTRANSFER, true );
    curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
    $result = curl_exec($ch );
    curl_close( $ch );

    #Echo Result Of FireBase Server
    echo $result;

}else{
    echo("No registration ID");
}
?>

0 个答案:

没有答案