gpt4 book ai didi

python - Web 推送通知有效负载数据为空

转载 作者:太空宇宙 更新时间:2023-11-03 16:15:15 25 4
gpt4 key购买 nike

您好,我正在尝试为网络实现网络推送通知,我遵循以下 example ,除了我使用 python 脚本连接到 gcm/fcm 并生成有效负载的服务器部分。我正在获取推送事件,但 event.data 为空。

from datetime import datetime
from pyfcm import FCMNotification
pushService = FCMNotification(api_key ='xxx'}
registrationId=""
messageTitle = "New update available"
messageBody ="some message"
dryRun = False
extraData = {}
extraData['title'] = "nknkn"

sw.js

self.addEventListener('push',function(e){

console.log('Push Message Recevied',e.data);
var title = 'Push message';
e.waitUntil(
self.registration.showNotification(title, {
body: 'The Message form data',
icon: 'icon.jpg',
tag: 'my-tag'
}));
});

最佳答案

Google Chrome 和 Mozilla Firefox 目前都支持推送消息的负载,请参阅 PushMessageData在 MDN 上。但根据 Push API 规范,任何有效负载都必须加密,否则浏览器将丢弃它并返回 null(请参阅 11.1.6 ):

If the push message could not be decrypted for any reason, or if it is not encrypted and contains any payload, discard the message and terminate this process. A push message may be empty if it contains no content, but otherwise push event must not be fired for a push message that was not successfully decrypted using the key pair associated with the push subscription.

这里有一篇来自 Google Developers 的好文章,其中提供了更多详细信息:Web Push Payload Encryption 。以及原稿Message Encryption for Web Push .

我还可以建议您查看一组已在不同语言上实现的 WebPush 库:web-push-libs 。您也可以找到一个用 Python 编写的库。 Java 上的另一个库,可以将带有负载的推送消息发送到 Chrome 和 Firefox:https://github.com/MartijnDwars/web-push .

关于python - Web 推送通知有效负载数据为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38992034/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com