私域操盘手 - 修改隐藏错误 - 找到token但没有用户信息,尝试保持登录状态

This commit is contained in:
柳清爽
2025-05-08 15:56:07 +08:00
parent 250464de39
commit 8effb037dd
3 changed files with 24 additions and 22 deletions

View File

@@ -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 {
// 如果能解析用户数据,先设置登录状态

View File

@@ -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());
}
/**

View File

@@ -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);
}
}