PHP 与 Apple 通知网关的套接字连接失败 [英] PHP fails socket connection with Apple notification gateway

查看:26
本文介绍了PHP 与 Apple 通知网关的套接字连接失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

免责声明:在 SO 上,我发现了许多类似的问题和一些答案,但没有一个能解决我的问题.

我有这个简单的 PHP 代码:

I have this easy PHP code:

<?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 警告:stream_socket_client() [function.stream-socket-client]:SSL 操作失败,代码为 1.OpenSSL 错误消息:错误:14094410:SSL 例程:SSL3_READ_BYTES:第 28 行/home/srv/public_html/myTest.php 中的 sslv3 警报握手失败

[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 警告:stream_socket_client() [function.stream-socket-client]:无法在第 28 行的/home/srv/public_html/myTest.php 中启用加密

[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 警告:stream_socket_client() [function.stream-socket-client]:无法连接到 ssl://gateway.sandbox.push.apple.com:2195(未知错误)在第 28 行的/home/srv/public_html/myTest.php

[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

知道发生了什么吗?

推荐答案

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

Some random finding from the internet which could help:

  1. 可能是证书问题.尝试使用流选项 allow_self_signedverify_peer 进行检查.

尝试明确使用 sslv2://sslv3:// ?

Try to use explicitely sslv2:// or sslv3:// ?

/dev/urandom"权限问题

Permission problem on "/dev/urandom"

这篇关于PHP 与 Apple 通知网关的套接字连接失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆