iOS推送通知2195端口打开

时间:2013-09-01 06:30:43

标签: ios windows-server-2008 port apple-push-notifications firewall

我正在尝试使用C#进行iOS推送通知。但我无法连接到苹果的网址(gateway.sandbox.push.apple.com:2195)。从谷歌搜索我发现这个端口必须在托管服务器中打开。

在linux中,他们说这样做

root@uio3-i [~]# 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.
root@uio3-i [~]#

当我在我的Windows服务器上尝试这个时,不会工作。我是服务器技术的新手。如何在我的Windows服务器上测试相同的?我有一个带远程访问的专用服务器

请帮忙 提前致谢

1 个答案:

答案 0 :(得分: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);