如何在PHP中使用Apple推送通知服务(apns)?

时间:2013-01-17 09:18:52

标签: php ssl apple-push-notifications

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

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)
你知道吗?我的证书格式有问题吗?

由于

1 个答案:

答案 0 :(得分:2)

我使用了this Tutorial,一切都很适合我。有关密钥文件的详细信息,还有php push example file可供下载。希望有所帮助。

相关问题