Files
----/后端源码/yifan.action-ai.cn/app/api/v1/module_application/miniapp/controller.py

41 lines
1.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- 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="登录成功")