使用 APNS PHP 出现错误
这是我正在使用的代码
<?php
$deviceToken = 'my device key'; // not putting in for security
$payload['aps'] = array('alert' => 'This is the alert text', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
socket_close($apns);
fclose($apns);
?>
,我收到这些错误
警告:stream_socket_client() [function.stream-socket-client]:无法在第 14 行 /home/bryan/sendpush.php 中设置私钥文件 `apns-dev.pem'
警告:stream_socket_client() [function.stream-socket-client]:无法在第 14 行的 /home/bryan/sendpush.php 中创建 SSL 句柄
警告:stream_socket_client() [function.stream-socket-client]:无法在第 14 行 /home/bryan/sendpush.php 中启用加密
警告:stream_socket_client() [function.stream-socket-client]:无法连接到 /home/bryan/sendpush.php 中的 ssl://gateway.sandbox.push.apple.com:2195 (未知错误)第 14 行
警告:fwrite():提供的参数不是 /home/bryan/sendpush.php 第 17 行中的有效流资源
警告:socket_close() 期望参数 1 为资源,布尔值在 /home/bryan/sendpush.php 第 19 行给出
警告:fclose():提供的参数不是 /home/bryan/sendpush.php 第 20 行中的有效流资源
我实际上现在将其归结为这些错误
警告:stream_socket_client() [function.stream-socket-client]:SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14094410:SSL 例程:SSL3_READ_BYTES:/home/bryan/PushService 中的 sslv3 警报握手失败。 php 第 27 行
警告:stream_socket_client() [function.stream-socket-client]:无法在第 27 行 /home/bryan/PushService.php 中启用加密
警告:stream_socket_client() [function.stream-socket-client]:无法连接到 /home/bryan/PushService.php 中的 ssl://gateway.sandbox.push.apple.com:2195 (未知错误)上线
Here's the code I'm using
<?php
$deviceToken = 'my device key'; // not putting in for security
$payload['aps'] = array('alert' => 'This is the alert text', 'badge' => 1, 'sound' => 'default');
$payload = json_encode($payload);
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
socket_close($apns);
fclose($apns);
?>
and I get these errors
Warning: stream_socket_client() [function.stream-socket-client]: Unable to set private key file `apns-dev.pem' in /home/bryan/sendpush.php on line 14
Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /home/bryan/sendpush.php on line 14
Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/bryan/sendpush.php on line 14
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/bryan/sendpush.php on line 14
Warning: fwrite(): supplied argument is not a valid stream resource in /home/bryan/sendpush.php on line 17
Warning: socket_close() expects parameter 1 to be resource, boolean given in /home/bryan/sendpush.php on line 19
Warning: fclose(): supplied argument is not a valid stream resource in /home/bryan/sendpush.php on line 20
I actually now got it down to these errors
Warning: stream_socket_client() [function.stream-socket-client]: SSL operation failed with code 1. OpenSSL Error messages: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /home/bryan/PushService.php on line 27
Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/bryan/PushService.php on line 27
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in /home/bryan/PushService.php on line
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用私钥的绝对路径而不是相对路径。
确保 php 用户(或 Web 服务器用户,具体取决于..
www-data
、apache
、nginx
、www< /code>...) 被允许读取它 (
chown
,chmod
)。Use the absolute path for the private key instead of relative path.
Make sure the php user (or webserver user, depending..
www-data
,apache
,nginx
,www
...) is allowed to read it (chown
,chmod
).我也收到这个错误。发现我对包含证书文件的文件夹的权限设置错误。这对我有用:
I was getting this error also. found out that I had set up the permission wrong on the folder that had the certificate file. This worked for me: