WebPush UnauthorizedRegistration 400尝试从节点Js发送推送通知时出错

我正尝试使用来自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错误。 我已经交叉validation了我的gcm_sender_id和我的服务器密钥。 一切看起来不错,通知在Firefox中testing正常工作,并在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' 

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

Interesting Posts