0

我正在嘗試使用C#執行iOS推送通知。但我無法連接到蘋果的網址(gateway.sandbox.push.apple.com:2195)。從谷歌搜索,我發現這個端口必須在託管服務器中打開。iOS pushnotification 2195端口打開

在linux下,他們說做這樣的

[email protected] [~]# telnet gateway.sandbox.push.apple.com 2195 
Trying XX.XXX.XXX.XX... 
Connected to gateway.sandbox.push.apple.com. 
Escape character is '^]'. 
^\q 
^] 
telnet> q 
Connection closed. 
[email protected] [~]# 

當我嘗試這在我的Windows服務器,不會工作。我是服務器技術的新手。如何在我的Windows服務器中測試相同的內容?我有一個專門的服務器與遠程訪問

請幫助 在此先感謝當然

+0

蘋果拒絕telnet會話。 –

+0

@ramesh我在同一條船上,你有什麼想法嗎? – meda

+1

是的..我與我的託管服務提供商交談,他們打開了相應的端口。請求打開ssl://gateway.sandbox.push.apple.com:2195。默認情況下,他們的防火牆阻止了此端口 – ramesh

回答

0
$passphrase = "Your_PEM_File_Password_Here"; 

    $ctx = stream_context_create(); 
    stream_context_set_option($ctx, 'ssl', 'local_cert', YOUR_PEM_FILE_PATH_HERE); 
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase); 
// use this when you in sandbox mode.. 
    $fp = stream_socket_client(
     'ssl://gateway.sandbox.push.apple.com:2195', $err, 
    $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 
// use this when you in development mode.. 
// $fp = stream_socket_client(
// 'ssl://gateway.push.apple.com:2195', $err, 
//$errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx); 

    $body['aps'] = array(
     'badge' => $badge, 
     'alert' => "Your Message Here.", 
     'sound' => 'default', 
     'content-available' => '1' 
    ); 
//echo "<pre>"; print_r($body); 
    $payload = json_encode($body); 

    $msg = chr(0) . pack('n', 32) . pack('H*', $deviceToken) . pack('n', strlen($payload)) . $payload; 

    $result = fwrite($fp, $msg, strlen($msg)); //echo "<pre>"; print_R($result); 

    if (!$result){ 
     $data = array(
      'Message' => 'Message not delivered' . PHP_EOL 
      ); 
     } else { 
    $data = array(
      'Message' => 'Message successfully delivered' . PHP_EOL 
      ); 
    } //echo "<pre>"; print_R($result); 

    fclose($fp);