Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

php - Firebase MismatchSenderID when Authorization key is my Server key

Really weird and no one has ever asked this.

I'm getting MismatchSenderIdas an error with my server key as my authorization key(server key). And on the other hand, I'm getting success as a return result from my push_notification() if my device's token as my authorization key, but no notification is received on my device.

I'm sure that my token is correct because I'm able to send to a single device with token in firebase (single device) console.

Which then leads me to this another question, but then I would like to confirm this issue before moving to the notification part

I'm pretty lost actually, since that all MismatchSenderId errors were resolved with replacing with the correct server key.

    <?php 
    require "dbconfig.php";

    $sql = "SELECT token FROM tokendb";
    $result = mysql_query($sql) or die($sql."<br/><br/>".mysql_error());
    $tokens = array();

    while($row = mysql_fetch_assoc($result))
    {
        echo $row['token']; //this shows the same token compared to the token show in logcat(visual studio)
        $tokens[] = $row["token"];

      echo '<form id="form1" name="form1" method="post" action="">'.
    '<p>From<br>'.
    '<input type="text" size="100" maxlength="100" name="From" id="From" /><br>'.
    '<p>Title<br>'.
    '<input type="text" size="100" maxlength="100" name="Title" id="Title" />'.
    '<br>'.
    '<input type="submit" name="Send" id="Send" value="Send" />'.
    '</form>';

    }

    $message = array("message" => "notification test");
    $message_status = sendFCMMessage($message, $tokens);
    echo $message_status;

    function sendFCMMessage($message,$target){

       //FCM API end-point
       $url = 'https://fcm.googleapis.com/fcm/send';

       $fields = array();
       $fields['body'] = $message;
       if(is_array($target)){
        $fields['registration_ids'] = $target;
       }else{
        $fields['to'] = $target;
       }

       //header with content_type api key
       $headers = array(
        'Content-Type:application/json',
            'Authorization:key=********'
       );
       //CURL request to route notification to FCM connection server (provided by Google)           
       $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('Oops! FCM Send Error: ' . curl_error($ch));
       }
       curl_close($ch);
       return $result;
    }

    ?>

EDIT: This short php code is also giving me MismatchSenderId error

  <?php
$ch = curl_init("https://fcm.googleapis.com/fcm/send");
$header=array('Content-Type: application/json',
"Authorization: key=***(serverkey from project)");
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{ "notification": {    "title": "Test desde curl",    "text": "Otra prueba"  },    "to" : "my device's token"}");

curl_exec($ch);
curl_close($ch);
?>

UPDATE

Uninstalling and reinstalling the app resolved the issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...