array( "api_token:{$sign}", "nick:{$nick}", "Content-Type: application/json" ) ); $result = Http::get($path, [], $headers); if($result['code'] != 200){ throw new \think\Exception($result['msg'], 400); } $res = json_decode($result['data'], true); if($res['resultCode'] != '00000000'){ throw new \think\Exception($res['resultMsg'], 400); } return $res['data']; } public function adminLogin($phone, $password){ $result = Admin::where('username', $phone)->where('is_deleted', 0)->find(); if($result){ if($result->status == 1){ throw new \think\Exception('用户已失效', 400); } if(password_verify($password, $result->password)){ unset($result->password); // 生成token $encrypt = array( 'lat' => config('jwt.lat'), 'nbf' => config('jwt.nbf'), 'exp' => config('jwt.exp'), 'user_id' => $result->id, 'role_ids' => $result->role_id, 'username' => $result->username, ); $token =JWT::encode($encrypt, config('jwt.key'), 'HS256'); $result->logintime = date('Y-m-d H:i:s'); $result->token = $token; $result->save(); $result = $result->toArray(); return $result; } } throw new \think\Exception('用户名或密码错误!', 400); } }