我正在尝试使用备用渠道向我的 UWP 应用程序发送推送通知。到目前为止,我已经获得了 URI,并尝试使用 cURL 和 pywebpush 发送推送通知,但在这两种情况下我都得到了 401。我正在使用 JS API 来获取这样的频道:
const pnm = Windows.Networking.PushNotifications.PushNotificationChannelManager.getDefault();
const writer = new Windows.Storage.Streams.DataWriter();
writer.writeString(environment.VAPID_PUBLIC_KEY);
const buffer = writer.detachBuffer();
const notifPromise = pnm.createRawPushNotificationChannelWithAlternateKeyForApplicationAsync(buffer, 'notif');
notifPromise.done(subscription => {
console.log(subscription);
subscription.addEventListener('pushnotificationreceived', message => {
console.log(message);
});
}
cURL 请求返回为
* upload completely sent off: 5 out of 5 bytes
< HTTP/1.1 401 Unauthorized
< Content-Length: 0
< X-WNS-MSG-ID: 1FFF6A946F1C84F4
< X-WNS-DEBUG-TRACE: SG2PEPF00000441
< MS-CV: npI4XUfCt0m9QBptzatEnQ.0
< Strict-Transport-Security: max-age=31536000; includeSubDomains
< WWW-Authenticate: bearer error="invalid_request",error_description="Invalid token"
< Date: Sun, 24 Feb 2019 08:21:00 GMT
我的 URI 的样子,并且添加https://sg2p.notify.windows.com/w/?token=BIG_TOKEN
了Authorization
,TTL
和Crypto-Key
标头。
我正在使用 webpush 通知浏览器,它工作正常。知道这里可能有什么问题吗?