diff --git a/app/common/middleware/ShopTokenMiddleware.php b/app/common/middleware/ShopTokenMiddleware.php index 4ccda6c..038dc24 100644 --- a/app/common/middleware/ShopTokenMiddleware.php +++ b/app/common/middleware/ShopTokenMiddleware.php @@ -32,13 +32,13 @@ class ShopTokenMiddleware extends BaseMiddleware{ $repository->checkToken($token); $payload = $service->decode($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]); - if (!$admin) throw new AuthException('账号不存在'); - if (!$admin['status']) throw new AuthException('账号已被禁用'); + if (!$admin) throw new ValidateException('账号不存在'); + if (!$admin['status']) throw new ValidateException('账号已被禁用'); /** * @var MerchantRepository $merchantRepository @@ -48,7 +48,7 @@ class ShopTokenMiddleware extends BaseMiddleware{ $merchant = $merchantRepository->get($admin->mer_id); if (!$merchant || !$merchant['status']) - throw new AuthException('商户已被锁定'); + throw new ValidateException('商户已被锁定'); } catch (Throwable $e) { if ($force) throw $e; @@ -56,7 +56,7 @@ class ShopTokenMiddleware extends BaseMiddleware{ return false; }); $request->macros(['merchantType', 'shopMerId'], function () { - throw new AuthException('请登录'); + throw new ValidateException('请登录'); }); return; } diff --git a/app/common/repositories/system/merchant/MerchantAdminRepository.php b/app/common/repositories/system/merchant/MerchantAdminRepository.php index 1e39884..dccf143 100644 --- a/app/common/repositories/system/merchant/MerchantAdminRepository.php +++ b/app/common/repositories/system/merchant/MerchantAdminRepository.php @@ -239,11 +239,9 @@ class MerchantAdminRepository extends BaseRepository public function checkToken(string $token) { $has = Cache::has('mer_' . $token); - if (!$has) - throw new AuthException('无效的token'); + if (!$has) throw new ValidateException('token 已经失效,请重新登录!'); $lastTime = Cache::get('mer_' . $token); - if (($lastTime + (intval(Config::get('admin.token_valid_exp', 15))) * 60) < time()) - throw new AuthException('token 已过期'); + if (($lastTime + (intval(Config::get('admin.token_valid_exp', 15))) * 60) < time()) throw new ValidateException('token 已过期'); } /** diff --git a/app/controller/api/store/merchant/Merchant.php b/app/controller/api/store/merchant/Merchant.php index dadf081..5b4d261 100644 --- a/app/controller/api/store/merchant/Merchant.php +++ b/app/controller/api/store/merchant/Merchant.php @@ -173,7 +173,7 @@ class Merchant extends BaseController return app('json')->success([ 'token' => $tokenInfo['token'], - 'exp' => $tokenInfo['out'], + 'exp' => $tokenInfo['exp'], 'mer_id' => $admin['mer_id'], 'merchant_type' => $admin['merchant_type'], 'mer_name' => $admin['mer_name'], diff --git a/config/admin.php b/config/admin.php index 370b968..31947d4 100644 --- a/config/admin.php +++ b/config/admin.php @@ -5,7 +5,7 @@ return [ //token 有效期 - 'token_exp' => 6, //6小时 + 'token_exp' => 24, //6小时 //token超时多久可自动续期(后台) 'token_valid_exp' => 30, //30分钟 //token超时多久可自动续期(用户)