ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
使用 Composer 安装 * 在项目中的 composer.json 文件中添加 jpush 依赖: `"require": { "jpush/jpush": "^3.5" }` (* ̄︶ ̄) 然后就可以开始编写代码啦! ~~~ namespace app\extendService; use JPush\Client as JPush; use think\Db; use think\Exception; class JpushService{ const APP_KEY = '************************';//极光创建应用后的app_key const MASTER_SECRET = '************************';//极光创建应用后的master_secret public function send(string $content, int $push_type = 0, string $target = null, array $extras = null) { //实例化jpush $jpush = new JPush(self::APP_KEY, self::MASTER_SECRET, null); //推送平台 $client = $jpush->push()->setPlatform('all'); //推送目标 $push_type == 0 && $client->addAllAudience(); //推送所有 $push_type == 1 && $client->addTag($target); //标签推送 OR关系 $push_type == 2 && $client->addTagAnd($target); //标签推送 AND关系 $push_type == 3 && $client->addAlias($target); //别名推送 $push_type == 4 && $client->addRegistrationId($target); //注册ID推送 $iosParam = [ 'sound' => 'sound', 'badge' => '+1', //ios推送图标+1 ]; !empty($extras) && $iosParam['extras'] = $extras; $androidParam = !empty($extras) ? ['extras' => $extras] : []; //设置推送具体值 $client ->AndroidNotification($content, $androidParam) ->iosNotification($content, $iosParam) ->message($content, $androidParam);//为了让Android在打开app时不用点击推送消息程序即可接收到 return $client->send(); } } ~~~ 注:具体推送方式请查看官方API文档