WebPush UnauthorizedRegistration 400尝试从节点J

时间:2017-08-07 13:19:24

标签: javascript node.js google-chrome push-notification web-push

我正在尝试使用NodeJS的Web Push发送推送通知。以下是我在前端获取订阅的方式:

swRegistration.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: "SOME_APPLICATION_PUBLIC_KEY"
}).....

这是我用来发送推送通知的NodeJS:

const webpush = require('web-push');
const options = {
  vapidDetails: {
    subject: 'mailto:SOME_MAIL_ID',
    publicKey: 'SOME_PUBLIC_KEY',
    privateKey: 'SOME_PRIVATE_KEY'
  }
};
const pushSubscription = {"endpoint":"https://fcm.googleapis.com/fcm/send/SOME_END_POINT","keys{"p256dh":"SOME VALUE","auth":"SOME_VALUE"}};
webpush.sendNotification(pushSubscription, "Test Notification", options)
.then(function(response) { console.log(response) })
.catch(function(error) {console.log(error)});

然后我收到400错误。我已经交叉验证了我的gcm_sender_id和我的服务器密钥。一切看起来都不错,并且在Firefox中测试时通知正常工作,并且在Chrome中失败。

以下是我遇到的错误:

  name: 'WebPushError',
  message: 'Received unexpected response code',
  statusCode: 400,
  headers: 
   { 'content-type': 'text/html; charset=UTF-8',
     date: 'Mon, 07 Aug 2017 13:04:32 GMT',
     expires: 'Mon, 07 Aug 2017 13:04:32 GMT',
     'cache-control': 'private, max-age=0',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'SAMEORIGIN',
     'x-xss-protection': '1; mode=block',
     server: 'GSE',
     'alt-svc': 'quic=":443"; ma=2592000; v="39,38,37,36,35"',
     'accept-ranges': 'none',
     vary: 'Accept-Encoding',
     connection: 'close' },
  body: '<HTML>\n<HEAD>\n<TITLE>UnauthorizedRegistration</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>UnauthorizedRegistration</H1>\n<H2>Error 400</H2>\n</BODY>\n</HTML>\n',
  endpoint: 'https://fcm.googleapis.com/fcm/send/SOME_END_POINT' 

我看到很多用户都有这个问题,但我找不到合适的解决方案。请帮我解决这个问题。

0 个答案:

没有答案