41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
||
|
||
from fastapi import APIRouter, Depends
|
||
from fastapi.responses import JSONResponse
|
||
from sqlalchemy.ext.asyncio import AsyncSession
|
||
from redis.asyncio.client import Redis
|
||
|
||
from app.common.response import SuccessResponse
|
||
from app.core.logger import log
|
||
from app.core.dependencies import db_getter, redis_getter
|
||
from app.api.v1.module_system.auth.schema import AuthSchema
|
||
|
||
from .service import MiniappService
|
||
from .schema import MiniappLoginSchema, MiniappLoginOutSchema
|
||
|
||
|
||
MiniappRouter = APIRouter(prefix="/miniapp", tags=["小程序"])
|
||
|
||
|
||
@MiniappRouter.post("/login", summary="小程序登录", description="微信小程序用户登录", response_model=MiniappLoginOutSchema)
|
||
async def miniapp_login_controller(
|
||
data: MiniappLoginSchema,
|
||
db: AsyncSession = Depends(db_getter),
|
||
redis: Redis = Depends(redis_getter),
|
||
) -> JSONResponse:
|
||
"""
|
||
小程序登录接口
|
||
|
||
前端调用 wx.login() 获取 code,传给此接口换取 token
|
||
|
||
参数:
|
||
- data (MiniappLoginSchema): 包含微信登录code
|
||
|
||
返回:
|
||
- MiniappLoginOutSchema: 包含access_token和用户信息
|
||
"""
|
||
auth = AuthSchema(db=db)
|
||
result = await MiniappService.login_service(auth=auth, redis=redis, data=data)
|
||
log.info(f"小程序用户登录成功")
|
||
return SuccessResponse(data=result, msg="登录成功")
|