Home >Backend Development >PHP Tutorial >PHP PEAR package developed for Apple Push: Services_Apple_PushNotification_PHP Tutorial
Apple Push Notification Service: Push messages to app users through Apple servers without starting the app.
Apple official documentation: http://developer.apple.com/library/mac/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/ApplePushService.html#//apple_ref/doc/uid/TP40008194-CH100-SW9
Standard URI
Advantages of PEAR: One-click installation to the php/lib/php directory, require to use, very convenient.
There is a Services_Apns on PHP PEAR and a Services_APNS on github, but they are both unusable, so I developed one. The installation steps are as follows:
pear channel-discover sinkcup.github.io/<span pear pear </span><span install</span> sinkcup/Services_Apple_PushNotification
Usage steps:
1. Log in to the Apple Developer Backend, download the dev or prod certificate, and merge it into a pem file. Add push permission to ios app and obtain device token. Reference: http://www.cnblogs.com/gpwzw/archive/2012/03/31/Apple_Push_Notification_Services_Tutorial_Part_1-2.html
2. demo (reference)
<?<span php require_once </span><span '</span><span Services/Apple/PushNotification.php</span><span '</span><span ; $conf </span>=<span array( </span><span '</span><span password</span><span '</span> => <span '</span><span 12346</span><span '</span><span , </span><span '</span><span cert</span><span '</span> => <span '</span><span /home/u1/cert.pem-sandbox</span><span '</span><span , ); $o </span>= new Services_Apple_PushNotification(<span '</span><span sandbox</span><span '</span><span , $conf); $deviceToken </span>= <span '</span><span aaaf818eaae8a5aa11aaaf9aa8f8aa15aaefae75a1aaaa597e51917aa2a1a111</span><span '</span><span ; $data </span>=<span array( </span><span '</span><span aps</span><span '</span> =><span array( </span><span '</span><span alert</span><span '</span> => <span '</span><span 测试push sandbox</span><span '</span><span , </span><span '</span><span badge</span><span '</span> => <span 2</span><span , </span><span '</span><span sound</span><span '</span> => <span '</span><span default</span><span '</span><span , ) ); $r </span>= $o-><span send($deviceToken, $data); var_dump($r); exit; </span>?>
Output:
<span bool</span>(<span true</span>)
My PEAR channel: http://sinkcup.github.io/pear/
Services_Apple_PushNotification project code: https://github.com/sinkcup/Services_Apple_PushNotification