JWT_UID 去除,更换为$this->rquest->uid

This commit is contained in:
monanxiao 2023-03-08 10:26:24 +08:00
parent f311e89370
commit da33dffa5a
11 changed files with 143 additions and 103 deletions

View File

@ -102,6 +102,7 @@ class Index extends BaseController
$data['user_id'] = $this->adminInfo['id']; // 操作用户ID $data['user_id'] = $this->adminInfo['id']; // 操作用户ID
$data['name'] = $params['title']; // 团队名称 $data['name'] = $params['title']; // 团队名称
$data['tel'] = $params['phone']; // 联系电话 $data['tel'] = $params['phone']; // 联系电话
$data['shareRate'] = $params['shareRate']; // 分润比例
$data['mer_id_list'] = json_encode($params['mer_id']); // 已选商户 $data['mer_id_list'] = json_encode($params['mer_id']); // 已选商户
$data['street_id'] = $params['street_id']; // 街道ID $data['street_id'] = $params['street_id']; // 街道ID
@ -169,6 +170,7 @@ class Index extends BaseController
$data['user_id'] = $this->adminInfo['id']; // 操作用户ID $data['user_id'] = $this->adminInfo['id']; // 操作用户ID
$data['name'] = $params['title']; // 团队名称 $data['name'] = $params['title']; // 团队名称
$data['tel'] = $params['phone']; // 联系电话 $data['tel'] = $params['phone']; // 联系电话
$data['shareRate'] = $params['shareRate']; // 分润比例
$data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户 $data['mer_id_list'] = isset($params['mer_id']) ? json_encode($params['mer_id']) : null; // 已选商户
$data['street_id'] = $params['street_id']; // 街道ID $data['street_id'] = $params['street_id']; // 街道ID
$street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据 $street = GeoStreet::where('street_id', $data['street_id'])->find(); // 街道数据

View File

@ -73,6 +73,16 @@
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<td colspan="4">
<div class="layui-col-md4">
<label class="layui-form-label">分润比例<font>*</font></label>
<div class="layui-input-block">
<input type="text" name="shareRate" required lay-verify="required" placeholder="请输入分润比例" autocomplete="off" class="layui-input">
</div>
</div>
</td>
</tr>
<tr> <tr>
<td class="layui-td-gray">请选择所在地址<font>*</font></td> <td class="layui-td-gray">请选择所在地址<font>*</font></td>
<td> <td>

View File

@ -74,7 +74,16 @@
</div> </div>
</td> </td>
</tr> </tr>
<tr>
<td colspan="4">
<div class="layui-col-md4">
<label class="layui-form-label">分润比例<font>*</font></label>
<div class="layui-input-block">
<input type="text" name="shareRate" required lay-verify="required" placeholder="{$detail.shareRate}" autocomplete="off" class="layui-input">
</div>
</div>
</td>
</tr>
<tr> <tr>
<td class="layui-td-gray">请选择所在地址<font>*</font></td> <td class="layui-td-gray">请选择所在地址<font>*</font></td>
<td> <td>

View File

@ -96,6 +96,11 @@
title: '联系电话', title: '联系电话',
align: 'center', align: 'center',
width:150, width:150,
},{
field: 'shareRate',
title: '分佣比例',
align: 'center',
width:150,
},{ },{
field: 'earnings_amount', field: 'earnings_amount',
title: '净收益', title: '净收益',

View File

@ -83,52 +83,62 @@ abstract class BaseController
//每页显示数据量 //每页显示数据量
$this->pageSize = Request::param('page_size', \think\facade\Config::get('app.page_size')); $this->pageSize = Request::param('page_size', \think\facade\Config::get('app.page_size'));
$token = Request::header('x-Token');
if ($token) {
if (strpos($token, 'Bearer') === 0){
$token = trim(substr($token, 6));
}
if (count(explode('.', $token)) != 3) {
return json(['code'=>404,'msg'=>'非法请求']);
}
$config = get_system_config('token');
//var_dump($config);exit; // 暂时去除 -----------------------------------------------------
try { // $token = Request::header('x-Token');
JWT::$leeway = 60;//当前时间减去60把时间留点余地 // if ($token) {
$decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应 // if (strpos($token, 'Bearer') === 0){
// $token = trim(substr($token, 6));
// }
// if (count(explode('.', $token)) != 3) {
// return json(['code'=>404,'msg'=>'非法请求']);
// }
// $config = get_system_config('token');
//return (array)$decoded; // return json($token);
// $decoded_array = json_decode(json_encode($decoded),TRUE); // JWT::$leeway = 60;//当前时间减去60把时间留点余地
// $jwt_data = $decoded_array['data']; // $decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应
$user=Db::connect('shop')->name('nk_user')->where('user_id',$decoded->jti[0])->find(); // return $decoded->jti[0];
if (!$user){ // exit;
return json(['code'=>403,'msg'=>'签名错误']); // //var_dump($config);exit;
return false; // try {
} // JWT::$leeway = 60;//当前时间减去60把时间留点余地
$user = Db::table('fa_user')->where('id',$user['n_user_id'])->find(); // $decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应
//$request->uid = $jwt_data['userid'];
define('JWT_UID', $user['id']); // //return (array)$decoded;
// $response = $next($request); // // $decoded_array = json_decode(json_encode($decoded),TRUE);
// return $response; // // $jwt_data = $decoded_array['data'];
//return $next($request);
} catch(\Firebase\JWT\SignatureInvalidException $e) { //签名不正确 // $user=Db::connect('shop')->name('nk_user')->where('user_id',$decoded->jti[0])->find();
return json(['code'=>403,'msg'=>'签名错误']); // if (!$user){
}catch(\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用 // return json(['code'=>403,'msg'=>'签名错误']);
return json(['code'=>401,'msg'=>'token失效']); // return false;
}catch(\Firebase\JWT\ExpiredException $e) { // token过期 // }
return json(['code'=>401,'msg'=>'token已过期']); // $user = Db::table('fa_user')->where('id',$user['n_user_id'])->find();
}catch(Exception $e) { //其他错误 // //$request->uid = $jwt_data['userid'];
return json(['code'=>404,'msg'=>'非法请求']); // define('JWT_UID', $user['id']);
}catch(\UnexpectedValueException $e) { //其他错误 // // $response = $next($request);
return json(['code'=>404,'msg'=>'非法请求']); // // return $response;
} catch(\DomainException $e) { //其他错误 // //return $next($request);
return json(['code'=>404,'msg'=>'非法请求']); // } catch(\Firebase\JWT\SignatureInvalidException $e) { //签名不正确
} // return json(['code'=>403,'msg'=>'签名错误']);
}else{ // }catch(\Firebase\JWT\BeforeValidException $e) { // 签名在某个时间点之后才能用
define('JWT_UID', ''); // return json(['code'=>401,'msg'=>'token失效']);
} // }catch(\Firebase\JWT\ExpiredException $e) { // token过期
// return json(['code'=>401,'msg'=>'token已过期']);
// }catch(Exception $e) { //其他错误
// return json(['code'=>404,'msg'=>'非法请求']);
// }catch(\UnexpectedValueException $e) { //其他错误
// return json(['code'=>404,'msg'=>'非法请求']);
// } catch(\DomainException $e) { //其他错误
// return json(['code'=>404,'msg'=>'非法请求']);
// }
// }else{
// define('JWT_UID', '');
// }
// 暂时去除 -----------------------------------------------------
} }
/** /**

View File

@ -41,8 +41,8 @@ class Article extends BaseController
unset($where[1]); unset($where[1]);
} }
//根据个人村id进行查询 //根据个人村id进行查询
if (JWT_UID) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();
if ($find) { if ($find) {
if ($find['auth_range']==1){ if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']]; $where[] = ['village', '=', $find['village_id']];
@ -54,7 +54,7 @@ class Article extends BaseController
} }
// 登录返回村名和村地址 // 登录返回村名和村地址
$cun_arr['cun_name'] = Db::table('fa_geo_village')->where('village_id', $find['village_id'])->value('village_name'); $cun_arr['cun_name'] = Db::table('fa_geo_village')->where('village_id', $find['village_id'])->value('village_name');
$cun_arr['cun_address'] = Db::table('fa_szxc_information_usermsg')->where('user_id', JWT_UID)->value('address_name'); $cun_arr['cun_address'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $this->request->uid)->value('address_name');
}else{ }else{
$cun_arr = []; $cun_arr = [];
} }
@ -183,8 +183,8 @@ class Article extends BaseController
unset($where[1]); unset($where[1]);
} }
// 如果登录 // 如果登录
if (JWT_UID) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();
if ($find) { if ($find) {
if ($find['auth_range']==1){ if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']]; $where[] = ['village', '=', $find['village_id']];
@ -312,8 +312,8 @@ class Article extends BaseController
['status', '=', 1], ['status', '=', 1],
]; ];
//根据个人村id进行查询 //根据个人村id进行查询
if (JWT_UID) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();
if ($find) { if ($find) {
if ($find['auth_range']==1){ if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']]; $where[] = ['village', '=', $find['village_id']];
@ -497,7 +497,7 @@ class Article extends BaseController
// if (!$res) { // if (!$res) {
// return $this->apiError($valdate->getError()); // return $this->apiError($valdate->getError());
// } // }
$useraddress = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->where('status', 1)->find(); $useraddress = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->where('status', 1)->find();
$data = []; $data = [];
if ($useraddress) { if ($useraddress) {
@ -507,7 +507,7 @@ class Article extends BaseController
} }
$data['end_time'] = date('Y-m-d H:i:s', strtotime('+1 day')); $data['end_time'] = date('Y-m-d H:i:s', strtotime('+1 day'));
$data['view_time'] = date('Y-m-d H:i:s'); $data['view_time'] = date('Y-m-d H:i:s');
$data['user_id'] = JWT_UID;//添加用户的id $data['user_id'] = $this->request->uid;//添加用户的id
$data['category_id'] = $input['category_id'];//大分类id $data['category_id'] = $input['category_id'];//大分类id
$data['category_type'] = $input['category_type'];//小分类id $data['category_type'] = $input['category_type'];//小分类id
$data['title'] = $input['title'];//标题 $data['title'] = $input['title'];//标题
@ -518,7 +518,7 @@ class Article extends BaseController
$data['image'] = $input['image'];//封面 $data['image'] = $input['image'];//封面
$data['is_vote'] =empty($input['is_vote'])?0:$input['is_vote'];//是否投票 $data['is_vote'] =empty($input['is_vote'])?0:$input['is_vote'];//是否投票
if ($input['category_id']==150){ if ($input['category_id']==150){
$name=Db::table('fa_szxc_information_usermsg')->where('user_id',JWT_UID)->value('name'); $name=Db::table('fa_szxc_information_usermsg')->where('user_id',$this->request->uid)->value('name');
$data['title'] = '来自于'.$name.'的一键求救'; $data['title'] = '来自于'.$name.'的一键求救';
} }
$res = Db::table('fa_article')->insertGetId($data); $res = Db::table('fa_article')->insertGetId($data);
@ -575,7 +575,7 @@ class Article extends BaseController
$data['describe'] = empty($input['describe'])?'':$input['describe'];//简介 $data['describe'] = empty($input['describe'])?'':$input['describe'];//简介
$data['image'] = $input['image'];//封面 $data['image'] = $input['image'];//封面
$data['is_vote'] = $input['is_vote'];//是否投票 $data['is_vote'] = $input['is_vote'];//是否投票
$input['update_user_id'] = JWT_UID;//更新用户的id $input['update_user_id'] = $this->request->uid;//更新用户的id
$res = Db::table('fa_article')->where('id', $id)->update($data); $res = Db::table('fa_article')->where('id', $id)->update($data);
if ($input['is_vote'] == 1) { if ($input['is_vote'] == 1) {
@ -596,8 +596,8 @@ class Article extends BaseController
{ {
// $model = Db::table('fa_article'); // $model = Db::table('fa_article');
//根据个人村id进行查询 //根据个人村id进行查询
if (JWT_UID) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();
if ($find) { if ($find) {
if ($find['auth_range']==1){ if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']]; $where[] = ['village', '=', $find['village_id']];
@ -650,12 +650,12 @@ class Article extends BaseController
{ {
// $model = Db::table('fa_article'); // $model = Db::table('fa_article');
//根据个人id进行查询 //根据个人id进行查询
$where[] = ['a.user_id','=',JWT_UID]; $where[] = ['a.user_id','=',$this->request->uid];
$where[] = ['b.is_read','=','0']; $where[] = ['b.is_read','=','0'];
$which = []; $which = [];
//根据个人村id进行查询 //根据个人村id进行查询
if (JWT_UID) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();
if ($find) { if ($find) {
if ($find['auth_range']==1){ if ($find['auth_range']==1){
$www[] = ['a.village', '=', $find['village_id']]; $www[] = ['a.village', '=', $find['village_id']];
@ -665,7 +665,7 @@ class Article extends BaseController
$www[] = ['a.county', '=', $find['area_id']]; $www[] = ['a.county', '=', $find['area_id']];
} }
} }
$which['user_id'] = JWT_UID; $which['user_id'] = $this->request->uid;
} }
$yishi = Db::table('fa_article')->alias('a')->join(['fa_article_vote_side_tables' => 'b'],'a.id=b.article_id')->where($www)->where('a.category_id',162)->whereTime('b.end_time', '>', date('Y-m-d H:i:s'))->count(); $yishi = Db::table('fa_article')->alias('a')->join(['fa_article_vote_side_tables' => 'b'],'a.id=b.article_id')->where($www)->where('a.category_id',162)->whereTime('b.end_time', '>', date('Y-m-d H:i:s'))->count();
$maodun = Db::table('fa_article')->alias('a')->join(['fa_article_comment' => 'b'],'a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id',147)->count(); $maodun = Db::table('fa_article')->alias('a')->join(['fa_article_comment' => 'b'],'a.id=b.vote_id')->where('a.is_solve', 1)->where($where)->where('a.category_id',147)->count();
@ -708,8 +708,8 @@ class Article extends BaseController
} }
//根据个人村id进行查询 //根据个人村id进行查询
if (JWT_UID) { if ($this->request->uid) {
$find = Db::table('fa_szxc_information_useraddress')->where('user_id', JWT_UID)->find(); $find = Db::table('fa_szxc_information_useraddress')->where('user_id', $this->request->uid)->find();
if ($find) { if ($find) {
if ($find['auth_range']==1){ if ($find['auth_range']==1){
$where[] = ['village', '=', $find['village_id']]; $where[] = ['village', '=', $find['village_id']];
@ -721,7 +721,7 @@ class Article extends BaseController
} }
// 登录返回村名和村地址 // 登录返回村名和村地址
$cun_arr['cun_name'] = Db::table('fa_geo_village')->where('village_id', $find['village_id'])->value('village_name'); $cun_arr['cun_name'] = Db::table('fa_geo_village')->where('village_id', $find['village_id'])->value('village_name');
$cun_arr['cun_address'] = Db::table('fa_szxc_information_usermsg')->where('user_id', JWT_UID)->value('address_name'); $cun_arr['cun_address'] = Db::table('fa_szxc_information_usermsg')->where('user_id', $this->request->uid)->value('address_name');
}else{ }else{
$cun_arr = []; $cun_arr = [];
} }

View File

@ -30,8 +30,8 @@ class User extends BaseController
*/ */
public function index() public function index()
{ {
$user = Db::table('fa_user')->where('id',JWT_UID)->find(); $user = Db::table('fa_user')->where('id', $this->request->uid)->find();
$user_msg = Db::table('fa_szxc_information_usermsg')->where('user_id',JWT_UID)->field('id,name,address_name,phone')->find(); $user_msg = Db::table('fa_szxc_information_usermsg')->where('user_id', $this->request->uid)->field('id,name,address_name,phone')->find();
$this->apiSuccess('', [ $this->apiSuccess('', [
'nickname' => $user['nickname'], 'nickname' => $user['nickname'],
'phone'=>$user_msg['phone'], 'phone'=>$user_msg['phone'],
@ -472,7 +472,7 @@ class User extends BaseController
// 获取实名认证信息 // 获取实名认证信息
public function get_shiming(){ public function get_shiming(){
$uid = JWT_UID; $uid = $this->request->uid;
$is_have = Db::table('cms_szxc_user_authentication')->where('user_id',$uid)->find(); $is_have = Db::table('cms_szxc_user_authentication')->where('user_id',$uid)->find();
if($is_have){ if($is_have){
$this->apiSuccess('获取成功',$is_have); $this->apiSuccess('获取成功',$is_have);
@ -483,7 +483,7 @@ class User extends BaseController
// 获取后台账号信息 // 获取后台账号信息
public function get_backstage(){ public function get_backstage(){
$uid = JWT_UID; $uid = $this->request->uid;
$admin = Db::table('cms_admin')->where('user_id',$uid)->find(); $admin = Db::table('cms_admin')->where('user_id',$uid)->find();
if($admin){ if($admin){
$data['url'] = 'https://nk.lihaink.cn'; $data['url'] = 'https://nk.lihaink.cn';

View File

@ -94,16 +94,17 @@ class Userinfo extends BaseController
public function Binding() public function Binding()
{ {
$post = get_params(); $post = get_params();
if(!$post['idcard'] || !$post['area_id'] || !$post['street_id'] || !$post['village_id'] || !$post['name']){ if(!$post['idcard'] || !$post['area_id'] || !$post['street_id'] || !$post['village_id'] || !$post['name']){
$this->apiError('缺少参数'); $this->apiError('缺少参数');
} }
if($post['phone'] == 'undefined'){ if($post['phone'] == 'undefined'){
$this->apiError('手机号错误'); $this->apiError('手机号错误');
} }
$where['id'] = $this->request->uid; $where['id'] = $this->request->uid;
$post['user_id'] = $this->request->uid; $post['user_id'] = $this->request->uid;
$user = Db::table('fa_user')->where($where)->field('id,nickname,group_id,mobile,avatar,username,createtime,score')->find(); $user = Db::table('fa_user')->where($where)->field('id,nickname,group_id,mobile,avatar,username,createtime,score')->find();
// 已绑定 // 已绑定
if ($user) { if ($user) {
Db::startTrans(); Db::startTrans();

View File

@ -664,7 +664,7 @@ class Village extends BaseController
}) })
->withAttr('is_dz', function ($value, $data) { ->withAttr('is_dz', function ($value, $data) {
// 判断redis // 判断redis
$user_id = JWT_UID; $user_id = $this->request->uid;
if($user_id){ if($user_id){
$name = $user_id . $data['id']; $name = $user_id . $data['id'];
$is_zan = Cache::store('redis')->get($name); $is_zan = Cache::store('redis')->get($name);

View File

@ -6,4 +6,6 @@ return [
//验证勾股cms是否完成安装 //验证勾股cms是否完成安装
\app\home\middleware\Install::class, \app\home\middleware\Install::class,
\app\api\middleware\AllowOriginMiddleware::class, \app\api\middleware\AllowOriginMiddleware::class,
\app\api\middleware\Auth::class,
]; ];

View File

@ -27,6 +27,7 @@ class Auth
if (count(explode('.', $token)) != 3) { if (count(explode('.', $token)) != 3) {
return json(['code'=>404,'msg'=>'非法请求']); return json(['code'=>404,'msg'=>'非法请求']);
} }
try { try {
JWT::$leeway = 60;//当前时间减去60把时间留点余地 JWT::$leeway = 60;//当前时间减去60把时间留点余地
$decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应 $decoded = JWT::decode($token, new Key('ae47e94a7dcd1fdfacb499b60e361a8d', 'HS256')); //HS256方式这里要和签发的时候对应