2012-04-24 13 views
1

私はそれに従いました: Apple Push Notification Services Tutorial。 それはローカルで私のために働いた。 次に、サーバーからプッシュ通知を送信しますか?サーバーからのAppleプッシュ通知

simplepush.phpck.pemをマイサーバにアップロードしました。私がhttp://www.myserver/simplepush.phpをチェックすると、私にエラーが出る:

*Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home/cherry/public_html/simplepush.php on line 21 Failed to connect: 110 Connection timed out*

私を助けてくれますか?

PHPコード:

<?php 

// Put your device token here (without spaces): 
$deviceToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'; 

// Put your private key's passphrase here: 
$passphrase = 'xxxxxxxxxx'; 

// Put your alert message here: 
$message = 'My first push notification!'; 

//////////////////////////////////////////////////////////////////////////////// 

$ctx = stream_context_create(); 
stream_context_set_option($ctx, 'ssl', 'local_cert', 'ck.pem'); 
stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 

// Open a connection to the APNS server 
$fp = stream_socket_client(
    'ssl://gateway.sandbox.push.apple.com:2195', $err, 
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

if (!$fp) 
    exit("Failed to connect: $err $errstr" . PHP_EOL); 

echo 'Connected to APNS' . PHP_EOL; 

// Create the payload body 
$body['aps'] = array(
    'alert' => $message, 
    'sound' => 'default' 
    ); 

// Encode the payload as JSON 
$payload = json_encode($body); 

// Build the binary notification 
$msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; 

// Send it to the server 
$result = fwrite($fp, $msg, strlen($msg)); 

if (!$result) 
    echo 'Message not delivered' . PHP_EOL; 
else 
    echo 'Message successfully delivered' . PHP_EOL; 

// Close the connection to the server 
fclose($fp); 
+0

それは本当にObjective-CのとXcodeの問題ではありません、 btw :) – kender

+0

あなたはそれを見つけることができましたか?私はまったく同じ問題を抱えています:/ – ghostrider

答えて

0

はSSLを使用してコンパイルPHPですか?あなたのローカルバージョンと同じバージョンですか?

ファイアウォールは、サーバーから2195ポートへの接続をブロックすることはできますか?

あなたは(いくつかの種類のシェルに)このサーバにログインしてこのサーバーとポートへのtelnet経由で接続できるかどうかを確認できます:

$ telnet gateway.sandbox.push.apple.com 2195 
+0

XX.XXX.XXX.XXを試しています... gateway.sandbox.push-apple.com.akadns.netに接続しました。 エスケープ文字は '^]です。これは、私がtelnetゲートウェイをチェックするとき、私が端末から得た答えです。 – shebi

+0

さて、ブロックされたポートではありません。私はPHPがコンパイルされたsslサポートを持っているかどうかチェックします。 – kender

+0

私のサーバのPHPコードで質問を更新しました。これを確認してください。余分にする必要があるものは何ですか? – shebi

関連する問題