1

我正在尝试连接APNS,但我需要通过代理,这里是连接测试代码:

if (!extension_loaded('openssl')) {
    exit("need openssl");
}

$http = array();
$http['http']['proxy'] = 'tcp://proxy.net:8080';
$http['http']['request_fulluri'] = true;

$ssl = array();
$ssl['ssl']['local_cert'] = 'ck.pem';
$ssl['ssl']['passphrase'] = 'passphrase';

$opts = array_merge($http,$ssl);

$context = stream_context_create($opts);

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

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected to APNS' . PHP_EOL;

问题是我总是有一个超时错误,比如我直接连接到苹果网关,比如忽略了 stream_context_creat 中的选项。

OpenSSL 和 Socket 支持已启用,并且端口 2195 已打开。

有任何想法吗?

编辑1:

尝试仅连接到代理它有效

$fp = stream_socket_client('tcp://proxy-dmz.pgol.net:8080', $err, $errstr, 60, STREAM_CLIENT_CONNECT);

if (!$fp)
    exit("Failed to connect: $err $errstr" . PHP_EOL);

echo 'Connected!' . PHP_EOL;

编辑2:

像这样的脚本(在某个论坛中找到)似乎可以工作......我被卡住了

$ip = "tcp://proxy.net"; // proxy IP
$port = "8080"; // proxy port

$url = "http://search.yahoo.com/search?p=test";

$request = "GET $url HTTP/1.0\r\nHost:www.yahoo.com:80\r\n\r\n";

$fp = fsockopen($ip,$port); // connect to proxy

fputs($fp, $request);

$data="";
while (!feof($fp)) $data.=fgets($fp,64000);

fclose($fp);

print $data;
4

0 回答 0