无法从 php 连接到 apns

发布于 2024-12-06 21:19:06 字数 1366 浏览 0 评论 0原文

我在从我的生产机器(它是 vps 托管)连接到 Apple apns 时遇到问题。

  1. 我询问了托管技术援助,他们说他们不会阻止任何端口上的传出连接,并且日志没有显示任何此问题,他们不知道可能导致此问题的原因,因此没有帮助。
  2. 这适用于我的本地开发机器,iPhone 会收到通知。
  3. extension=php_openssl.dll 已在两台计算机上的 php.ini 文件中启用。
  4. 在两台机器上 telnet 都会出现黑屏,并且不会像我在此处的某些线程上看到的那样做出响应。

我使用的代码是:

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 10, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', $deviceToken) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
fclose($apns);

我得到的错误是:

Warning: stream_socket_client(): SSL: crypto enabling timeout in test.php on line 116

Warning: stream_socket_client(): Failed to enable crypto in test.php on line 116

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in test.php on line 116

Warning: fwrite() expects parameter 1 to be resource, boolean given in test.php on line 118

Warning: fclose() expects parameter 1 to be resource, boolean given in test.php on line 119

最后两个错误是连接失败时给出的,但前三个错误我无法解决。

任何帮助将不胜感激:)

I am having trouble connecting to the apple apns from my production machine, its a vps hosting.

  1. I asked the hosting technical assistance and they said that they do not block outgoing connections on any port and that the logs show nothing of this problem and they have no idea what might cause this, so no help there.
  2. This works on my local dev machine and the iPhone gets the notifications.
  3. extension=php_openssl.dll is enabled in the php.ini file on both machines.
  4. on both machines telnet gives a black screen and not a response like i saw on some threads here.

The code im using is:

$streamContext = stream_context_create();
stream_context_set_option($streamContext, 'ssl', 'local_cert', $apnsCert);
$apns = stream_socket_client('ssl://' . $apnsHost . ':' . $apnsPort, $error, $errorString, 10, STREAM_CLIENT_CONNECT, $streamContext);
$apnsMessage = chr(0) . chr(0) . chr(32) . pack('H*', $deviceToken) . chr(0) . chr(strlen($payload)) . $payload;
fwrite($apns, $apnsMessage);
fclose($apns);

And the error I get are:

Warning: stream_socket_client(): SSL: crypto enabling timeout in test.php on line 116

Warning: stream_socket_client(): Failed to enable crypto in test.php on line 116

Warning: stream_socket_client(): unable to connect to ssl://gateway.sandbox.push.apple.com:2195 (Unknown error) in test.php on line 116

Warning: fwrite() expects parameter 1 to be resource, boolean given in test.php on line 118

Warning: fclose() expects parameter 1 to be resource, boolean given in test.php on line 119

The last two errors are a given as the connection fails, but the first three I can't resolve them.

Any help will be appreciated :)

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文