修复:酒道馆token过期后未正常处理,导致用户登录状态也被删除了。

This commit is contained in:
wuhui_zzw 2024-03-13 12:02:11 +08:00
parent 1310ea97b1
commit 045fb46855
4 changed files with 10 additions and 12 deletions

View File

@ -32,13 +32,13 @@ class ShopTokenMiddleware extends BaseMiddleware{
$repository->checkToken($token); $repository->checkToken($token);
$payload = $service->decode($token); $payload = $service->decode($token);
} catch (Throwable $e) {//Token 过期 } catch (Throwable $e) {//Token 过期
throw new AuthException('token 已过期'); throw new ValidateException('token 已过期');
} }
if ('mer' != $payload->jti[1]) throw new AuthException('无效的 token'); if ('mer' != $payload->jti[1]) throw new ValidateException('无效的 token');
$admin = $repository->get($payload->jti[0]); $admin = $repository->get($payload->jti[0]);
if (!$admin) throw new AuthException('账号不存在'); if (!$admin) throw new ValidateException('账号不存在');
if (!$admin['status']) throw new AuthException('账号已被禁用'); if (!$admin['status']) throw new ValidateException('账号已被禁用');
/** /**
* @var MerchantRepository $merchantRepository * @var MerchantRepository $merchantRepository
@ -48,7 +48,7 @@ class ShopTokenMiddleware extends BaseMiddleware{
$merchant = $merchantRepository->get($admin->mer_id); $merchant = $merchantRepository->get($admin->mer_id);
if (!$merchant || !$merchant['status']) if (!$merchant || !$merchant['status'])
throw new AuthException('商户已被锁定'); throw new ValidateException('商户已被锁定');
} catch (Throwable $e) { } catch (Throwable $e) {
if ($force) throw $e; if ($force) throw $e;
@ -56,7 +56,7 @@ class ShopTokenMiddleware extends BaseMiddleware{
return false; return false;
}); });
$request->macros(['merchantType', 'shopMerId'], function () { $request->macros(['merchantType', 'shopMerId'], function () {
throw new AuthException('请登录'); throw new ValidateException('请登录');
}); });
return; return;
} }

View File

@ -239,11 +239,9 @@ class MerchantAdminRepository extends BaseRepository
public function checkToken(string $token) public function checkToken(string $token)
{ {
$has = Cache::has('mer_' . $token); $has = Cache::has('mer_' . $token);
if (!$has) if (!$has) throw new ValidateException('token 已经失效,请重新登录!');
throw new AuthException('无效的token');
$lastTime = Cache::get('mer_' . $token); $lastTime = Cache::get('mer_' . $token);
if (($lastTime + (intval(Config::get('admin.token_valid_exp', 15))) * 60) < time()) if (($lastTime + (intval(Config::get('admin.token_valid_exp', 15))) * 60) < time()) throw new ValidateException('token 已过期');
throw new AuthException('token 已过期');
} }
/** /**

View File

@ -173,7 +173,7 @@ class Merchant extends BaseController
return app('json')->success([ return app('json')->success([
'token' => $tokenInfo['token'], 'token' => $tokenInfo['token'],
'exp' => $tokenInfo['out'], 'exp' => $tokenInfo['exp'],
'mer_id' => $admin['mer_id'], 'mer_id' => $admin['mer_id'],
'merchant_type' => $admin['merchant_type'], 'merchant_type' => $admin['merchant_type'],
'mer_name' => $admin['mer_name'], 'mer_name' => $admin['mer_name'],

View File

@ -5,7 +5,7 @@
return [ return [
//token 有效期 //token 有效期
'token_exp' => 6, //6小时 'token_exp' => 24, //6小时
//token超时多久可自动续期(后台) //token超时多久可自动续期(后台)
'token_valid_exp' => 30, //30分钟 'token_valid_exp' => 30, //30分钟
//token超时多久可自动续期(用户) //token超时多久可自动续期(用户)