FCM返回MismatchSenderId [英] FCM returning MismatchSenderId

查看:102
本文介绍了FCM返回MismatchSenderId的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我已经完成了将我的消息传递应用程序从GCM转换为FCM的所有必要步骤,但是它不起作用. FCM当前正在重用MismatchSenderId.

I think I have completed every step necessary to convert my messaging app from GCM to FCM but it is not working. FCM is currently returing MismatchSenderId.

我在AndroidManifest.xml中定义了以下服务.

I have the following services defined in my AndroidManifest.xml .

<service
         android:name=".MyFcmListenerService">
         <intent-filter>
             <action android:name="com.google.firebase.MESSAGING_EVENT" />
         </intent-filter>
     </service>
     <service
         android:name=".MyFirebaseInstanceIDService">
         <intent-filter>
             <action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
         </intent-filter>
     </service>

现在,下面的侦听器代码永远不会被执行,因为消息被拒绝了

Right now the following listener code never gets executed, of course, because the message is getting rejected

public class MyFcmListenerService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage message)
    {
        String from = message.getFrom();
        Map data = message.getData();
        String debug = "what is in data?";
        //todo Process incoming message here
    }

实例ID服务的代码如下. .

The code for the instance Id service is as follows . . .

public class MyFirebaseInstanceIDService extends FirebaseInstanceIdService
{
    private static final String TAG = "MyFirebaseIIDService";
    @Override
    public void onTokenRefresh() {

        String regToken = FirebaseInstanceId.getInstance().getToken();
        //store token in shared memory
        SPHelper.setTempString(GlobalStuff.GCT, "fcmtoken", regToken);
    }
}

我的Firebase控制台上的发件人ID与我的google-services.json中的项目编号匹配.它们都是相同的12位数字.我为控制台定义了两个变体:com.deanblakely.myapp和com.deanblakely.myapp.debug,这两个变体也包含在我的json文件中.

The sender id on my firebase console matches the project number in my google-services.json. They are both the same 12 digit number. I defined two variants to the console: com.deanblakely.myapp and com.deanblakely.myapp.debug and those two variants are also included in my json file.

在完成所有工作之后,我再次下载了google-services.json以确保它与我所拥有的相同.它不是.最新的json增加了这一行,但对我的问题没有影响.

BTW after all work was done I again downloaded google-services.json to make sure it was identical to the one I had. It was not. The most recent json had this one additional line but it had no effect on my issue.

"storage_bucket": "optimal-xxxxxx-824.appspot.com"

以下C#代码在我的服务器上运行,并执行Post to FCM.除了FCM URL外,这是我相同的GCM发布代码. ("regid"实际上是目标电话的FCM令牌).

The following C# code runs on my server and does the Post to FCM. It is my same GCM posting code except for the FCM URL. ("regid" is actually the FCM token of the target phone).

   private string FCMPostToPhone(string regid, string apiKey, string postData)
    {

    //This posts the message to Firebase Cloud Messaging (FCM)

    string PostString = "{ \"registration_ids\": [ \"" + regid + "\" ], \"data\":" + postData + "}";

    byte[] byteArray = Encoding.UTF8.GetBytes(PostString);
    Logger.log("Post to FCM = " + PostString);
    HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("https://fcm.googleapis.com/fcm/send");
    Request.Method = "POST";
    Request.KeepAlive = false;
    Request.ContentType = "application/json";
    Request.Headers.Add(string.Format("Authorization: key={0}", apiKey));
    Request.ContentLength = byteArray.Length;
    Stream dataStream = Request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();
    //  SEND MESSAGE
    try
    {
        WebResponse Response = Request.GetResponse();
        HttpStatusCode ResponseCode = ((HttpWebResponse)Response).StatusCode;
        if (ResponseCode.Equals(HttpStatusCode.Unauthorized) || ResponseCode.Equals(HttpStatusCode.Forbidden))
        {
            Logger.log("Unauthorized - need new token");

        }
        else if (!ResponseCode.Equals(HttpStatusCode.OK))
        {
            Logger.log("Response from web service isn't OK");
        }
        //HttpStatusCode.
        StreamReader Reader = new StreamReader(Response.GetResponseStream());
        string responseLine = Reader.ReadToEnd();
        Reader.Close();
        Logger.log("Post Response from GCM = " + responseLine);

以下是根据上面的代码制作的实际日志,显示了FCM的MimatchSenderId错误(尽管显示为GCM). (该邮件看起来很怪异,因为它全部都已加密).

The following is the actual logs made from the above code showing the MimatchSenderId error from FCM (although it says GCM). (the message looks weird because it’s all encrypted).

6/25/2018 12:08:43 PMDBAWP7发布到GCM = {"registration_ids":[ "eBGLX0_IzPI:APA91bGKIRz6Qu-W-OrFjB2vY5_yS8EanepiZjkz83borQw2bvHwWLvuzNSQAr3WStWDY2ijALLBAnGgq64jWfW2YHMkAImgEKdAWZgJ3YKYJNYJ1YKNJYKNJYKYKYZNJYK1LQY2KYK3YQ1Y2BQJ1Y ], 数据":{ 消息": 9FnAod3oemeAH0iw8oojG5WNnmcqmiGLjIjESex0mHY \ u003d \ n", aeskey": tSFErur1I8O1ADjhP5UTNdpryNwVw156bTr9Hz70//jpJoUIcEE41KOjkrt8yKpQQpSgqgj2A2/GMDXOzIN2wEVnKRqJir7Ylp85DHuj2Z0swOnEuYPUTHXv3z6iQXZlVrw65EP6TrpqyAnCppejqxuDAC2wtQI1zpfRWIlBs9sSnsucOxtpBEbIAo2AdWaBAnL9JtzuMc/XG/IzLKFsH5 + DBOwQccWM4MfK8RbpVmS0RUxzSBbkUi2RBVW86ZP6vzAdliR9qCRVzr2K/X7/7IvCdmpzT5V2LM0xBiXA0Vr8BBBOygXVxM4HYplNS8C7C6eSeb/JzoGD8qj/hMvDTw \ u003d \ u003d",fromLang :"英语," fromPhoneKey:" gbsamsung," fromUsername:"," mine:" y," subActive:" n," timeSentGMT:" 2018-06-25 19:08:43," toPhoneKey:" emulator27," tran:" ## 03}}

6/25/2018 12:08:43 PMDBAWP7 Post to GCM = { "registration_ids": [ "eBGLX0_IzPI:APA91bGKIRz6Qu-W-OrFjB2vY5_yS8EanepiZjkz83borQw2bvHwWLvuzNSQAr3WStWDY2ijALLBAnGgq64jWfW2YHMkAImgEKdAWZvgj7m1MXgpB9_2zH7uRdLUQNAG2jmEK3YzHYxgJBQTq_Cgz1mOpNxbDeLU3A" ], "data":{"Message":"9FnAod3oemeAH0iw8oojG5WNnmcqmiGLjIjESex0mHY\u003d\n","aeskey":"tSFErur1I8O1ADjhP5UTNdpryNwVw156bTr9Hz70//jpJoUIcEE41KOjkrt8yKpQQpSgqgj2A2/GMDXOzIN2wEVnKRqJir7Ylp85DHuj2Z0swOnEuYPUTHXv3z6iQXZlVrw65EP6TrpqyAnCppejqxuDAC2wtQI1zpfRWIlBs9sSnsucOxtpBEbIAo2AdWaBAnL9JtzuMc/xG/IzLKFsH5+DBOwQccWM4MfK8RbpVmS0RUxzSBbkUi2RBVW86ZP6vzAdliR9qCRVzr2K/x7/7IvCdmpzT5V2LM0xBiXA0Vr8BBBOygXVxM4HYplNS8C7C6eSeb/JzoGD8qj/hMvDTw\u003d\u003d","fromLang":"English","fromPhoneKey":"gbsamsung","fromUsername":"","mine":"y","subActive":"n","timeSentGMT":"2018-06-25 19:08:43","toPhoneKey":"emulator27","tran":"##03"}}

6/25/2018 12:08:44 PMDBAWP7来自GCM的帖子回复= {"multicast_id":5172924974567668915,成功":0,失败":1,"canonical_ids":0,结果":[{错误":"MismatchSenderId"}]}}

6/25/2018 12:08:44 PMDBAWP7 Post Response from GCM = {"multicast_id":5172924974567668915,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

在我的项目中,我没有使用代码中的SENDER_ID进行任何操作.

Nowhere in my project do I do anything with SENDER_ID in my code.

推荐答案

我只是遇到了类似的问题.我发现,甚至有多个google-services.xml文件(由合并引起),即使文件名不同(例如google-services_LOCAL_46008),也可能包含在构建中,从而导致ID错误.检查您的包含google-services.xml的文件夹中只有一个文件.我删除了所有多余的xml文件,它起作用了.

I just had a similar issue. What I found was that there were more than one google-services.xml files (caused by merging), even with different names (like google-services_LOCAL_46008) that were probably included in the build, causing a wrong ID. Check your folder that contains the google-services.xml that there is only one file. One I removed any extraneous xml files, it worked.

这篇关于FCM返回MismatchSenderId的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆