['except' => ['login','apidoc'] ], ]; use ResponseJson; /** * @Apidoc\Title("基础的接口演示") * @Apidoc\Tag("基础,示例") * @Apidoc\Author("ihavoc") * @Apidoc\Method ("GET") * @Route("/") * @Middleware({}) */ public function index() { return $this->JsonSucess(["info"=>"这是后端接口"]); } public function hello($name = 'ThinkPHP6') { return 'hello,' . $name; } /** * @Apidoc\Title("登录接口") * @Apidoc\Tag("用户登录") * @Apidoc\Author("ihavoc") * @Apidoc\Method ("POST") * @throws ModelNotFoundException * @throws DataNotFoundException * @throws DbException * @Route("login",method="POST") * @Middleware({}) */ public function login():Json{ $loginInfo = $this->request->post(); try { validate(UserLogin::class)->check($loginInfo); }catch (ValidateException $e){ return $this->JsonError($e->getError(),0); } $userInfo=UserService::selectLoginInfo($loginInfo); if ($userInfo){ $token = JWTAuth::builder(['xzqdm' => $userInfo["xzqdm"],'id'=>$userInfo["id"]]);//参数为用户认证的信息,请自行添加 return $this->JsonSucess(["token"=>$token,"userInfo"=>$userInfo],1001); }else{ return $this->JsonError(1002); } } /** * @throws ModelNotFoundException * @throws DataNotFoundException * @throws DbException * @Apidoc\Title("根据token获取用户信息") * @Apidoc\Tag("用户信息") * @Apidoc\Method ("POST") * @Apidoc\Author("ihavoc") * @Route("/getUserInfo",method="POST") * @Middleware({"jwt"}) */ public function getUserInfo(): Json { return $this->JsonSucess(UserService::getUserInfoById(getUserId())); } /** * @throws ModelNotFoundException * @throws DataNotFoundException * @throws DbException * @Apidoc\Title("修改密码") * @Apidoc\Tag("用户信息") * @Apidoc\Method ("POST") * @Apidoc\Author("ihavoc") * @Route("/editPassword",method="POST") * @Middleware({"jwt"}) */ public function editPassword():Json{ $rePassword = $this->request->post(); try { validate(RePassword::class)->check($rePassword); }catch (ValidateException $e){ return $this->JsonError($e->getError()); } return $this->JsonSucess(UserService::editPasswordById(getUserId(),$rePassword["password"])); }/** * @throws ModelNotFoundException * @throws DataNotFoundException * @throws DbException * @Apidoc\Title("修改用户信息") * @Apidoc\Tag("用户信息") * @Apidoc\Method ("POST") * @Apidoc\Author("ihavoc") * @Route("/editUserInfo",method="POST") * @Middleware({"jwt"}) */ public function editUserInfoById():Json{ $userInfo = $this->request->post(); try { validate(EditUserInfo::class)->check($userInfo); }catch (ValidateException $e){ return $this->JsonError($e->getError()); } return $this->JsonSucess(UserService::editUserInfoById(getUserId(),$userInfo)); } }