0

我正在尝试使用 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 服务器中进行相同的测试?我有一个可以远程访问的专用服务器

请帮助提前谢谢

4

1 回答 1

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);
于 2015-05-06T10:18:53.963 回答