項目中用到了給客戶端的推送功能,選用了極光推送,下面演示一下在thinkphp中集成極光推送php
1.下載極光推送的php類,能夠從筆者的git下載git
地址:https://git.oschina.net/zhangchao123/jiguangtuisongphplei.git
2.thinkphp集成thinkphp
解壓後,直接把jpush文件夾放在Thinkphp/Libray/Vender目錄
/*
* 極光推送
* $pushId:極光ID,字符串或者array()
* $content:推送內容
* $remark:備註
* $type:推送類型參數array()
*/app
function pushMessage($pushId,$content,$remark,$type){
vendor('JPush.JPush');
$jPush = C('jPush');
$app_key = $jPush['app_key'];
$master_secret = $jPush['master_secret'];
$client = new \JPush($app_key, $master_secret);
$result = $client->push()
->setPlatform('all')
->addRegistrationId($pushId)
->addAndroidNotification($content,"'".$remark."'", 1,$type)
->addIosNotification($content, 'iOS sound', '+1', true, 'iOS category',$type)
->send();
return $result;
}ui