authService = new AuthService(); } /** * 微信小程序登录 * POST /note/v1/auth/wechat-login */ public function wechatLogin() { try { $data = $this->request->post(); validate([ 'code' => 'require', ], [ 'code.require' => '微信登录 code 不能为空', ])->check($data); $result = $this->authService->wechatLogin( (string) $data['code'], isset($data['nickname']) ? (string) $data['nickname'] : null, isset($data['avatar_url']) ? (string) $data['avatar_url'] : null ); return Response::success($result, '登录成功'); } catch (ValidateException $e) { return Response::error($e->getMessage(), 400); } catch (\Throwable $e) { return Response::error($e->getMessage(), $e->getCode() ?: 500); } } /** * 获取当前小程序用户信息 * GET /note/v1/auth/me */ public function me() { try { $result = $this->authService->getUserInfo($this->getCurrentNoteUserId()); return Response::success($result); } catch (\Throwable $e) { return Response::error($e->getMessage(), $e->getCode() ?: 500); } } }