0

我正在发送以下通知

Authorization:key=A.....
Content-Type:application/json    
{
    "to" : "cBx_ErhkhNw:APA91bEzwHvZ2daEK15Y3A0VAprxPV-4GGq10FjlrFnHzCs8xSJXz2lATjh9AoLRQvnSseT6r4ggApC6TbtD9M_sI_BDDmycZ1TEVn0HaF5pAABeSbHqcOK-kmkPqOve1VThUaUIXQy4",

      "notification": {
        "title": "Test Nachricht",
        "body": "This is a message from FCM to web"
      },
      "priority": "high",
      "webpush": {
      "fcm_options": {
        "link": "https://dummypage.com"
      }
    }

}

并具有以下代码:

应用程序.js

 // Initialize Firebase
 var config = {
     apiKey: "<KEY>",
     authDomain: "<AUTH_DOMAIN>",
     databaseURL: "<DB_URL>",
     projectId: "atlas-test-35d33",
     storageBucket: "<STORAGE_BUCKET>",
     messagingSenderId: "817272374311"
 };
 firebase.initializeApp(config);
 const messaging = firebase.messaging();
 messaging.usePublicVapidKey("<PUBLIC_KEY>");
 messaging.requestPermission()
     .then(function() {
         console.log("Permission granted");
         return messaging.getToken()
     })
     .then(function(token) {
         console.log(token)
     })
     .catch(function(err) {
         console.log(err)
     })
 console.log("listenting")
 messaging.onMessage(function(payload) {
     console.log('Message received. ', payload);
     // ...
 });

firebase-messaging-sw.js

    // Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/5.9.0/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/5.9.0/firebase-messaging.js');

  var config = {
    apiKey: "<KEY>",
    authDomain: "<AUTH_DOMAIN>",
    databaseURL: "https://atlas-test-35d33.firebaseio.com",
    projectId: "atlas-test-35d33",
    storageBucket: "<STORAGE_BUCKET>",
    messagingSenderId: "817272374311"
  };
  firebase.initializeApp(config);

// Retrieve an instance of Firebase Messaging so that it can handle background
// messages.
const messaging = firebase.messaging();

当我尝试向 fcm 服务器发送通知时,我得到以下响应:

{
    "multicast_id": 5394725759940263108,
    "success": 1,
    "failure": 0,
    "canonical_ids": 0,
    "results": [
        {
            "message_id": "0:1552646324437940%e609af1cf9fd7ecd"
        }
    ]
}

看起来,对我来说一切都很好。但是我在我的 Web 应用程序中没有收到任何东西。我只是为了测试目的硬编码了“to”令牌,但我认为这不是问题所在。

您是否有任何线索是什么问题,或者是否有任何调试的可能性。

谢谢!

4

0 回答 0