post =$this->request->post(); $vali = $this->validateToken(); if($vali['code']!=0){ error_show($vali['code'],$vali['message'])->send(); die(); } } /** * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function validateToken(){ $token = isset($this->post['token']) ? trim($this->post['token']) : ""; if($token==""){ return ["code"=>101,"message"=>"参数token不能为空"]; } $effetc = VerifyTokens($token); if(!empty($effetc) && $effetc['code']!=0) { return ["code"=>$effetc['code'],"message"=>$effetc['message']]; // return error_show($effetc['code'], $effetc['message']); } $this->uid=isset($effetc['data']['user']['id']) ?$effetc['data']['user']['id']:""; $this->uname=isset($effetc['data']['user']['nickname']) ?$effetc['data']['user']['nickname']:""; $role = Db::name("user_role")->where(["uid"=>$this->uid,"is_del"=>0])->find(); if($role['status']==0){ return ["code"=>101,"message"=>"账户已禁用"]; //return error_show(101,'账户已禁用'); } $this->roleid=$role['roleid']; return ["code"=>0,"message"=>"验证通过"]; } }