【问题标题】:APNS_CERTIFICATE - Push Notification does not send in productionAPNS_CERTIFICATE - 推送通知不会在生产中发送
【发布时间】:2016-12-30 00:47:44
【问题描述】:

我遇到此问题大约 2 周,当时我突然停止在生产中发送通知。我正在使用 django-push-notifications 库,通过 django admin 我可以发送测试消息,但它不会通过系统发送消息。

在我的本地计算机上,一切正常。我发现了一个测试证书的命令:

openssl s_client -connect gateway.push.apple.com:2195 -cert apns-cert.pem

有了这个我有回报:超时:7200(秒)验证回报 代码:20(无法获得本地颁发者证书)扩展主 秘密:是的

所以经过大量研究,我发现我需要放置“CA”的路径:

openssl s_client -CApath /etc/ssl/certs/ -connect gateway.push.apple.com:2195 -cert apns-cert.pem

谁带我去:验证返回码:0(ok)

但是,为了在库中使用,我需要放置 .pem 文件的完整路径。然后我找到了这个命令:

ls /etc/ssl/certs/Entrust*

我测试了所有的 .pem 文件,直到我达到了看起来完美的结果:

openssl s_client -CAfile /etc/ssl/certs/Entrust.net_Premium_2048_Secure_Server_CA.pem -connect gateway.push.apple.com:2195 -cert apns-cert.pem

很快,我格式化了我的 PUSH_NOTIFICATIONS_SETTINGS:

PUSH_NOTIFICATIONS_SETTINGS = {
     "GCM_API_KEY": "xxxx",
    "APNS_CERTIFICATE": os.path.join(BASE_DIR, "apns-cert.pem"),
    "APNS_CA_CERTIFICATES": "/etc/ssl/certs/Entrust.net_Premium_2048_Secure_Server_CA.pem",
    "APNS_ERROR_TIMEOUT": 3,
}


IOS_VERIFY_RECEIPT_API = 'https://buy.itunes.apple.com/verifyReceipt'
ANDROID_VERIFY_RECEIPT_API = 'https://www.googleapis.com/androidpublisher/v2/applications/{packageName}/purchases/subscriptions/{subscriptionId}/tokens/{token}' 

很遗憾,它仍然不发送 PUSH,也没有错误,因为我已将其配置为弹出错误以通过电子邮件发送。

PS:通过 django admin 发送测试文本记住这一点:好的。通过沙箱发送(调试):OK。

【问题讨论】:

  • 我并不孤单!我遇到了同样的问题,只发生在生产环境中!所以问题可能出在 Apple 一方或 django-push-notifications 中任何可能的贬值。
  • 我发现了它停止工作的原因。我的查询集选择发送消息的设备,最终爆出“令牌无效”的错误,对于基础的旧设备。这导致功能被取消。我通过循环并忽略错误来解决,在循环内逐个设备发送设备。
  • 感谢分享。将签入我的项目。

标签: ios django python-3.x apple-push-notifications django-push-notifications


【解决方案1】:

实际上这不是 SSL 问题,而是库的批量上传错误。

在系统中注册的令牌已过期,库不知道如何使用它并取消了操作,导致没有其他令牌被尝试。我通过向我的电子邮件发送测试来循环和忽略单个错误来纠正问题:

 def send_push(self):
    errors = []

    # IOS
    queryset_ios = APNSDevice.objects.filter(user=self.authentication)
    for device in queryset_ios:
        try:
            device.send_message(self.subject, badge=1, sound=self.kind.sound)
        except APNSServerError as e:
            errors.append(APNS_ERROR_MESSAGES[e.status])
        except Exception:
            pass

    # ANDROID
    queryset_android = GCMDevice.objects.filter(user=self.authentication)
    extra = {'notification': self.pk, 'kind': self.kind.kind, 'sound': self.kind.sound}

    for device in queryset_android:
        try:
            queryset_android.send_message(self.subject, badge=1, extra=extra)
        except GCMError as e:
            errors.append(str(e))
        except Exception:
            pass

    if errors:
        send_mail("Push Error",
                  "Push: %s \n User: %s \n\n Errors: %s" % (self.subject, self.authentication.full_name, errors),
                  settings.DEFAULT_FROM_EMAIL, ["my@mail.com"])

【讨论】:

    猜你喜欢
    • 2013-06-10
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-27
    • 1970-01-01
    相关资源
    最近更新 更多