6

我必须向 iOS 设备发送推送通知。我的连接必须通过代理启用。我尝试了一切,但没有成功。我有一个错误 110 连接超时。如果我只是尝试连接到 Apple push 的地址,它就可以使用 cURL。我不知道问题出在哪里。代理配置?PHP stream_context 错误的实现?

这是我的代码:

$ctx = stream_context_create();
stream_context_set_option($ctx, 'ssl', 'local_cert', 'certificate.pem');
stream_context_set_option($ctx, 'ssl', 'passphrase', 'my_passphrase');
stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
stream_context_set_option($ctx, 'http', 'proxy', 'tcp://my-proxy.net:8080');
stream_context_set_option($ctx, 'http', 'request_fulluri', true);

$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
var_dump($fp);
var_dump($err);
var_dump($errstr);
exit;

你有想法吗 ?

编辑:

它可以直接链接到 Squid 吗?我刚刚发现代理正在与 Squid 一起运行。我也尝试使用fopen()函数而不是,stream_socket_client()但它似乎不允许 ssl 协议。

这是我的 var_dump 输出:bool(false) int(110) string(20) "Connection timed out"

我也有这个警告:警告:stream_socket_client():无法连接到第 22 行 /share/www/website/test.php 中的 ssl://gateway.sandbox.push.apple.com:2195(连接超时)

4

2 回答 2

1

可能只是您的代理不允许打开端口 2195。

iPhone 推送通知无法连接到 SSL 服务器

我猜你要么:

  • 需要与运行代理的人交谈以查看端口 2195 是否打开。

或者

  • 设置一个在端口 2195 上侦听的测试服务器,然后尝试通过代理对其进行测试连接。这应该允许您测试是否是阻止连接请求的代理。

或者

  • 测试 Curl 是否可以使用代理打开连接。

这是通过设置选项来完成的:

// sets the proxy to go through
curl_setopt($ch, CURLOPT_PROXY, $proxy);
// sets to use a tunnel proxy which most http proxies are
curl_setopt($ch, CURLOPT_HTTPTUNNELPROXY, $proxy);

完整的测试代码在这里

于 2013-01-07T14:30:10.390 回答
0
  • 创建 SSL 上下文
  • 打开到代理的 tcp 套接字
  • 向代理发送请求以连接到 APN
  • 一旦连接被接受,启用 SSL

看看我在这篇文章中的回复:Send Push Notification to APNS through proxy

于 2015-10-06T19:47:37.787 回答