2014-01-22 73 views
1

我有一個簡單的腳本來發送推送通知消息到iOS Phonegap應用程序。那就是:蘋果推送通知 - 無法連接到telnet

$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 

有很多關於str的SO問題eam_socket_client()錯誤,但事實上,我甚至不能連接telnet表明我有一個不同的問題...

回答