<i id='EpJvf'><tr id='EpJvf'><dt id='EpJvf'><q id='EpJvf'><span id='EpJvf'><b id='EpJvf'><form id='EpJvf'><ins id='EpJvf'></ins><ul id='EpJvf'></ul><sub id='EpJvf'></sub></form><legend id='EpJvf'></legend><bdo id='EpJvf'><pre id='EpJvf'><center id='EpJvf'></center></pre></bdo></b><th id='EpJvf'></th></span></q></dt></tr></i><div id='EpJvf'><tfoot id='EpJvf'></tfoot><dl id='EpJvf'><fieldset id='EpJvf'></fieldset></dl></div>

        <bdo id='EpJvf'></bdo><ul id='EpJvf'></ul>
      <legend id='EpJvf'><style id='EpJvf'><dir id='EpJvf'><q id='EpJvf'></q></dir></style></legend>

    1. <small id='EpJvf'></small><noframes id='EpJvf'>

      <tfoot id='EpJvf'></tfoot>
      1. 当授权密钥是我的服务器密钥时的 Firebase MismatchSenderID

        时间:2024-08-22

          <i id='DjdJJ'><tr id='DjdJJ'><dt id='DjdJJ'><q id='DjdJJ'><span id='DjdJJ'><b id='DjdJJ'><form id='DjdJJ'><ins id='DjdJJ'></ins><ul id='DjdJJ'></ul><sub id='DjdJJ'></sub></form><legend id='DjdJJ'></legend><bdo id='DjdJJ'><pre id='DjdJJ'><center id='DjdJJ'></center></pre></bdo></b><th id='DjdJJ'></th></span></q></dt></tr></i><div id='DjdJJ'><tfoot id='DjdJJ'></tfoot><dl id='DjdJJ'><fieldset id='DjdJJ'></fieldset></dl></div>

          1. <small id='DjdJJ'></small><noframes id='DjdJJ'>

            <legend id='DjdJJ'><style id='DjdJJ'><dir id='DjdJJ'><q id='DjdJJ'></q></dir></style></legend>
              <bdo id='DjdJJ'></bdo><ul id='DjdJJ'></ul>
                <tbody id='DjdJJ'></tbody>
            • <tfoot id='DjdJJ'></tfoot>
                  本文介绍了当授权密钥是我的服务器密钥时的 Firebase MismatchSenderID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  真的很奇怪,从来没有人问过这个问题.

                  Really weird and no one has ever asked this.

                  我收到 MismatchSenderId 作为我的服务器密钥作为我的授权密钥(服务器密钥)的错误.另一方面,如果我的设备令牌作为我的授权密钥,我会从我的 push_notification() 返回成功,但我的设备上没有收到任何通知.

                  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.

                  我确定我的令牌是正确的,因为我能够在 firebase(单个设备)控制台中使用令牌发送到单个设备.

                  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

                  实际上我很迷茫,因为所有 MismatchSenderId 错误都已通过替换为正确的服务器密钥来解决.

                  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:这个简短的 php 代码也给了我 MismatchSenderId 错误

                  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);
                  ?>
                  

                  更新

                  卸载并重新安装应用程序解决了这个问题.

                  Uninstalling and reinstalling the app resolved the issue.

                  推荐答案

                  MismatchSenderId 在您尝试发送到与不同发件人(项目)关联的注册令牌时遇到错误.来自文档:

                  The MismatchSenderId error is encountered when you are attempting to send to a registration token that is associated with a different Sender (Project). From the docs:

                  注册令牌与特定的发件人组相关联.当客户端应用注册 FCM 时,它必须指定允许哪些发件人发送消息.在向客户端应用程序发送消息时,您应该使用其中一个发件人 ID.如果您切换到其他发件人,现有的注册令牌将不起作用.

                  A registration token is tied to a certain group of senders. When a client app registers for FCM, it must specify which senders are allowed to send messages. You should use one of those sender IDs when sending messages to the client app. If you switch to a different sender, the existing registration tokens won't work.

                  确保您使用的服务器密钥来自与注册令牌关联的同一个发件人项目.您可以通过检查您的 google-services.json 文件并查看其中的 Sender ID 是否与您用于发送消息的 Firebase 项目中可见的 Sender ID 匹配来执行此操作.

                  Make sure that the Server Key you are using is from the same Sender Project that the registration token is associated to. You can do this by checking your google-services.json file and see if the Sender ID there matches the Sender ID visible in the Firebase Project you are using to send the message.

                  关于不接收消息的问题,您的代码发送的有效负载的结构有点不清楚.尝试使用 notification 和/或 data 消息负载检查它是否是结构正确的消息负载.

                  For the matter of not receiving messages, It's a bit unclear as to what is the structure of payload that your code is sending. Try checking if it is a properly structured message payload with a notification and/or data message payload.

                  这篇关于当授权密钥是我的服务器密钥时的 Firebase MismatchSenderID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从服务器端向安卓设备发送 FCM 消息 下一篇:如何从网络向应用发送 FCM 通知

                  相关文章

                  <small id='ME4Lb'></small><noframes id='ME4Lb'>

                  <legend id='ME4Lb'><style id='ME4Lb'><dir id='ME4Lb'><q id='ME4Lb'></q></dir></style></legend>
                  • <bdo id='ME4Lb'></bdo><ul id='ME4Lb'></ul>
                  <tfoot id='ME4Lb'></tfoot>

                    <i id='ME4Lb'><tr id='ME4Lb'><dt id='ME4Lb'><q id='ME4Lb'><span id='ME4Lb'><b id='ME4Lb'><form id='ME4Lb'><ins id='ME4Lb'></ins><ul id='ME4Lb'></ul><sub id='ME4Lb'></sub></form><legend id='ME4Lb'></legend><bdo id='ME4Lb'><pre id='ME4Lb'><center id='ME4Lb'></center></pre></bdo></b><th id='ME4Lb'></th></span></q></dt></tr></i><div id='ME4Lb'><tfoot id='ME4Lb'></tfoot><dl id='ME4Lb'><fieldset id='ME4Lb'></fieldset></dl></div>