连接失败:111连接被拒绝

时间:2017-05-18 05:27:15

标签: php apple-push-notifications

如果我使用共享主机,有没有办法发送iOS推送通知,因为端口2195在Godaddy共享主机上关闭(因为你必须知道这一点)。 那么通知在这里可以起作用吗?

编辑:

<?php 
$deviceToken = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX888';
    // Put your private key's passphrase here:
    $passphrase = '';

    // Put your alert message here:
    $message = 'Hello';

    ////////////////////////////////////////////////////////////////////////////////
//echo dirname(__FILE__);die;
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'local_cert', dirname(__FILE__).'/ck.pem');
    stream_context_set_option($ctx, 'ssl', 'passphrase', $passphrase);
echo "No";
    // 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 个答案:

没有答案