我按照苹果指南在我的上网本上设置证书。然后当我尝试执行推送通知时,我得到了这个错误:
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 xxxx.php on line 92
Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in xxxx.php on line 92
Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in xxxx.php on line 92
Failed to connect 0
这是我的php函数:
function push($deviceToken,$badge,$message) {
$sound = "default";
// Construct the notification payload
$body = array();
$body['aps'] = array("alert" => $message);
if ($badge)
$body['aps']['badge'] = $badge;
if ($sound)
$body['aps']['sound'] = $sound;
$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'apns-dev.pem');
$fp = stream_socket_client("ssl://gateway.sandbox.push.apple.com:2195", $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
if (!$fp) {
print "Failed to connect $err $errstrn";
return;
} else {
print "Connection OK\n";
}
$payload = json_encode($body);
$msg = chr(0) . pack('n',32) . pack('H*', str_replace(' ', '', $deviceToken)) . pack('n',strlen($payload)) . $payload;
print "sending message :" . $payload . "\n";
fwrite($fp, $msg);
fclose($fp);
}
我尝试测试苹果gatway,但这是我的输出:
$ telnet gateway.sandbox.push.apple.com:2195
Trying 212.48.8.140...
telnet: connect to address 212.48.8.140: Operation timed out
telnet: Unable to connect to remote host
有什么想法解决它?
编辑: 我不确定是否应该在远程服务器上设置证书
解决: 我的 我的错误是apns-dev.pem的路径
答案 0 :(得分:0)
无论你的目的是什么阻止它,Apple的网关都关闭了,或者你需要在访问之前向Apple注册你的IP地址。请检查这三个: - )