【发布时间】:2015-03-29 01:30:50
【问题描述】:
我一直在阅读 Ray Wenderlich 的关于使用 PHP 脚本的推送通知的教程。
参考: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 文件。
/Applications/XAMPP/bin/php push.php development
我唯一的区别是我使用的是 XAMPP 而不是 MAMP。
我已确认已安装所有扩展程序。
我可以通过这样做在终端中测试我的证书:
openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem
它要求我输入密码,我输入了。一切都在终端中成功运行。
但是,当我运行 push.php 文件时,出现以下错误:
PHP 警告:stream_socket_client():SSL 操作失败,代码为 1。OpenSSL 错误消息: 错误:14090086:SSL 例程:SSL3_GET_SERVER_CERTIFICATE:证书验证失败 PHP 警告:stream_socket_client(): 无法启用加密
PHP 警告:stream_socket_client():无法在第 140 行连接到 ssl://gateway.sandbox.push.apple.com:2195(未知错误)
php文件中的第140行是:
$this->fp = stream_socket_client('ssl://' . $this->server, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
我找到了这些:
iOS push notification does not work when using crontab scheduler
https://devforums.apple.com/message/1054840#1054840
我确实重试了所有内容。我知道我的密码是正确的。我重新创建了我的证书、pem 文件和密钥。没有任何效果。每次我这样做时都会出现同样的错误。
我很困惑。
有没有人有任何建议或知道发生了什么?
谢谢!
更新 1:
我还尝试设置 ck.pem 文件的完整路径,但也无法修复错误。
【问题讨论】:
-
您确定您的 .p12 导出正确吗?从钥匙串导出私钥时,请确保您使用了私钥,而不仅仅是公钥
-
@Emilie 我只导出了私钥。我没有导出公钥,因为教程也没有告诉我。
-
$ctx的值是多少,上面设置了哪些选项? -
@oflannabhra 选项集:stream_context_set_option($ctx, 'ssl', 'local_cert', $this->certificate); stream_context_set_option($ctx, 'ssl', 'passphrase', $this->passphrase); $ctx 打印出 Resource id #9 当然,我不知道这是什么意思。
-
$this->certificate应该是您本地证书的绝对文件路径。
标签: php ios openssl apple-push-notifications