使用PEM文件在PHP中推送通知 [英] Push Notification in PHP using PEM file
问题描述
我一直在研究Ray Wenderlich的有关使用PHP脚本进行推送通知的教程.
I've been working through Ray Wenderlich's tutorials on push notifications using a PHP Script.
参考: http ://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
http://www.raywenderlich.com/32963/apple-push-notification-services-in-ios-6-tutorial-part-2
我做了很多研究,但是在第2部分中遇到了一个问题,在该问题中,您使用ck.pem文件运行push.php文件.
I have done a ton of research but I have ran into an issue on part 2 where you run the push.php file using the ck.pem file.
/Applications/XAMPP/bin/php push.php development
我唯一的区别是我使用的是XAMPP,而不是MAMP.
My only difference is that I'm using XAMPP and not MAMP.
我已确认已安装所有扩展.
I have confirmed that all the extensions are installed.
我可以通过以下方法在终端中测试我的证书:
I am able to test out my certificate in the terminal by doing this:
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
它要求我输入密码,然后输入.一切都在终端上成功完成.
It asks me to enter my passphrase and I do. Everything works successfully in the terminal.
但是,当我运行push.php文件时,出现以下错误:
However, when I run the push.php file, I get these errors:
PHP警告:stream_socket_client():SSL操作失败,代码为1.OpenSSL错误消息: 错误:14090086:SSL例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 PHP警告:stream_socket_client():无法启用加密功能
PHP Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed PHP Warning: stream_socket_client(): Failed to enable crypto in
PHP警告:stream_socket_client():无法连接到第140行上的ssl://gateway.sandbox.push.apple.com:2195(未知错误)
PHP Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in on line 140
php文件中的第140行是:
Line 140 in the php file is:
$this->fp = stream_socket_client('ssl://' . $this->server, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
我发现了这些:
https://devforums.apple.com/message/1054840#1054840
我从字面上重试了所有内容.我知道我的密码短语是正确的.我已经重新创建了证书,pem文件和密钥.什么都行不通.每次执行此操作时都会出现相同的错误.
I have literally retried everything. I know my passphrase is correct. I've re-created my certificates, pem files, and keys. Nothing works. Same error every time I do this.
我很困惑.
有人有任何建议或知道发生了什么事吗?
Does anyone have any suggestions or know what's going on?
谢谢!
更新1:
我还尝试将ck.pem文件的完整路径设置为也无法修复该错误.
I have also tried setting the full path to the ck.pem file that does not fix the error either.
推荐答案
好的,我终于明白了!经过2天的工作.
Okay, I finally figured this out! After 2 days of working with this.
因此,对于遇到此问题的其他人:
So, for anyone else who runs into this issue:
从以下位置下载entrust_2048_ca.cer证书: https://www.entrust.com/get-support/ssl-certificate -support/root-certificate-downloads/
Download the entrust_2048_ca.cer certificate from: https://www.entrust.com/get-support/ssl-certificate-support/root-certificate-downloads/
向下滚动并获取Entrust.net证书颁发机构(2048)
Scroll down and get the Entrust.net Certificate Authority (2048)
然后,在push.php文件中,设置密码短语的上下文后,添加以下行:
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
Then, in the push.php file, after you set the context for the passphrase, add this line:
stream_context_set_option($ctx, 'ssl', 'cafile', 'entrust_2048_ca.cer');
这篇关于使用PEM文件在PHP中推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!