Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios APNS_证书-推送通知未在生产中发送_Ios_Django_Python 3.x_Apple Push Notifications_Django Push Notifications - Fatal编程技术网

Ios APNS_证书-推送通知未在生产中发送

Ios APNS_证书-推送通知未在生产中发送,ios,django,python-3.x,apple-push-notifications,django-push-notifications,Ios,Django,Python 3.x,Apple Push Notifications,Django Push Notifications,我已经有这个问题大约两周了,当时我突然停止在生产中发送通知。我使用的是django推送通知库,django管理员可以发送测试消息,但它不会通过系统发送消息 在我的本地电脑上,一切都完美无瑕。我发现了一个测试证书的命令: openssl s_client -connect gateway.push.apple.com:2195 -cert apns-cert.pem 有了这个,我得到了返回:Timeout:7200(秒)Verify return 代码:20(无法获取本地颁发者证书)扩展主机 秘

我已经有这个问题大约两周了,当时我突然停止在生产中发送通知。我使用的是django推送通知库,django管理员可以发送测试消息,但它不会通过系统发送消息

在我的本地电脑上,一切都完美无瑕。我发现了一个测试证书的命令:

openssl s_client -connect gateway.push.apple.com:2195 -cert apns-cert.pem
有了这个,我得到了返回:Timeout:7200(秒)Verify return 代码:20(无法获取本地颁发者证书)扩展主机 秘密:是的

因此,通过大量研究,我发现我需要将“CA”的路径:

谁将我带到:验证返回代码:0(确定)

但是,为了在库中使用,我需要放置.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 = {
     "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}' 
不幸的是,它仍然没有发送推送,并且没有错误,因为我已将其配置为通过电子邮件发送弹出错误。


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

事实上,这不是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"])

事实上,这不是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"])

我不是一个人!我也有同样的问题,这只发生在生产环境中!所以问题可能出在苹果方面,也可能是django推送通知中的任何贬值。我发现了它停止工作的原因。我的queryset选择要发送消息的设备,结果对于基础的较旧设备,它会突发“令牌无效”错误。这导致函数被取消。我通过循环和忽略错误解决了这个问题,在循环中一个设备一个设备地发送。谢谢分享。我会检查我的项目。我不是一个人!我也有同样的问题,这只发生在生产环境中!所以问题可能出在苹果方面,也可能是django推送通知中的任何贬值。我发现了它停止工作的原因。我的queryset选择要发送消息的设备,结果对于基础的较旧设备,它会突发“令牌无效”错误。这导致函数被取消。我通过循环和忽略错误解决了这个问题,在循环中一个设备一个设备地发送。谢谢分享。我将签入我的项目。