使用 APNS PHP 获取错误 [英] Getting errors using APNS PHP

查看:24
本文介绍了使用 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'

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

警告:stream_socket_client() [function.stream-socket-client]:无法在第 14 行的/home/bryan/sendpush.php 中创建 SSL 句柄

Warning: stream_socket_client() [function.stream-socket-client]: failed to create an SSL handle in /home/bryan/sendpush.php on line 14

警告:stream_socket_client() [function.stream-socket-client]:无法在第 14 行的/home/bryan/sendpush.php 中启用加密

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/bryan/sendpush.php on line 14

警告:stream_socket_client() [function.stream-socket-client]:无法连接到/home/bryan/sendpush.php 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误)第 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

警告:fwrite():在第 17 行的/home/bryan/sendpush.php 中提供的参数不是有效的流资源

Warning: fwrite(): supplied argument is not a valid stream resource in /home/bryan/sendpush.php on line 17

警告:socket_close() 期望参数 1 是资源,布尔值在第 19 行的/home/bryan/sendpush.php 中给出

Warning: socket_close() expects parameter 1 to be resource, boolean given in /home/bryan/sendpush.php on line 19

警告:fclose():在第 20 行的/home/bryan/sendpush.php 中提供的参数不是有效的流资源

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

警告:stream_socket_client() [function.stream-socket-client]:SSL 操作失败,代码 1.OpenSSL 错误消息:错误:14094410:SSL 例程:SSL3_READ_BYTES:/home/bryan/PushService 中的sslv3 警报握手失败.php 第 27 行

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

警告:stream_socket_client() [function.stream-socket-client]:无法在第 27 行的/home/bryan/PushService.php 中启用加密

Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/bryan/PushService.php on line 27

警告:stream_socket_client() [function.stream-socket-client]:无法连接到/home/bryan/PushService.php 中的 ssl://gateway.sandbox.push.apple.com:2195(未知错误)在线

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

推荐答案

  1. 使用私钥的绝对路径而不是相对路径.

  1. Use the absolute path for the private key instead of relative path.

确保 php 用户(或网络服务器用户,取决于.. www-dataapachenginxwww...) 被允许读取(chown, chmod).

Make sure the php user (or webserver user, depending.. www-data, apache, nginx, www...) is allowed to read it (chown, chmod).

这篇关于使用 APNS PHP 获取错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆