@@ -92,6 +92,9 @@ class ChainResult(BaseModel):
9292 }
9393 }
9494
95+ class WechatOAuthResponse (BaseModel ):
96+ url : str
97+
9598 class MaimaiRoutes :
9699 _client : MaimaiClient
97100 _with_curves : bool
@@ -125,8 +128,8 @@ def _dep_arcade_player(self, credentials: str):
125128
126129 def _dep_wechat_player (
127130 self ,
128- t : str = Query (..., alias = "_t" , description = "_t in cookies " ),
129- user_id : str = Query (..., alias = "userId" , description = "userId in cookies " ),
131+ t : str = Query (..., alias = "_t" , description = "_t in returned credentials dict " ),
132+ user_id : str = Query (..., alias = "userId" , description = "userId in returned credentials dict " ),
130133 ):
131134 return PlayerIdentifier (credentials = Cookies ({"_t" : t , "userId" : user_id }))
132135
@@ -476,6 +479,30 @@ def _callback(to: dict, scores: MaimaiScores, err: BaseException | None, kwargs:
476479
477480 return router
478481
482+ def get_utils_route (self ) -> APIRouter :
483+ """Get a FastAPI APIRouter with routes for utility functions.
484+
485+ Returns:
486+ APIRouter: A FastAPI APIRouter with utility routes.
487+ """
488+ router = APIRouter ()
489+
490+ async def _get_wechat_oauth () -> WechatOAuthResponse :
491+ auth_url = await self ._client .wechat ()
492+ assert isinstance (auth_url , str )
493+ return WechatOAuthResponse (url = auth_url )
494+
495+ router .add_api_route (
496+ "/wechat_oauth" ,
497+ _get_wechat_oauth ,
498+ name = "get_wechat_oauth" ,
499+ methods = ["GET" ],
500+ response_model = WechatOAuthResponse ,
501+ description = f"Get wechat offiaccount oauth2 auth url with protocal modified redirect_url (https to http)." ,
502+ )
503+
504+ return router
505+
479506
480507if all ([find_spec (p ) for p in ["fastapi" , "uvicorn" , "typer" ]]):
481508 import typer
@@ -522,6 +549,9 @@ async def lifespan(app: FastAPI):
522549 tags = ["utils" ],
523550 )
524551
552+ # other utils routes
553+ asgi_app .include_router (routes .get_utils_route (), prefix = "/utils" , tags = ["utils" ])
554+
525555 def main (
526556 host : Annotated [str , typer .Option (help = "The host address to bind to." )] = "127.0.0.1" ,
527557 port : Annotated [int , typer .Option (help = "The port number to bind to." )] = 8000 ,
0 commit comments