FCM Firebase推送消息传递发送者ID MISSMATCH



我正在尝试将网站现代化成为PWA。一部分是推送通知。到目前为止,我添加了gcm_sender_id的清单,并订阅了推送服务。我尝试了自我生成的vapid-key或Google Firebase提供的自动脉络。摘要:

   var reg;
   navigator.serviceWorker.ready
      .then(function(swreg) {
         console.log('SW ready');
         reg = swreg;
         return swreg.pushManager.getSubscription();
      })
      .then(function(sub) {
         console.log('SW ready.then');
         if (sub === null) {
            var vapidPublicKey = 'BEP1z-pU7KfRqXjQGbB_af7YydA1Hxzb3EWDYyb5q44YEflE8RaT0wISdJJnvQlzBkVuC4CupAqU2wm0SxCjxpk';
            // taken^^ from the fcm console under cloud messaging web configuration
            var convertedVapidPublicKey = urlBase64ToUint8Array(vapidPublicKey);
            console.log(convertedVapidPublicKey);
            var retval = reg.pushManager.subscribe({
               userVisibleOnly: true,
               applicationServerKey: convertedVapidPublicKey
            });
            return retval;
         }
         return sub;
      })
      .then(function(newSub) {
         console.log('Received PushSubscription: ', JSON.stringify(newSub));
         return newSub
      })
      .then(function(res) {
         console.log('SW ready.then.then.then');
            if (res.ok) {
               displayConfirmNotification();
            }
      })
      .catch(function(err) {
            console.log(err);
      });

我得到订阅:

Received PushSubscription:  {"endpoint":"https://fcm.googleapis.com/fcm/send/eU1Mfq-f1So:APA91bEds1D8pio29fNYdMoAQfd_zXcfai7OR_JzppN-Dq5hMhv3_tI9HZHlATBuwBcaPYC6bkmwMXm6IVZ1T83o8r3l8Dyyvxlvy191MjVwc1eKsy8lD1E2sGNaKrZrb5a2qDr9vUi9","expirationTime":null,"keys":{"p256dh":"BLiNeIZqBMTskRwnV5YCtdQFAcbj_-l2fyhOBpcRSOklLy7iv0Ru0XHjJJqOauHeYWk_9rpAjM7lVyVr7_oGHyE","auth":"yXHXHjFu0EiXRXjN8KMEyA"}}

到目前为止一切都很好。据我了解这一过程,浏览器(在本例中为Chrome(与Google Chrome服务器和订阅的文件联系。使用的VAPID密钥使Firebase可以联系Chrome服务器,然后通过专有代码触发通知,该代码会因每个浏览器而变化。

现在我尝试实际使用我的订阅:

$ curl "https://fcm.googleapis.com/fcm/send/eU1Mfq-f1So:APA91bEds1D8pio29fNYdMoAQfd_zXcfai7OR_JzppN-Dq5hMhv3_tI9HZHlATBuwBcaPYC6bkmwMXm6IVZ1T83o8r3l8Dyyvxlvy191MjVwc1eKsy8lD1E2sGNaKrZrb5a2qDr9vUi9" --request POST --header "TTL: 60" --header "Content-Length: 0" --header "Authorization: key=[server key from fcm console under cloud messaging server key (first entry)"
the key in the authorization header does not correspond to the sender ID used to subscribe this user. Please ensure you are using the correct sender ID and server Key from the Firebase console.

我几次替换了钥匙。没有什么变化。Google在此字符串上什么都没有。

我有node.js express,postgres,angular 8 app。

我通过添加" gcm_sender_id"来使它起作用:我还使用了Firebase生成的公共和私钥

您的gcm_sender_id是您的项目ID,在Google Cloud或Firebase发件人ID

最新更新