diff --git a/genshin/client/manager/cookie.py b/genshin/client/manager/cookie.py index ef3af82e..2ee60d5b 100644 --- a/genshin/client/manager/cookie.py +++ b/genshin/client/manager/cookie.py @@ -14,6 +14,8 @@ - fetch_cookie_with_stoken_v2 - stoken (v2) + mid -> ltoken_v2 (token_type=2) - stoken (v2) + mid -> cookie_token_v2 (token_type=4) +- cn_fetch_cookie_token_with_stoken_v2 + - stoken (v2) + mid -> cookie_token - fetch_cookie_token_with_game_token - game_token -> cookie_token - fetch_stoken_with_game_token @@ -37,6 +39,7 @@ from genshin.utility import ds as ds_utility __all__ = [ + "cn_fetch_cookie_token_with_stoken_v2", "complete_cookies", "fetch_cookie_token_info", "fetch_cookie_token_with_game_token", @@ -116,6 +119,27 @@ async def fetch_cookie_with_stoken_v2( return cookies +async def cn_fetch_cookie_token_with_stoken_v2( + cookies: managers.CookieOrHeader, +) -> typing.Mapping[typing.Literal["uid", "cookie_token"], str]: + """Fetch cookie_token with an stoken (v2) and mid.""" + cookies = managers.parse_cookie(cookies) + url = routes.CN_GET_COOKIE_TOKEN_BY_STOKEN_URL.get_url() + + headers = { + "ds": ds_utility.generate_dynamic_secret(constants.DS_SALT["app_login"]), + "x-rpc-app_id": "bll8iq97cem8", + } + async with aiohttp.ClientSession() as session: + r = await session.request("GET", url, headers=headers, cookies=cookies) + data = await r.json() + + if data["retcode"] != 0: + errors.raise_for_retcode(data) + + return data["data"] + + async def fetch_cookie_token_info( cookies: managers.CookieOrHeader, *, diff --git a/genshin/client/routes.py b/genshin/client/routes.py index 5bea27ff..566ef4aa 100644 --- a/genshin/client/routes.py +++ b/genshin/client/routes.py @@ -247,6 +247,9 @@ def get_url(self, region: types.Region, game: types.Game) -> yarl.URL: COOKIE_V2_REFRESH_URL = Route("https://sg-public-api.hoyoverse.com/account/ma-passport/token/getBySToken") GET_COOKIE_TOKEN_BY_GAME_TOKEN_URL = Route("https://api-takumi.mihoyo.com/auth/api/getCookieAccountInfoByGameToken") GET_STOKEN_BY_GAME_TOKEN_URL = Route("https://passport-api.mihoyo.com/account/ma-cn-session/app/getTokenByGameToken") +CN_GET_COOKIE_TOKEN_BY_STOKEN_URL = Route( + "https://passport-api.mihoyo.com/account/auth/api/getCookieAccountInfoBySToken" +) WEB_LOGIN_URL = Route("https://sg-public-api.hoyolab.com/account/ma-passport/api/webLoginByPassword") APP_LOGIN_URL = Route("https://sg-public-api.hoyoverse.com/account/ma-passport/api/appLoginByPassword")