错误:
警告:stream_socket_client():无法启用加密 第28行/home/####/public_html/####/testpushnotification.php
警告:stream_socket_client():无法连接 ssl://gateway.push.apple.com:2195(未知错误)in 第28行的/home/####/public_html/####/testpushnotification.php失败 连接:0
这是我的代码:
$apnsPort = 2195;
$badgecount = 1;
$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);
if (!$apns)
{
exit("Failed to connect: $error $errorString" . PHP_EOL);
} else
{
$payload['aps'] = array('alert' => $message,'badge' => $count, 'sound' => 'default');
$output = json_encode($payload);
$token = pack('H*', str_replace(' ', '', $deviceToken));
$apnsMessage = chr(0) . chr(0) . chr(32) . $token . chr(0) . chr(strlen($output)) . $output;
fwrite($apns, $apnsMessage);