我如何使用苹果推送通知服务(apns)与php


How can I use the Apple Push Notification Service (apns) with php?

我正在尝试连接到苹果推送通知服务(apns)与php。如果我使用

命令
openssl s_client -connect gateway.push.apple.com:2195 -cert AppCert.pem -key AppKeyNoPass.pem -CAfile ca.pem
在控制台上的

上,我在最后一行得到一条长消息,其中包含"验证返回代码:0 (ok)"。如果我使用下面的PHP代码,我会得到一些警告。

$uuid = '11111111-22222222-33333333-44444444-55555555-66666666-77777777-88888888';
$url = 'ssl://gateway.push.apple.com:2195';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', 'App.pem');
stream_context_set_option($streamContext, 'ssl', 'cafile', 'ca.pem');
$socketClient = stream_socket_client($url, $error, $errorString, 60, STREAM_CLIENT_CONNECT, $streamContext);

以下是stream_socket_client()的PHP警告

Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094416:SSL routines:SSL3_READ_BYTES:sslv3 alert certificate unknown
Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.push.apple.com:2195 (Unknown error)

你知道吗?我的证书格式有问题吗?

谢谢

我使用了这个教程,一切都很好。这里有关于关键文件的所有细节,还有一个php推送示例文件供下载。