【发布时间】:2013-09-26 15:04:16
【问题描述】:
是的:这个问题有很多重复,但没有一个答案有帮助。
我正在关注这个伟大的tutorial by Ali Hafizji on using APNS service for push notifications。
在开发模式下测试APNS:
- 下载
aps_development.cer - 导出证书的私钥 (
aps_development_key.p12)
然后我使用以下命令(使用终端)将两者结合起来:
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, 寻找它的正确地址可能是https://www.entrust.net/downloads/binary/entrust_2048_ca.cer (无论如何它们都是一样的)。
在这种情况下,应用程序在调试模式下运行(在设备上,从 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:398\nStack 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 令牌 - 调试和生产模式下的设备 APNS 令牌不一样 - 已使用。
无论如何:令牌不是问题,因为我的通知发送脚本甚至无法连接到ssl://gateway.push.apple.com:2195。
尝试通过telnet 连接ssl://gateway.push.apple.com:2195 只是为了确保:连接正常。
很明显:这是一个证书问题。
【问题讨论】:
标签: php ios apple-push-notifications apns-php