php ApnsPHP 无法连接到 Apple Gateway

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6279185/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:53:31  来源:igfitidea点击:

ApnsPHP can't connect to Apple Gateway

phpapple-push-notifications

提问by Tim Specht

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

回答by saurabh

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:

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

$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.

我真的不知道这条线的重点是什么,但知道推送通知工作正常。

回答by Elminson De Oleo Baez

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. */

即时我来说,我变线58和59的文件ApnsPHP / Push.php该 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. */ protected $_aServiceURLs = array( 'gateway.push.apple.com:2195', // Production environment 'gateway.sandbox.push.apple.com:2195' // Sandbox environment ); /< @type array Service URLs environments. */

回答by Federico J. álvarez Valero

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

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

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

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

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

Hope that it helps. Regards.

希望它有帮助。问候。

回答by ahyong

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

我得到了同样的错误。我谷歌了很多并遵循本指南的每一步,确保我的 pem 文件正确生成: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:

然后我运行下面的命令来检查 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 

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)

然后我意识到我忘记了为证书设置密码(在我的情况下是 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);

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

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

回答by Nish

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

我有同样的问题,我做错的是为 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

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

回答by Gurjinder Singh

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

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

回答by Arpit

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

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