我有一个简单的脚本可以向iOS Phonegap应用发送推送通知消息。这是:
$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 = 'mountmercy/MountMercy-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$deviceToken = "the_device_token";
$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);
echo "error is ".$error."<br />";
echo "errorString is ".$errorString."<br />";
我得到了非常常见和一般的错误:
Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out)
然后我尝试了:
telnet gateway.sandbox.push.apple.com 2195
但我得到了答复:
Trying 17.149.34.189...
Trying 17.149.34.188...
Trying 17.149.34.187...
telnet: Unable to connect to remote host: Connection timed out
有很多关于stream_socket_client()错误的SO问题,但我甚至无法连接到telnet的事实表明我遇到了另一个问题......
答案 0 :(得分:1)
这是防火墙的问题。