无法通过 PHP 代码连接苹果 APN 服务器进行 pusNotification

发布于 2024-08-27 00:56:50 字数 802 浏览 4 评论 0原文

要将我的服务器与 APN 服务器连接,我使用以下代码。

// coonecting the apn server
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $errorNo, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

但是我连接失败,我打印了 $errorNo 和 $errorString 输出是: 错误:连接超时 errorNo: 110

但我还在 errorLog 中收到以下警告:

无法连接到第 35 行 /home/riseupla/public_html/applications/apn/apn.php 中的 ssl://gateway.sandbox.push.apple.com:2195(连接超时)

我该怎么办?

注意: 我可以通过我的 mac 项目发送推送通知(使用 Push me Baby 项目)。 但是我的PHP项目无法连接。

To connect my server with the APN server I use the following code.

// coonecting the apn server
$apnsHost = 'gateway.sandbox.push.apple.com';
$apnsPort = 2195;
$apnsCert = 'apns-dev.pem';
$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);

$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $errorNo, $errorString, 2, STREAM_CLIENT_CONNECT, $streamContext);

But I am failed to connect, I print the $errorNo and $errorString
the output was:
error: Connection timed out
errorNo: 110

But I am also getting the following warnings in errorLog:

Unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Connection timed out) in /home/riseupla/public_html/applications/apn/apn.php on line 35

What shoud I do?

NOTE:
I can send push notifications by my mac project (using push me baby project).
But my PHP project failed to connect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

雨后咖啡店 2024-09-03 00:56:50

您没有说您是否从与 Mac 不同的计算机运行 php,但如果您为 php 站点使用托管服务,那么 ISP 可能会阻止端口 2195(和 2196)。

尝试在运行 Mac 项目时使用的同一台计算机上运行 php,看看这是否有帮助。如果是这种情况,那么您的 ISP 很可能已阻止了这些端口,您必须寻找其他 ISP 或让他们打开这些端口。

克劳斯

You do not say if you run the php from a different machine than your Mac, but if you are using a hosted service for your php site, then it might be that the ISP has blocked port 2195 (and 2196).

Try to run your php on the same machine as you use when running your Mac project and see if this helps. If that's the case, then you ISP has most likely blocked the ports, and you will have to either find a different ISP or have them open the ports.

Claus

年华零落成诗 2024-09-03 00:56:50

你可能已经解决了。

但对于那些有兴趣了解端口是否被阻止的人:如果您可以通过 SSH 访问服务器,一个简单的方法是检查您是否可以 telnet 到服务器。这样我发现我的提供商阻止了端口...

:~ telnet gateway.sandbox.push.apple.com 2195
:~ telnet gateway.sandbox.push.apple.com 2196

您应该看到类似的内容:

Trying 17.172.232.236...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.

You probably solved it.

But for those interested to find out if the ports are blocked: IF you have SSH access to the server a simple way is to check if you can telnet to the server. This way i found out my provider blocked the ports...

:~ telnet gateway.sandbox.push.apple.com 2195
:~ telnet gateway.sandbox.push.apple.com 2196

You should see something like:

Trying 17.172.232.236...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.
夜空下最亮的亮点 2024-09-03 00:56:50

可能是你的服务器的IP不同,必须固定才能工作!!

may be that your server's IP variety, it must be fixed so work!!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文