项目基础模块代码

This commit is contained in:
2025-02-19 11:47:33 +08:00
parent 3cb2a4c507
commit 31302bcd17
30 changed files with 588 additions and 74 deletions

View File

@ -2,6 +2,7 @@ import datetime
import jwt
from app.common.redis_cli import redis_conn
from fastapi import Request
# 过期时间单位S
exp = 6000
@ -48,3 +49,11 @@ def check_token(token: str):
raise jwt.ExpiredSignatureError("Expired Token")
except jwt.InvalidTokenError:
raise jwt.InvalidTokenError("Invalid Token")
def get_user_id(request: Request):
"""根据Request请求获取token"""
token = request.headers.get("Authorization")
decoded_payload = check_token(token)
user_id = decoded_payload['user_id']
return user_id

View File

@ -12,6 +12,7 @@ def response_code_view(code: int,msg: str) -> Response:
}
)
def response_success(msg: str = "查询成功", data: object = None):
return JSONResponse(
status_code=status.HTTP_200_OK,
@ -35,7 +36,7 @@ def response_success_pager(pager: Pager):
)
def response_error(msg:str):
def response_error(msg: str):
return JSONResponse(
status_code=status.HTTP_200_OK,
content={