ApnsPHP 无法连接到 Apple 网关

发布于 2024-11-14 11:21:05 字数 1319 浏览 3 评论 0原文

今天突然出现一个非常奇怪的错误,说它无法连接到适当的网关......有什么修复建议吗?

这是记录器输出:

Wed, 08 Jun 2011 15:05:44 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:45 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:45 +0200 ApnsPHP[21724]: INFO: Retry to connect (1/3)...
Wed, 08 Jun 2011 15:05:46 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:47 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:47 +0200 ApnsPHP[21724]: INFO: Retry to connect (2/3)...
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: INFO: Retry to connect (3/3)...
Wed, 08 Jun 2011 15:05:49 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...

Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)' in /home/xxxx/xxxxx/ApnsPHP/Abstract.php:354

suddenly a really strange error appeared today, saying that it isn't able to connect to the appropriate gateway...any fix suggestions?

Here's the logger output:

Wed, 08 Jun 2011 15:05:44 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:45 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:45 +0200 ApnsPHP[21724]: INFO: Retry to connect (1/3)...
Wed, 08 Jun 2011 15:05:46 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:47 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:47 +0200 ApnsPHP[21724]: INFO: Retry to connect (2/3)...
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: ERROR: Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)
Wed, 08 Jun 2011 15:05:48 +0200 ApnsPHP[21724]: INFO: Retry to connect (3/3)...
Wed, 08 Jun 2011 15:05:49 +0200 ApnsPHP[21724]: INFO: Trying ssl://gateway.sandbox.push.apple.com:2195...

Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195':  (0)' in /home/xxxx/xxxxx/ApnsPHP/Abstract.php:354

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

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

发布评论

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

评论(7

为你鎻心 2024-11-21 11:21:05

这个解决方案对我有用。原始答案位于 推送通知服务器实现 -

我找到了解决方案,但没有知道这是否是最好的,但它确实有效。在 Abstract.php (该文件是 apns-php 源代码的一部分)上,我评论了第 343 行。现在它看起来像这样:

$streamContext = stream_context_create(array('ssl' => array(
//'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
'cafile' => $this->_sRootCertificationAuthorityFile,
'local_cert' => $this->_sProviderCertificateFile
)));

我真的不知道这一行的意义是什么,但知道推送通知正在工作适当地。

This solution worked for me. The original answer is on Push notifications server implementation -

I have found a solution, I don't know if it's the best, but it works. On Abstract.php (this file is part of the apns-php source) I have commented the line 343. Now it looks like this:

$streamContext = stream_context_create(array('ssl' => array(
//'verify_peer' => isset($this->_sRootCertificationAuthorityFile),
'cafile' => $this->_sRootCertificationAuthorityFile,
'local_cert' => $this->_sProviderCertificateFile
)));

I really don't know what is the point of this line, but know the push notification is working properly.

萌逼全场 2024-11-21 11:21:05

我的情况是我更改第 58 行和第 59 行文件 ApnsPHP/Push.php

<代码>
受保护的 $_aServiceURLs = 数组(
'ssl://gateway.push.apple.com:2195', // 生产环境
'ssl://gateway.sandbox.push.apple.com:2195' // 沙盒环境
); /<强>< @type array 服务 URL 环境。 */


<代码>
受保护的 $_aServiceURLs = 数组(
'gateway.push.apple.com:2195', // 生产环境
'gateway.sandbox.push.apple.com:2195' // 沙箱环境
); /
< @type array 服务 URL 环境。 */

im my case i change line 58 and 59 File ApnsPHP/Push.php
This

protected $_aServiceURLs = array(
'ssl://gateway.push.apple.com:2195', // Production environment
'ssl://gateway.sandbox.push.apple.com:2195' // Sandbox environment
); /< @type array Service URLs environments. */

With

protected $_aServiceURLs = array(
'gateway.push.apple.com:2195', // Production environment
'gateway.sandbox.push.apple.com:2195' // Sandbox environment
); /
< @type array Service URLs environments. */

苏佲洛 2024-11-21 11:21:05

您可以检查是否安装了正确的证书。查看此网址:https://code.google.com/p/apns- php/wiki/CertificateCreation 生成“entrust_root_certification_authority.pem”文件。

您可以通过在sample_push.php 上注释以下行来跳过证书验证:

    //$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

希望它有帮助。问候。

You might check you have the right certificates installed. Look into this URL: https://code.google.com/p/apns-php/wiki/CertificateCreation to generate 'entrust_root_certification_authority.pem' file.

You can skip the certificate validation by commenting the following line on sample_push.php:

    //$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

Hope that it helps. Regards.

冰火雁神 2024-11-21 11:21:05

请检查苹果文档中指定的端口。
您必须打开提供商端系统上的端口。

Please check with ports specified in apple doc.
You have to open the ports on your provider side system.

怪我入戏太深 2024-11-21 11:21:05

我遇到了同样的错误。我用谷歌搜索了很多并遵循本指南的每一步,确保我的 pem 文件正确生成:
https://code.google.com/p/apns-php/wiki/CertificateCreation

然后我运行下面的命令来检查 apns 的安全链接是否正确:

 openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-cert.pem -key apns-dev-key.pem -CApath /etc/ssl/certs/Entrust_Root_Certification_Authority.pem 

按 Enter 键,我收到此提示:

Enter pass phrase for apns-dev-key.pem:

然后我意识到我忘记了为证书设置密码(在我的情况下是 dev.pem)

// Instantiate a new ApnsPHP_Push object
$this->push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'dev.pem'
);
// Set the Provider Certificate passphrase
$this->push->setProviderCertificatePassphrase($passphrase);
// Set the Root Certificate Autority to verify the Apple remote peer
$this->push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$this->push->connect();
// Instantiate a new Message with a single recipient
$this->message = new ApnsPHP_Message($deviceToken);

为 apns pem 设置正确的密码,问题解决。

I got the same error. I google a lot and follow every step of this guide, make sure my pem file is generated rightly:
https://code.google.com/p/apns-php/wiki/CertificateCreation

then i run below command to check is the secure link to apns right or not:

 openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-cert.pem -key apns-dev-key.pem -CApath /etc/ssl/certs/Entrust_Root_Certification_Authority.pem 

Press enter and i got this prompt :

Enter pass phrase for apns-dev-key.pem:

then i realize that i forgot set passphrase for cert(it is dev.pem in my case)

// Instantiate a new ApnsPHP_Push object
$this->push = new ApnsPHP_Push(
    ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
    'dev.pem'
);
// Set the Provider Certificate passphrase
$this->push->setProviderCertificatePassphrase($passphrase);
// Set the Root Certificate Autority to verify the Apple remote peer
$this->push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
// Connect to the Apple Push Notification Service
$this->push->connect();
// Instantiate a new Message with a single recipient
$this->message = new ApnsPHP_Message($deviceToken);

set the right passphrase for the apns pem, problem solved.

倾`听者〃 2024-11-21 11:21:05

我遇到了同样的问题,我做错的是为 SSL 客户端身份验证和根 CA 提供相同的证书,下面的代码对我有用

$push = new ApnsPHP_Push(
        ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
        'ck.pem'
    );

$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

https://code.google.com/p/apns-php/wiki/CertificateCreation

I had same issue and what I did wrong was providing same certificate for SSL client authentication and the root CA, below code worked for me

$push = new ApnsPHP_Push(
        ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,
        'ck.pem'
    );

$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');

https://code.google.com/p/apns-php/wiki/CertificateCreation

陈年往事 2024-11-21 11:21:05

开发者需要以不同的方式导出 APNS 证书及其密钥。如果同时导出两者,则会出现此错误。

Developer need to export APNS certificate and its key differently. If both are exported in one go then this error will arise.

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