无法在终端中运行PHP时遇到这些错误,如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文章http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1#comments
创建了所有证书和pem文件答案 0 :(得分:58)
问题是pem文件不正确,我使用http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1创建了pem文件。 创建p12文件和使用p12创建pem文件对我来说不起作用。正确创建p12并使用p12创建pem文件的过程如下所示
从Apple获得应用程序的证书后,将您的密钥和Apple证书导出为p12文件。以下是有关如何执行此操作的快速演练:
现在将p12文件转换为pem文件:
$ openssl pkcs12 -in cert.p12 -out apple_push_notification_production.pem -nodes -clcerts
这对我有用,现在我正在收到推送通知。
答案 1 :(得分:9)
在http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1中将密钥文件转换为pem推荐给我带来了问题。
运行
openssl pkcs12 -in keyname.p12 -out keyname.pem -nodes -clcerts
而不是
openssl pkcs12 -nocerts -out keyname.pem -in keyname.p12
解决了我的问题。
答案 2 :(得分:0)
我遵循了youtube教程,该教程与raywenderlich文章几乎相同。我只是忘了添加PEM密码短语。添加后,如here所述,它有效:
stream_context_set_option($ctx, 'ssl', 'passphrase', 'MyPassPhrase');
答案 3 :(得分:-4)
这是reywenderlich Apple推送通知服务的解决方案 教程
$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!';