原文地址:http://blog.csdn.net/zhihua_w/article/details/52197611php
極光推送(JPush)是獨立的第三方雲推送平臺,致力於爲全球移動應用開發者提供專業、高效的移動消息推送服務。json
本篇博文講述如何在將極光推送DEMO整合到ThinkPHP框架中,我使用的是極光推送PHP_DEMO_V3.4.3版本:
數組
一、將極光推送DEMO文件(文件夾名稱爲Jpush)放入到你的公共文件夾(Common)中,按照極光開發文檔在極光後臺創建好本身的應用,獲取相應的app_key、master_secret,在文件中將會用到這兩個值;
app
二、如上,在公共文件夾(Common)下創建function.php文件;框架
-
- function json_array($result){
- $result_json = json_encode($result);
- return json_decode($result_json,true);
- }
-
-
- function sendNotifyAll($message){
- require_once "JPush\JPush.php";
- $app_key = 'your app_key';
- $master_secret = 'your master_secret';
- $client = new \JPush($app_key,$master_secret);
- $result = $client->push()->setPlatform('all')->addAllAudience()->setNotificationAlert($message)->send();
- return json_array($result);
- }
-
-
-
- function sendNotifySpecial($regid,$message){
- require_once "JPush\JPush.php";
- $app_key = 'your app_key';
- $master_secret = 'your master_secret';
- $client = new \JPush($app_key,$master_secret);
- $result = $client->push()->setPlatform('all')->addRegistrationId($regid)->setNotificationAlert($message)->send();
- return json_array($result);
- }
-
-
-
- function sendSpecialMsg($regid,$message,$did,$mid){
- require_once "JPush\JPush.php";
- $app_key = 'your app_key';
- $master_secret = 'your master_secret';
- $client = new \JPush($app_key,$master_secret);
- $result = $client->push()->setPlatform('all')->addRegistrationId($regid)
- ->addAndroidNotification($message,'',1,array('did'=>$did,'mid'=>$mid))
- ->addIosNotification($message,'','+1',true,'',array('did'=>$did,'mid'=>$mid))->send();
-
- return json_array($result);
- }
-
-
- function reportNotify($msgIds){
- require_once "JPush\JPush.php";
- $app_key = 'your app_key';
- $master_secret = 'your master_secret';
- $client = new \JPush($app_key,$master_secret);
- $response = $client->report()->getReceived($msgIds);
- return json_array($response);
- }
在文件中寫入各類集成函數,以方便在系統應用控制器中進行調用。
函數
三、最後即是在控制器中進行調用便可;ui
-
-
-
- $result_s = sendNotifySpecial($regid, $data['content']);
-
-
- $result_a = sendNotifyAll($data['content']);
-
-
-
- $result_r = reportNotify($msgIds);