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);