警告:stream_socket_client():无法设置私钥文件

无法得到这个得到这些错误时,在PHPterminal运行PHP simplepush.php

Warning: stream_socket_client(): Unable to set private key file `/users/accenture/Desktop/newAPNS/ck.pem' in /users/accenture/Desktop/newAPNS/simplepush.php on line 22 Warning: stream_socket_client(): failed to create an SSL handle in /users/accenture/Desktop/newAPNS/simplepush.php on line 22 Warning: stream_socket_client(): Failed to enable crypto in /users/accenture/Desktop/newAPNS/simplepush.php on line 22 Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /users/accenture/Desktop/newAPNS/simplepush.php on line 22 Failed to connect: 0 

我使用raywenderlich文章创build了所有证书和pem文件, http: //www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1#comments

问题是pem文件不正确,我使用http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1创build了pem文件。 创buildp12文件和创buildpem文件的p12不适用于我。 正确的过程创buildp12和p12创buildpem文件如下

从您的应用程序获得Apple的证书之后,将您的密钥和Apple证书导出为p12文件。 以下是如何做到这一点的快速演练:

  1. 单击钥匙串访问中证书旁边的公开箭头,然后select证书和密钥。
  2. 右键单击并select导出2项…。
  3. 从下拉列表中selectp12格式,并将其命名为cert.p12。

现在将p12文件转换为一个pem文件:

$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts

这是为我工作,现在我得到一个推送通知。

将密钥文件转换为pem在http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1中推荐给我造成问题。

运行

 openssl pkcs12 -in keyname.p12 -out keyname.pem -nodes -clcerts 

而不是

 openssl pkcs12 -nocerts -out keyname.pem -in keyname.p12 

解决了我的问题。

我遵循了与raywenderlich文章几乎相同的YouTube教程。 我忘了添加PEM密码。 join后,如下所述,它的工作原理:

 stream_context_set_option($ctx, 'ssl', 'passphrase', 'MyPassPhrase'); 

这是reywenderlich Apple推送通知服务教程的解决scheme

  $deviceToken = ''; //Enter your token number // Put your private key's passphrase here: $passphrase = '1234';//Enter ck.pem 's password // Put your alert message here: $message = 'My first push notification!';