2013-09-26 79 views
4

是的:這個問題有很多重複,但沒有任何答案有幫助。ApnsPHP:推送通知在開發中工作,但不在生產

我正在關注這個偉大的tutorial by Ali Hafizji on using APNS service for push notifications

測試APNS在發展模式

  • 下載aps_development.cer
  • 導出私鑰證書(aps_development_key.p12

然後我用下面的命令兩者合用(使用終端):

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)我可以成功發送推送通知這個配置:

... 
$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/push2press, 正確的地址去尋找它很可能是https://www.entrust.net/downloads/binary/entrust_2048_ca.cer (無論如何,它們都是同樣的東西)。

在這種情況下,應用程序運行在調試模式(在設備上,從XCode運行),一切工作正常。

測試APNS在生產模式

要在生產模式測試APNS我存檔以用於即席分發應用程序,並用iPhone Configuration Utility它安裝在設備上。

我遵循相同的程序與aps_production.cer,使final_aps_production.pem

爆炸,PHP腳本被稱爲發送推送通知返回的HTML狀態碼500

$push一代人的課程修改生產模式:

... 
$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指出的問題:

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(有有這個問題,很多人)被證明fruitle SS。

許多不同的建議,例如甚至如此bizzare以更改持有證書的目錄的文件權限爲775 ...沒有任何建議爲我工作。

我也在ApnsPHP/Abstract.php(建議在這裏:https://github.com/duccio/ApnsPHP/issues/29)試過這個改變,但沒有成功。

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

那討厭ApnsPHP_Exception沒有消失。

當然,我還相信,當我在測試的生產模式正確的設備APNS 令牌 - 設備APNS在調試和生產模式令牌是不一樣的 - 使用。

無論如何:令牌不能成爲問題,因爲我的通知發送腳本甚至不能連接到ssl://gateway.push.apple.com:2195

試圖連接ssl://gateway.push.apple.com:2195通過telnet只是爲了確保:連接是好的。

很明顯:這是一個證書問題。

回答

7

看來aps_production.cer不應handeled的方式aps_development.cer

相同這裏談到的RTM moment。在鑰匙串

下載並安裝證書(雙擊aps_production.cer

出口.p12版本aps_production證書從鑰匙串訪問(您還可以設置密碼,在這裏)。

使用此命令將其轉換爲.pem格式(必須在這裏輸入密碼):

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

而且 - 一切都開始工作,我又是一個快樂的人。

Jeremy有很多關於如何導出證書的教程式指令& key here on SO

+1

您正在導出CERTIFICATE的.p12或證書的KEY嗎?這是你的意思,他們不應該被類似地處理? – Jeremy

+1

我的措辭很笨拙 - 可能兩個證書都可以用相同的方式安裝。在這最後一個變體中,首先將證書安裝在鑰匙串(OSX)中,然後將其與鑰匙組合在一起導出。更不用說這樣出錯了。 –

+4

我可以吻你 – Jeremy

相關問題