未收到 Firebase 消息

Firebase message not received

我初始化 Web firebase 并获得令牌:

https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/web/src/main/web/js/initFirebase.js

我在创建当前令牌后获取它,并在简单消息中发送它:

curl -X POST -H "Authorization: key=AAAA_XXXMYKEYXXXw26gv" -H "Content-Type: application/json" -d '{
    "to" : "fo3aexgjsbQ:APA91bEWh47m2cVoflhQ_E__E31jbQpoyaHZTRKmkJIG7Uaarrw0KwvCYYCnNTMmaQIcKBFrq2fGFEBj-nVB9obE-wf4FiTCKedR_gWdMPfc8bNgpK5MQ7SsLmcVRWLlert3AXXdbuzk",
    "data" : {
      "body" : "This is an FCM notification message!",
      "title" : "FCM Message",
    }
}' "https://fcm.googleapis.com/fcm/send"

我得到以下成功结果:

{"multicast_id":8683406144829883570,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1512147661586241%2fd9afcdf9fd7ecd"}]}

问题是控制台没有显示或打印任何内容!我正在发送请求,我看到成功并且...网站打开和关闭时都没有任何反应!

这是我放在根目录中的 firebase-messaging-sw.js 文件:

https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/web/src/main/web/firebase-messaging-sw.js

我也试过这样设置配置:

firebase.initializeApp({
  'messagingSenderId': '1091715558873'
});

我指定清单:

https://github.com/MarcinMoskala/KotlinAcademyApp/blob/master/web/src/main/web/manifest.json

因为您的负载使用密钥 data,您发送的是 data message, not a notification. They are handled differently, as explained in the documentation

data更改为notification

"to" : "fo3aexgjsbQ:APA91bEWh47m2cVoflhQ_E__E31jbQpoyaHZTRKmkJIG7Uaarrw0KwvCYYCnNTMmaQIcKBFrq2fGFEBj-nVB9obE-wf4FiTCKedR_gWdMPfc8bNgpK5MQ7SsLmcVRWLlert3AXXdbuzk",
"notification" : {
  "body" : "This is an FCM notification message!",
  "title" : "FCM Message",