我正在尝试使用php发送IOS应用程序的推送通知。但是,当我尝试建立连接时,但每当我尝试建立连接时,我得到一个"无法建立连接:0"错误。谁能告诉我我的代码有什么问题。
function iOS()
{
$deviceToken ="XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$ctx = stream_context_create();
$pem = get_site_url().'/wp-content/themes/MY-child/ck.pem';
$passphrase = '';
stream_context_set_option($ctx, 'ssl', 'local_cert', $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 , $ctx);
if (!$fp)
exit("Failed to establish connection : $err $errstr" . PHP_EOL);
$body['aps'] = array(
'alert' => "Hello from APNs Tester",
'sound' => 'default'
);
$payload = json_encode($body);
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload;
$result = fwrite($fp, $msg, strlen($msg));
fclose($fp);
if (!$result)
return 'Message not delivered' . PHP_EOL;
else
return 'Message successfully delivered' . PHP_EOL;
}