简体   繁体   中英

Push notifications server implementation

I'm trying to make work apns-php (http://code.google.com/p/apns-php/) on my server (Bluehost with dedicated IP and port 2195 open for tcp and udp outgoing).

I'm getting this error:

Fatal error: Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.sandbox.push.apple.com:2195': (0)' in /home2/xxxxx/public_html/xxxxx/pns/ApnsPHP/Abstract.php:352 Stack trace: #0 /home2/xxxxx/public_html/xxxxx/pns/ApnsPHP/Abstract.php(295): ApnsPHP_Abstract->_connect() #1 /home2/xxxxx/public_html/xxxxx/pns/sample_push.php(41): ApnsPHP_Abstract->connect() #2 {main} thrown in /home2/xxxxx/public_html/xxxxx/pns/ApnsPHP/Abstract.php on line 352

I have contact Bluehost support and they told me this:

Thanks for contacting us. If seems as though the server ssl://gateway.sandbox.push.apple.com:2195* is refusing to accept the connection made from your account. Is there a way you can whitelist your dedicated ip or accept incoming connections on their end?

Someone can help me to solve this out? Any ideas? Thanks!

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. My doubt is if it will work properly too on production server. Someone knows?

In our case we did not do the last part of this tutorial; http://code.google.com/p/apns-php/wiki/CertificateCreation (thinking it was optional)

Which resulted in exactly the same errors as you had.

After we did that, everything worked as expected.

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

你可能需要联系苹果..因为它听起来是苹果阻止你的应用程序访问他们的网关..你需要联系苹果,以便你可以获得你的IP地址或网络应用程序批准

This problem is exactly what i was seeing in local development. I'm assuming you'd want to uncomment that line once it's on the server and the certs are all setup properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM