使用PHP APNS收到错误 [英] Getting errors using APNS PHP
问题描述
这里的code我用
< PHP
$ deviceToken ='我的设备密钥'; //不投入安全$有效载荷['APS'] =阵列('警报'=>'这是警报文本','徽章'=大于1,声音= GT;'默认');
$有效载荷= json_en code($负载);$ 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,$错误,$为errorString,2,STREAM_CLIENT_CONNECT,$ streamContext);$ apnsMessage = CHR(0)。字符(0)。字符(32)。包(H *',str_replace函数('','',$ deviceToken))。字符(0)。字符(strlen的($有效载荷))。 $有效载荷;
FWRITE($ APNS,$ apnsMessage);socket_close($ APNS);
FCLOSE($ APNS);
?>
和我得到这些错误
警告:在stream_socket_client()[function.stream插槽客户端]:无法/home/bryan/sendpush.php设置私钥文件`APNS-dev.pem第14行
警告:在stream_socket_client()[function.stream插槽客户端]:未能上线14中创建一个/home/bryan/sendpush.php SSL句柄
警告:在stream_socket_client()[function.stream插槽客户端]:失败,使在线14 /home/bryan/sendpush.php加密
警告:在stream_socket_client()[function.stream插槽客户端]:无法连接到SSL://gateway.sandbox.push.apple.com:2195(未知错误)在/home/bryan/sendpush.php第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插槽客户端]:在/ home /布赖恩的SSLv3警报握手失败:SSL操作失败,code 1. OpenSSL的错误信息:错误:14094410:SSL例程:SSL3_READ_BYTES /PushService.php第27行
警告:在stream_socket_client()[function.stream插槽客户端]:失败,使第27行中/home/bryan/PushService.php加密
警告:在stream_socket_client()[function.stream插槽客户端]:无法连接到SSL:在/home/bryan/PushService.php 2195(未知错误)://gateway.sandbox.push.apple.com在线
块引用>解决方案
使用私钥,而不是相对路径的绝对路径。
确保PHP用户(或网络服务器的用户,根据..
www数据
,阿帕奇
,nginx的
,WWW
...)被允许读取它(CHOWN
,搭配chmod
)。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
解决方案
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
).
这篇关于使用PHP APNS收到错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!