我正在尝试通过PHP在iOS应用程序中发送推送通知。因此,iOS开发者给了我pem文件。我要求主机服务器打开gateway.sandbox.push.apple.com:2195
端口,他们已经打开了该端口。但是当我尝试发送推送通知时,我遇到了以下错误。我的代码如下:
$deviceToken='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$passphrase="";
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', '/home/sitename/public_html/push/ck.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195',
$err,
$errstr,
60,
STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,
$ctx);
if (!$fp)
exit("Failed to connect amarnew: $err $errstr" . PHP_EOL);
echo 'Connected to APNS' . PHP_EOL;
获取以下错误信息
Failed to connect amarnew: 0
我尝试通过 Telnet 连接到苹果,结果如下:
root@uio3-i [~]# telnet gateway.sandbox.push.apple.com 2195
Trying XX.XXX.XXX.XX...
Connected to gateway.sandbox.push.apple.com.
Escape character is '^]'.
^\q
^]
telnet> q
Connection closed.
root@uio3-i [~]#
作为一个新手,我在这里卡住了,请有经验的人帮助我。提前感谢您。