From 8effb037dd12eac653894af873fdcbcf4e1ef27d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Thu, 8 May 2025 15:56:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98=E6=89=8B?= =?UTF-8?q?=20-=20=E4=BF=AE=E6=94=B9=E9=9A=90=E8=97=8F=E9=94=99=E8=AF=AF?= =?UTF-8?q?=20-=20=E6=89=BE=E5=88=B0token=E4=BD=86=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BF=A1=E6=81=AF=EF=BC=8C=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BF=9D=E6=8C=81=E7=99=BB=E5=BD=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/components/AuthProvider.tsx | 2 +- .../device/GetRelatedAccountsV1Controller.php | 6 +-- Server/extend/library/ResponseHelper.php | 38 ++++++++++--------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/Cunkebao/app/components/AuthProvider.tsx b/Cunkebao/app/components/AuthProvider.tsx index ca09cfa5..fe5f9c4b 100644 --- a/Cunkebao/app/components/AuthProvider.tsx +++ b/Cunkebao/app/components/AuthProvider.tsx @@ -77,7 +77,7 @@ export function AuthProvider({ children }: AuthProviderProps) { if (storedToken) { // 首先尝试从localStorage获取用户信息 - const userDataStr = safeLocalStorage.getItem("user") + const userDataStr = safeLocalStorage.getItem("userInfo") if (userDataStr) { try { // 如果能解析用户数据,先设置登录状态 diff --git a/Server/application/cunkebao/controller/device/GetRelatedAccountsV1Controller.php b/Server/application/cunkebao/controller/device/GetRelatedAccountsV1Controller.php index f46e91e4..4bdd6e0f 100644 --- a/Server/application/cunkebao/controller/device/GetRelatedAccountsV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetRelatedAccountsV1Controller.php @@ -72,12 +72,12 @@ class GetRelatedAccountsV1Controller extends BaseController /** * 通过微信id获取微信最后活跃时间 * - * @param int $wechatId + * @param int $time * @return string */ - protected function getWechatLastActiveTime($wechatId): string + protected function getWechatLastActiveTime(int $time): string { - return date('Y-m-d H:i:s', $wechatId ?: time()); + return date('Y-m-d H:i:s', $time ?: time()); } /** diff --git a/Server/extend/library/ResponseHelper.php b/Server/extend/library/ResponseHelper.php index ab17eb45..256bdd9b 100644 --- a/Server/extend/library/ResponseHelper.php +++ b/Server/extend/library/ResponseHelper.php @@ -2,21 +2,23 @@ namespace library; +use think\response\Json as JsonResponse; + class ResponseHelper { /** * 成功响应 * - * @param mixed $data 响应数据 - * @param string $msg 响应消息 - * @param int $code 响应代码 - * @return \think\response\Json + * @param mixed $data + * @param string $msg + * @param int $code + * @return JsonResponse */ - public static function success($data = null, $msg = '操作成功', $code = 200) + public static function success($data = null, string $msg = 'success', int $code = 200): JsonResponse { return json([ 'code' => $code, - 'msg' => $msg, + 'msg' => $msg, 'data' => $data ]); } @@ -24,16 +26,16 @@ class ResponseHelper /** * 错误响应 * - * @param string $msg 错误消息 - * @param int $code 错误代码 - * @param mixed $data 错误数据 - * @return \think\response\Json + * @param string $msg + * @param int $code + * @param mixed $data + * @return JsonResponse */ - public static function error($msg = '操作失败', $code = 400, $data = []) + public static function error(string $msg = 'fail', int $code = 400, $data = []): JsonResponse { return json([ 'code' => $code, - 'msg' => $msg, + 'msg' => $msg, 'data' => $data ]); } @@ -42,21 +44,21 @@ class ResponseHelper * 未授权响应 * * @param string $msg 错误消息 - * @return \think\response\Json + * @return JsonResponse */ - public static function unauthorized($msg = '未授权访问') + public static function unauthorized(string $msg = 'unauthorized access'): JsonResponse { - return self::error($msg, 401); + return static::error($msg, 401); } /** * 禁止访问响应 * * @param string $msg 错误消息 - * @return \think\response\Json + * @return JsonResponse */ - public static function forbidden($msg = '禁止访问') + public static function forbidden(string $msg = 'access denied'): JsonResponse { - return self::error($msg, 403); + return static::error($msg, 403); } } \ No newline at end of file