且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android 未收到 Firebase 推送通知 - MismatchSenderId

更新时间:2021-06-30 21:46:19

编辑#1:

1) 确保向 fcm 发送有效的 json.2) 确保您发送到正确的令牌.

Edit #1:

1) Make sure you are sending a valid json to the fcm. 2) Make sure you are sending to the right token.

关于如何发送通知的其他信息:

Other informations on how to send notifications:

向特定设备发送消息

要将消息发送到特定设备,请将 设置为特定应用实例的注册令牌

To send messages to specific devices, set the to the registration token for the specific app instance

curl -H "Content-type: application/json" -H "Authorization:key=<Your Api key>"  -X POST -d '{ "data": { "score": "5x1","time": "15:10"},"to" : "<registration token>"}' https://fcm.googleapis.com/fcm/send

向主题发送消息

这里的主题是:/topics/foo-bar

here the topic is : /topics/foo-bar

curl -H "Content-type: application/json" -H "Authorisation:key=<Your Api key>"  -X POST -d '{ "to": "/topics/foo-bar","data": { "message": "This is a Firebase Cloud Messaging Topic Message!"}}' https://fcm.googleapis.com/fcm/send

向设备组发送消息

向设备组发送消息与向单个设备发送消息非常相似.将 to 参数设置为设备组的唯一通知键

Sending messages to a device group is very similar to sending messages to an individual device. Set the to parameter to the unique notification key for the device group

curl -H "Content-type: application/json" -H "Authorisation:key=<Your Api key>"  -X POST -d '{"to": "<aUniqueKey>","data": {"hello": "This is a Firebase Cloud Messaging Device Group Message!"}}' https://fcm.googleapis.com/fcm/send

原文:

问题是你的服务器配置.如果您想在单个服务器中管理两个 Firebase 应用程序,您必须使用位于以下位置的 Firebase APK_KEY 配置两个 Firebase 应用程序:

Original:

The problem is you server configuration. If you want to manage two firebase apps in single server you have you have to config two firebase apps with your Firebase APK_KEY that located at:

在 Firebase 控制台中转到您的应用程序 -> 点击右上角的三个点 -> 管理 -> CLOUD MESSAGES ->(服务器密钥)

Go to your applications in Firebase console -> Click on three dots at the top right -> Manage -> CLOUD MESSAGES -> (Server key)

获得两个应用程序的两个服务器密钥后,您必须像这样配置它:

After you get your both server keys for your two apps, you have to configure it like this:

var firebaseLib = require("firebase");

var app1Config = {
    apiKey: "<PROJECT_1_API_KEY>",
    authDomain: "<PROJECT_1_ID>.firebaseapp.com",
    databaseURL: "https://<PROJECT_1_DATABASE_NAME>.firebaseio.com",
    storageBucket: "<PROJECT_1_BUCKET>.appspot.com",
}
var app2Config = {
    apiKey: "<PROJECT_2_API_KEY>",
    authDomain: "<PROJECT_2_ID>.firebaseapp.com",
    databaseURL: "https://<PROJECT_2_DATABASE_NAME>.firebaseio.com",
    storageBucket: "<PROJECT_2_BUCKET>.appspot.com",
}

var firebaseApp1 = firebaseLib.initailize(app1Config); // Primary
var firebaseApp2 = firebaseLib.initailize(app2Config, "Secondary"); // Secondary