ApnsPHP:推送通知的开发工作,但不是在生产中 [英] ApnsPHP: Push notifications working in development but not in production

查看:486
本文介绍了ApnsPHP:推送通知的开发工作,但不是在生产中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是:有很多重复这个问题,但没有答案的帮助

Yes: there are many duplicates to this question, but none of the answers helped.

我下面这个伟大的教程阿里Hafizji使用APNS服务推送通知

测试APNS在开发模式


  • 下载 aps_development.cer

  • 导出证书的私钥( aps_development_key.p12

  • download aps_development.cer
  • export the private key for the certificate (aps_development_key.p12)

然后我结合这两个使用以下命令(使用终端):

Then I combined the two using following commands (using terminal):

openssl x509 -in aps_development.cer -inform der -out aps_development.pem
openssl pkcs12 -nocerts -out aps_development_key.pem -in aps_development.p12
cat aps_development.pem aps_development_key.pem > final_aps_development.pem

和(在服务器上使用ApnsPHP)我可以成功发送推送通知这个配置:

And (using ApnsPHP on server) I could successfully send a push-notification with this configuration:

...
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_SANDBOX,'final_aps_development.pem');
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push->setProviderCertificatePassphrase('mypassword');
...

一个旁注:我把entrust_root_certification_authority.pem从 https://github.com/jonathanrcarter/ push2 preSS
正确的地址去寻找它很可能是 https://www.entrust.net/downloads /binary/entrust_2048_ca.cer
(他们是同样的事情反正)。

A sidenote: i took the entrust_root_certification_authority.pem from https://github.com/jonathanrcarter/push2press, the correct address to look for it would probably be https://www.entrust.net/downloads/binary/entrust_2048_ca.cer (they are the same thing anyway).

在这种情况下,应用程序在调试模式正在运行(在设备上,从X code运行),一切都正常工作。

In this case application was running in debug mode (on device, run from XCode) and everything was working fine.

测试APNS在的生产模式

要在生产模式下测试APNS我存档即席分发应用程序和的 iPhone配置实用工具

To test APNS in production mode i archived the app for AdHoc distribution and installed it on device with iPhone Configuration Utility.

我也跟着用 aps_production.cer 相同的步骤,使 final_aps_production.pem

I followed the same procedure with aps_production.cer to make final_aps_production.pem.

浜,PHP脚本被称为发送推送通知返回的HTML状态code 500。

Bang, the php script that is called to send push-notifications returned HTML Status Code 500.

$推代是课程修改了生产方式:

The $push generation was of-course modified for production mode:

...
$push = new ApnsPHP_Push(ApnsPHP_Abstract::ENVIRONMENT_PRODUCTION,'final_aps_production.pem');
$push->setRootCertificationAuthority('entrust_root_certification_authority.pem');
$push->setProviderCertificatePassphrase('mypassword');
...

一个快速浏览到 /var/log/apache2/error.log 指出的问题:

A quick look to /var/log/apache2/error.log indicated the problem:

PHP Fatal error:  Uncaught exception 'ApnsPHP_Exception' with message 'Unable to connect to 'ssl://gateway.push.apple.com:2195':  (0)' in /var/www/gettapro/mobile/ApnsPHP/Abstract.php:398\nStack trace:\n#0 /var/www/gettapro/mobile/ApnsPHP/Abstract.php(334): ApnsPHP_Abstract->_connect()\n#1  ....

周围的Googling(有有这个问题,很多人)被证明无果而终。

Googling around (there are many people having this problem) proved fruitless.

许多不同的意见,这样即使如此作为的bizzare改变拿着证书到775目录的文件权限......没有任何的建议,为我工作。

Many different advices, such even so bizzare as to change the file permissions of the directory holding the certificates to 775... none of the suggestions worked for me.

我也试图在 ApnsPHP / Abstract.php 这种变化(这里建议:的 https://github.com/duccio/ApnsPHP/issues/29 ),但没有成功。

I have also tried this change in ApnsPHP/Abstract.php (suggested here: https://github.com/duccio/ApnsPHP/issues/29) but with no success.

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

这讨厌的 ApnsPHP_Exception 并没有消失。

当然,我也确信,当我测试的生产模式正确的设备APNS
令牌 - 设备的APN令牌调试和生产方式是不一样的的 - 使用。

Of course i also made sure that when i was testing the production mode the correct device APNS token - device APNS tokens in debugging and production mode are not the same - was used.

总之:令牌不能因为我的通知发送脚本甚至不能连接到 SSL一个问题://gateway.push.apple.com:2195

Anyway: tokens can not be a problem since my notification sending script can't even connect to ssl://gateway.push.apple.com:2195.

试图连接 SSL://gateway.push.apple.com:2195 通过远程登录只是为了让肯定的是:连接被罚款

Tried to connect ssl://gateway.push.apple.com:2195 via telnet just to make sure: connection was fine.

很明显:这是一个证书有问题

It became obvious: it is a certificate problem.

推荐答案

似乎 aps_production.cer 不应该handeled方法一样 aps_development.cer

It seems that aps_production.cer shouldn't be handeled the same way as aps_development.cer

下面来的<一个href=\"https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ProvisioningDevelopment.html#//apple_ref/doc/uid/TP40008194-CH104-SW6\">RTFM此刻的。

下载并在钥匙串上安装证书(双击 aps_production.cer

Download and install certificate in the keychain (double clicking aps_production.cer)

从钥匙串访问导出aps_production证书的.p12 版本(也设置在这里密码)。

Export a .p12 version of aps_production certificate (you also set a password here) from the Keychain Access.

将其转换为质子交换膜使用此命令格式(必须在这里输入密码):

Convert it to .pem format using this command (you will have to enter password here):

openssl pkcs12 -in aps_production.p12 -out final_aps_production.pem -nodes

的 - 一切都开始工作,我又一个快乐的人。

And voilà - everything started working and i am a happy camper again.

有关于如何导出证书和放大器伟大的教程类的指令由Jeremy;关键这里SO

There are great tutorial-like instructions by Jeremy on how to export certificate & key here on SO.

这篇关于ApnsPHP:推送通知的开发工作,但不是在生产中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆