ApnsPHP:推送通知在开发中工作但不在生产中
是的:这个问题有很多重复,但没有一个答案有帮助.
我正在关注这个伟大的tutorial by Ali Hafizji on using APNS service for push notifications. 在开发模式下测试APNS: >下载aps_development.cer 然后我使用以下命令(使用终端)将两者结合起来: openssl x509 -in aps_development.cer -inform der -out aps_development.pem openssl pkcs12 -nocerts -out aps_development_key.pem -in aps_development.p12 cat aps_development.pem aps_development_key.pem > final_aps_development.pem 并且(在服务器上使用ApnsPHP)我可以使用此配置成功发送推送通知: ... $push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,'final_aps_development.pem'); $push->setRootCertificationAuthority('entrust_root_certification_authority.pem'); $push->setProviderCertificatePassphrase('mypassword'); ... 旁注:我从https://github.com/jonathanrcarter/push2press获得了entrust_root_certification_authority.pem, 在这种情况下,应用程序在调试模式下运行(在设备上,从XCode运行),一切正常. 在生产模式下测试APNS: 为了在生产模式下测试APNS,我将应用程序归档为AdHoc分发,并使用iPhone Configuration Utility将其安装在设备上. 我使用aps_production.cer执行相同的过程来生成final_aps_production.pem. Bang,调用发送推送通知的php脚本返回HTML状态代码500. $push生成当然是为生产模式修改的: ... $push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,'final_aps_production.pem'); $push->setRootCertificationAuthority('entrust_root_certification_authority.pem'); $push->setProviderCertificatePassphrase('mypassword'); ... 快速查看/var/log/apache2/error.log表明问题: PHP Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.push.apple.com:2195': (0)' in /var/www/gettapro/mobile/ApnsPHP/Abstract.php:398nStack trace:n#0 /var/www/gettapro/mobile/ApnsPHP/Abstract.php(334): ApnsPHP_Abstract->_connect()n#1 .... 谷歌搜索(有很多人有这个问题)证明没有结果. 许多不同的建议,甚至如此眩晕,以至于将持有证书的目录的文件权限更改为775 …没有任何建议对我有用. 我也在ApnsPHP / Abstract.php(这里建议:https://github.com/duccio/ApnsPHP/issues/29)中尝试了这个改变,但没有成功. $streamContext = stream_context_create(array('ssl' => array( //'verify_peer' => isset($this->_sRootCertificationAuthorityFile),'cafile' => $this->_sRootCertificationAuthorityFile,'local_cert' => $this->_sProviderCertificateFile ))); 那令人讨厌的ApnsPHP_Exception并没有消失. 当然,我也确保在我测试生产模式时正确的设备APNS 无论如何:令牌不是问题,因为我的通知发送脚本甚至无法连接到ssl://gateway.push.apple.com:2195. 试图通过telnet连接ssl://gateway.push.apple.com:2195只是为了确保:连接没问题. 很明显:这是一个证书问题. 解决方法
似乎aps_production.cer不应该像aps_development.cer那样被handeled
这是RTM moment. 在钥匙串中下载并安装证书(双击aps_production.cer) 从Keychain Access导出.ps12版本的aps_production证书(此处也设置了密码). 使用此命令将其转换为.pem格式(您必须在此处输入密码): openssl pkcs12 -in aps_production.p12 -out final_aps_production.pem -nodes 瞧 – 一切都开始了,我又是一个快乐的露营者. Jeremy提供了关于如何出口证书和附件的精彩指导说明.关键here on SO. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |