极光推送

This commit is contained in:
weiz 2023-11-20 10:18:43 +08:00
parent aa8816b7df
commit e2c2a776f9
4 changed files with 41 additions and 4 deletions

View File

@ -245,10 +245,14 @@ class LogisticsLogic extends BaseLogic
//推送消息 //推送消息
$register_id = Courier::field('register_id')->where('id',$courier['user_id'])->find(); $register_id = Courier::field('register_id')->where('id',$courier['user_id'])->find();
if($register_id && !empty($register_id['register_id'])){ if($register_id && !empty($register_id['register_id'])){
$push_result = push_message($register_id['register_id'],'您有一条新的配送任务,请尽快处理!!'); $push_result1 = push_message($register_id['register_id'],'您有一条新的配送任务,请尽快处理!!');
if($push_result['code'] == 0) { $push_result2 = push_message($register_id['register_id'],'您有一条新的配送任务,请尽快处理!!');
Log::write('["极光推送:"]'.$push_result['msg'],'error'); if($push_result1['code'] == 0) {
Log::write('["极光推送:"]'.$push_result1['msg'],'error');
} }
if($push_result2['code'] == 0) {
Log::write('["极光推送:"]'.$push_result2['msg'],'error');
}
} }
return ['code'=>1, 'msg'=>'操作成功','data'=>['nickname'=>$courier['master_name'],'phone'=>$courier['master_phone']]]; return ['code'=>1, 'msg'=>'操作成功','data'=>['nickname'=>$courier['master_name'],'phone'=>$courier['master_phone']]];
} }

View File

@ -341,6 +341,25 @@ function push_message($reg_id,$message){
} }
} }
function push_message2($reg_id,$message){
//获取配置信息
$jpush_config = config('app.jpush2');
$app_key= $jpush_config['app_key']; //这是app密钥填你自己的
$master_secret= $jpush_config['master_secret']; //这也是密钥,填你自己的
//实例化
$client = new Client($app_key,$master_secret);
$pusher = $client->push();
$pusher->setPlatform('all');
$pusher->addRegistrationId($reg_id);
$pusher->setNotificationAlert($message);
try {
$res = $pusher->send();
return ['code'=>1,'msg'=>'','data'=>$res];
} catch (\JPush\Exceptions\JPushException $e) {
return ['code'=>0,'msg'=>$e->getMessage(),'data'=>[]];
}
}
/** /**
* 校验日期格式是否正确 * 校验日期格式是否正确

View File

@ -5,6 +5,7 @@
use app\common\model\logistics\Logistics; use app\common\model\logistics\Logistics;
use app\common\model\logistics\LogisticsRecord; use app\common\model\logistics\LogisticsRecord;
use app\common\model\logistics\Product; use app\common\model\logistics\Product;
use think\facade\Log;
class LogisticController extends BaseLikeAdminController class LogisticController extends BaseLikeAdminController
{ {
@ -178,4 +179,13 @@
//返回数据 //返回数据
return $result['code'] ==1 ? $this->success('配送完成') : $this->fail($result['msg']); return $result['code'] ==1 ? $this->success('配送完成') : $this->fail($result['msg']);
} }
// public function test() {
// $push_result = push_message2('1507bfd3f6c212e2012','您有一条新的配送任务,请尽快处理!!');
// if($push_result['code'] == 0) {
// Log::write('["极光推送:"]'.$push_result['msg'],'error');
// }else{
// return $this->success('ok',$push_result);
// }
// }
} }

View File

@ -29,9 +29,13 @@ return [
'error_message' => '页面错误!请稍后再试~', 'error_message' => '页面错误!请稍后再试~',
// 显示错误信息 // 显示错误信息
'show_error_msg' => false, 'show_error_msg' => false,
// 机关推送 // 极光推送
'jpush' => [ 'jpush' => [
'app_key' => '5ced5ec5fa7bb86302944f0f', 'app_key' => '5ced5ec5fa7bb86302944f0f',
'master_secret' => 'd85135e7d8470c90b476e535', 'master_secret' => 'd85135e7d8470c90b476e535',
], ],
'jpush2' => [
'app_key' => 'ef20394fbd9b59ead68f53b3',
'master_secret' => 'cb588b0d210df80b3659c543',
],
]; ];