【问题标题】:Web Push Notification with Encrypted Payload in Python使用 Python 加密有效负载的 Web 推送通知
【发布时间】:2016-12-10 11:25:21
【问题描述】:

谁能解释一下如何使用 Python/Django 使用 Payload for Chrome 发送通知

我正在这样做-

    fcm_url = "https://fcm.googleapis.com/fcm/send"
    encoded = WebPusher(subscription_info).encode(json.dumps(data))

    crypto_key = "dh=" + encoded["crypto_key"]
    salt = "salt=" + encoded['salt']

    headers = {'Authorization': 'key=' + gcm_key, 'Content-Type': 'application/json', }
    headers.update({'crypto-key': crypto_key, 'content-encoding': 'aesgcm', 'encryption': salt})    

    fcm_data = {"raw_data":base64.b64encode(encoded.get('body')), "registration_ids": ['eYXdX1V94XY:APA91bHPQdnlQiVwe5HmWnRQrtpOnHzAJ4kEHNgB8GrEZ_YxSgtwz-0gvcpUFBAb3_eVXOVcJAjvVotGfKl9jLGM_X6nZb76YzFBZazMu1auIDAXhXjUgFDHm7E2ffRpBD70rpD1qC1r']}

    resp = requests.post(fcm_url,data=json.dumps(fcm_data),headers=headers)

输出:-

{"multicast_id":6483153199368608385,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1481362362576359%958b01adf9fd7ecd"}]}

但通知不包含上述指定的数据。

【问题讨论】:

  • 我认为这个问题类似于this thread
  • 是的,这是一样的,但对我不起作用,我无法评论这个线程所以......

标签: django python-2.7 google-cloud-messaging firebase-cloud-messaging


【解决方案1】:

您似乎正在混合使用 Web 推送协议和 Firebase 云消息传递 API。

您是在尝试向正常打开的网络 PushSubscription 发送请求,还是尝试向 Firebase 令牌发送请求?

如果您使用 Firebase Messaging SDK for web,则无需加密负载(这是使用 Firebase 消息 SDK 的主要原因之一)。

如果您只使用普通的开放式 Web API 而没有接触 Firebase 消息传递 SDK,我会查看:https://github.com/web-push-libs/pywebpush

【讨论】:

    猜你喜欢
    • 2016-12-08
    • 2018-04-04
    • 2021-04-26
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多