为Apple Push开发的PHP PEAR 包:Services_Apple_PushNotification
Apple Push Notification Service:通過蘋果服務(wù)器向app用戶推送消息,無需啟動app。
蘋果官方文檔:http://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9
對于這種第三方庫,PHP官方稱之為PEAR,需要按照PEAR標準開發(fā)(標準URI)。
PEAR的優(yōu)勢:一鍵安裝到php/lib/php目錄,require即可使用,很方便。
PHP PEAR上有一個Services_Apns,github上有一個Services_APNS,但都無法使用,所以我開發(fā)了一個,安裝步驟如下:
pear channel-discover sinkcup.github.io/pear pear install sinkcup/Services_Apple_PushNotification使用步驟:
1、登錄蘋果開發(fā)者后臺,下載dev或prod證書,合并成pem文件。在ios app里添加push權(quán)限,獲得device token。參考:http://www.cnblogs.com/gpwzw/archive/2012/03/31/Apple_Push_Notification_Services_Tutorial_Part_1-2.html
2、demo(參考)
<?php require_once 'Services/Apple/PushNotification.php'; $conf = array('password' => '12346','cert' => '/home/u1/cert.pem-sandbox', ); $o = new Services_Apple_PushNotification('sandbox', $conf); $deviceToken = 'aaaf818eaae8a5aa11aaaf9aa8f8aa15aaefae75a1aaaa597e51917aa2a1a111'; $data = array('aps' => array('alert' => '測試push sandbox','badge' => 2,'sound' => 'default',) ); $r = $o->send($deviceToken, $data); var_dump($r); exit; ?>輸出:
bool(true)我的PEAR 頻道:http://sinkcup.github.io/pear/
Services_Apple_PushNotification項目代碼:https://github.com/sinkcup/Services_Apple_PushNotification
轉(zhuǎn)載于:https://www.cnblogs.com/sink_cup/p/PHP-PEAR-Services_Apple_PushNotification.html
總結(jié)
以上是生活随笔為你收集整理的为Apple Push开发的PHP PEAR 包:Services_Apple_PushNotification的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: rabbitmq 学习-2-安装
- 下一篇: Bjarne Stroustrup语录[