如果您无法使用端口 2195,如何使用 Apple 推送通知


How to use Apple Push Notifications if you can't use port 2195?

我使用 stream_socket_client() 开发了一个脚本,它可以在我的本地主机上工作,但是当我尝试在线使用它(使用 Fatcow.com 虚拟主机)时,它不起作用。我收到以下错误:

警告:stream_socket_client() [function.stream-socket-client]:无法连接到 ssl://gateway.sandbox.push.apple.com:2195 (连接被拒绝)在 .../send-notification.php18 行 连接失败 111 连接被拒绝

这是第 18 行:

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

我知道 .pem 文件的密码是正确的。问题是如果我不能使用此端口该怎么办?我可以使用任何免费服务吗?我知道端口 80 是开放的。

我听说使用 curl() 函数可以工作,但到目前为止还没有成功。

我真的很感激能被指出正确的方向。

为了向设备发送通知,需要在防火墙中启用2195端口。出于安全原因,某些组织在防火墙中禁用这些端口。2196端口用于反馈服务,此端口也应在防火墙中打开。如果不打开这些端口,消息将无法传递到 APNS。

我相信

以下是您要查找的内容

$url = 'https://gateway.sandbox.push.apple.com:2195';
$cert = 'AppCert.pem';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_SSLCERT, $cert);
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, "passphrase");
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"device_tokens": ["458e5939b2xxxxxxxxxxx3"], "aps": {"alert": "test message one!"}}');
$curl_scraped_page = curl_exec($ch);

更多信息可以在这里找到:带有cURL的Apple推送通知

尝试使用端口 2196。

我也遇到过类似的问题,即使使用 cURL,您也会面临这个问题。请与您的托管服务提供商仔细检查传出端口 (2195,2196) 是否已打开或阻止。或者尝试远程登录ssl://gateway.sandbox.push.apple.com:2195
并检查您得到的响应。如果端口已打开,您将被连接。

我当前的托管服务提供商遇到了同样的问题。您可以切换到其他提供商-或-只需"购买"预算LAMP VPS(3欧元/月)。你很好去

在每个

共享主机中,他们禁用2195端口,因为您可以请求启用此端口,但在大多数共享主机公司中不要启用此端口,因此如果您想执行iOS推送通知,我建议您使用虚拟专用服务器(VPS),您可以轻松配置iOS推送通知。