diff --git a/modules/apihelper/client/components/authclient.py b/modules/apihelper/client/components/authclient.py index af30fc8f..f3933f85 100644 --- a/modules/apihelper/client/components/authclient.py +++ b/modules/apihelper/client/components/authclient.py @@ -34,9 +34,6 @@ class AuthClient: QRCODE_GET_API = f"https://{HK4E_SDK_HOST}/hk4e_cn/combo/panda/qrcode/query" GET_COOKIE_ACCOUNT_BY_GAME_TOKEN_API = f"https://{TAKUMI_HOST}/auth/api/getCookieAccountInfoByGameToken" GET_TOKEN_BY_GAME_LTOKEN_API = f"https://{PASSPORT_HOST}/account/ma-cn-session/app/getTokenByGameToken" - GET_COOKIES_TOKEN_BY_STOKEN_API = f"https://{PASSPORT_HOST}/account/auth/api/getCookieAccountInfoBySToken" - GET_LTOKEN_BY_STOKEN_API = f"https://{PASSPORT_HOST}/account/auth/api/getLTokenBySToken" - get_STOKEN_URL = f"https://{TAKUMI_HOST}/auth/api/getMultiTokenByLoginTicket" def __init__( self, @@ -60,24 +57,6 @@ class AuthClient: else: self.user_id = self.cookies.user_id - async def get_stoken_by_login_ticket(self) -> bool: - if self.cookies.login_ticket is None and self.user_id is None: - return False - params = {"login_ticket": self.cookies.login_ticket, "uid": self.user_id, "token_types": 3} - data = await self.client.get(self.get_STOKEN_URL, params=params, headers={"User-Agent": self.USER_AGENT}) - res_json = data.json() - res_data = res_json.get("data", {}).get("list", []) - for i in res_data: - name = i.get("name") - token = i.get("token") - if name and token and hasattr(self.cookies, name): - setattr(self.cookies, name, token) - if self.cookies.stoken: - if self.cookies.stuid: - self.cookies.stuid = self.user_id - return True - return False - async def get_ltoken_by_game_token(self, game_token: str) -> bool: if self.user_id is None: return False @@ -154,68 +133,6 @@ class AuthClient: if res_data.get("stat", "") == "Confirmed": return await self._set_cookie_by_game_token(res_json.get("data", {})) - async def get_cookie_token_by_stoken(self) -> bool: - if self.cookies.stoken is None: - return False - user_id = self.cookies.user_id - headers = { - "x-rpc-app_version": "2.11.1", - "User-Agent": ( - "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) " - "AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1" - ), - "x-rpc-client_type": "5", - "Referer": "https://webstatic.mihoyo.com/", - "Origin": "https://webstatic.mihoyo.com", - } - params = { - "stoken": self.cookies.stoken, - "uid": user_id, - } - res = await self.client.get( - self.GET_COOKIES_TOKEN_BY_STOKEN_API, - headers=headers, - params=params, - ) - res_json = res.json() - cookie_token = res_json.get("data", {}).get("cookie_token", "") - if cookie_token: - self.cookies.cookie_token = cookie_token - self.cookies.account_id = user_id - return True - return False - - async def get_ltoken_by_stoken(self) -> bool: - if self.cookies.stoken is None: - return False - user_id = self.cookies.user_id - headers = { - "x-rpc-app_version": "2.11.1", - "User-Agent": ( - "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) " - "AppleWebKit/605.1.15 (KHTML, like Gecko) miHoYoBBS/2.11.1" - ), - "x-rpc-client_type": "5", - "Referer": "https://webstatic.mihoyo.com/", - "Origin": "https://webstatic.mihoyo.com", - } - params = { - "stoken": self.cookies.stoken, - "uid": user_id, - } - res = await self.client.get( - self.GET_LTOKEN_BY_STOKEN_API, - headers=headers, - params=params, - ) - res_json = res.json() - ltoken = res_json.get("data", {}).get("ltoken", "") - if ltoken: - self.cookies.ltoken = ltoken - self.cookies.ltuid = user_id - return True - return False - @staticmethod def generate_qrcode(url: str) -> bytes: qr = qrcode.QRCode(version=1, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4) diff --git a/plugins/account/cookies.py b/plugins/account/cookies.py index 5212abc3..64bc6961 100644 --- a/plugins/account/cookies.py +++ b/plugins/account/cookies.py @@ -226,8 +226,8 @@ class AccountCookiesPlugin(Plugin.Conversation): if cookies.login_ticket is not None: try: cookies.cookie_token = await client.get_cookie_token_by_login_ticket() - cookies.account_id = cookies.account_id - cookies.ltuid = cookies.account_id + cookies.account_id = client.account_id + cookies.ltuid = client.account_id logger.success("用户 %s[%s] 绑定时获取 cookie_token 成功", user.full_name, user.id) cookies.stoken = await client.get_stoken_by_login_ticket() logger.success("用户 %s[%s] 绑定时获取 stoken 成功", user.full_name, user.id) @@ -246,14 +246,11 @@ class AccountCookiesPlugin(Plugin.Conversation): try: if client.account_id is None and cookies.is_v2: logger.info("检测到用户 %s[%s] 使用 V2 Cookie 正在尝试获取 account_id", user.full_name, user.id) - if client.region == Region.CHINESE: - account_info = await client.get_user_info() - account_id = account_info.accident_id - account_cookies_plugin_data.account_id = account_id - cookies.set_v2_uid(account_id) - logger.success("获取用户 %s[%s] account_id[%s] 成功", user.full_name, user.id, account_id) - else: - logger.warning("用户 %s[%s] region[%s] 也许是不正确的", user.full_name, user.id, client.region.name) + account_info = await client.get_user_info() + account_id = account_info.accident_id + account_cookies_plugin_data.account_id = account_id + cookies.set_v2_uid(account_id) + logger.success("获取用户 %s[%s] account_id[%s] 成功", user.full_name, user.id, account_id) else: account_cookies_plugin_data.account_id = client.account_id genshin_accounts = await client.get_genshin_accounts() diff --git a/plugins/account/players.py b/plugins/account/players.py index eba0db54..1710338b 100644 --- a/plugins/account/players.py +++ b/plugins/account/players.py @@ -2,6 +2,7 @@ import html from http.cookies import SimpleCookie from typing import Tuple, TYPE_CHECKING +from simnet import Region, GenshinClient from telegram import InlineKeyboardMarkup, InlineKeyboardButton from telegram.ext import filters @@ -10,7 +11,6 @@ from core.plugin import Plugin, handler from core.services.cookies import CookiesService from core.services.players import PlayersService from core.services.players.services import PlayerInfoService -from modules.apihelper.client.components.authclient import AuthClient from modules.apihelper.models.genshin.cookies import CookiesModel from utils.log import logger @@ -211,12 +211,13 @@ class PlayersManagesPlugin(Plugin): if cookies.stoken is not None: try: - auth_client = AuthClient(cookies=cookies) - if await auth_client.get_cookie_token_by_stoken(): + region = Region.CHINESE if player.region.value == 1 else Region.OVERSEAS + async with GenshinClient(cookies=cookies.to_dict(), region=region) as client: + cookies.cookie_token = await client.get_cookie_token_by_stoken() logger.success("用户 %s[%s] 刷新 cookie_token 成功", user.full_name, user.id) - if await auth_client.get_ltoken_by_stoken(): - logger.success("用户 %s[%s] 刷新 ltoken 成功", user.full_name, user.id) - auth_client.cookies.remove_v2() + cookies.ltoken = await client.get_ltoken_by_stoken() + logger.success("用户 %s[%s] 刷新 ltoken 成功", user.full_name, user.id) + cookies.remove_v2() except Exception as exc: # pylint: disable=W0703 logger.error("刷新 cookie_token 失败 [%s]", (str(exc))) await callback_query.edit_message_text( diff --git a/plugins/tools/genshin.py b/plugins/tools/genshin.py index 0a69c209..2fd9dde9 100644 --- a/plugins/tools/genshin.py +++ b/plugins/tools/genshin.py @@ -311,7 +311,7 @@ class GenshinHelper(Plugin): device_fp = devices.device_fp async with GenshinClient( - cookies, + cookies.data, region=game_region, account_id=player.account_id, player_id=uid,