feat : jwt

This commit is contained in:
2025-09-15 09:32:15 +08:00
parent 1d01ecfdcb
commit 8665b27294
3 changed files with 42 additions and 38 deletions

View File

@@ -4,6 +4,8 @@ declare(strict_types=1);
namespace App\Middleware\Token;
use App\Constants\ResultCode;
use App\Exception\ErrException;
use App\Interface\CheckTokenInterface;
use App\Interface\JwtInterface;
use App\Lib\Jwt\JwtFactory;
@@ -11,6 +13,7 @@ use Hyperf\Collection\Arr;
use Hyperf\Stringable\Str;
use Lcobucci\JWT\Token;
use Lcobucci\JWT\UnencryptedToken;
use Lcobucci\JWT\Validation\RequiredConstraintsViolated;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
@@ -57,7 +60,11 @@ abstract class AbstractTokenMiddleware
*/
protected function parserToken(ServerRequestInterface $request): Token
{
return $this->getJwt()->parserAccessToken($this->getToken($request));
try {
return $this->getJwt()->parserAccessToken($this->getToken($request));
} catch (RequiredConstraintsViolated $e) {
throw new ErrException('token过期',ResultCode::JWT_EXPIRED,['err_msg' => $e->getMessage()]);
}
}
/**