PHP无法与Apple通知网关进行套接字连接

前端之家收集整理的这篇文章主要介绍了PHP无法与Apple通知网关进行套接字连接前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
免责声明:在SO上我发现了许多类似的问题和一些答案,但没有一个解决了我的问题.

我有这个简单的PHP代码

<?PHP
    $deviceToken = "myDeviceToken";
    $message = "Hello from server";
    $badge = 1;
    $sound = "default";

    // Construct the notification payload
    $body['aps'] = array(
        'alert' => $message
    );

    if ($badge) {
        $body['aps']['badge'] = $badge;
    }

    if ($sound) {
        $body['aps']['sound'] = $sound;
    }

    /* End of Configurable Items */
    $ctx = stream_context_create();
    stream_context_set_option($ctx,'ssl','local_cert','my.pem');

    $fp = stream_socket_client("ssl://gateway.sandBox.push.apple.com:2195",$err,$errstr,60,STREAM_CLIENT_CONNECT,$ctx);

    if (!$fp) {
        print "Failed to connect $err $errstrn";
        return;
    } else {
        print "Connection OK\n";
    }

    $payload = json_encode($body);
    $msg = chr(0) . pack("n",32) . pack("H*",str_replace(" ","",$deviceToken)) . pack("n",strlen($payload)) . $payload;
    print "sending message :" . $payload . "\n";
    fwrite($fp,$msg);
    fclose($fp);
?>

从浏览器调用时我收到:

[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: SSL operation Failed with code 1. OpenSSL Error messages:
error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure in /home/srv/public_html/myTest.PHP on line 28

[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: Failed to enable crypto in /home/srv/public_html/myTest.PHP on line 28

[13-Dec-2011 18:52:52] PHP Warning: stream_socket_client() [function.stream-socket-client]: unable to connect to ssl://gateway.sandBox.push.apple.com:2195 (Unknown error) in /home/srv/public_html/myTest.PHP on line 28

知道发生了什么事吗?

来自互联网的一些随机发现可能会有所帮助:

>这可能是证书问题.尝试使用流选项allow_self_signed和verify_peer来检查它.>尝试使用explicitely sslv2://或sslv3://?>“/ dev / urandom”上的权限问题

猜你在找的PHP相关文章