原文地址: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);