自从关注了这个小伙子,妈妈再也不用担心我出bug了,后续会继续推出一系列的教程;
服务端下载地址:https://docs.jiguang.cn/jpush/resources/#sdk_1
这是最新版的skd目录结构,我们只需要src里的JPush,复制出来放到thinkphp的第三方函数库(其他地方也可以哦!);
登陆激光推送,获取AppKey&& Master Secret,如果没有应用先创建;
这是小弟随便封装的一个给指定用户推送的函数;
public function addPush($addtag,$content,$id,$type){ //new极光推送类,C函数是thinkphp取配置文件里的方法,这里取得是刚刚准备好的key&secret $client = new \JPush\Client(C('jpush_key'), C('jpush_secret')); $response = $client->push() //设置发送的平台 ->setPlatform(array('ios', 'android')) //别名,用于推送到指定用户 ->addalias($addtag) //设置给ios平台推送的数据 ->iosNotification('有新的评论:'.$content, array( 'sound' => 'sound.caf', 'badge' => '1', 'content-available' => true, 'mutable-content' => true, //推送的数据 'extras' => array( 'id' => $id, 'type' => $type ), )) //设置android平台推送 ->androidNotification('有新的评论:'.$content, array( 'title' => '有新的评论:'.$content, // 'build_id' => 2, 'extras' => array( 'id' => $id, 'type' => $type ), )) ->options(array( //设置推送环境是开发环境 or 运营模式(上线模式) 'apns_production' => false, )) //执行推送 ->send(); }友情提示:极光推送的样例在这里哟~~