From cf22949a8153cc99b22a9014489a23b56e8b49ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B0=B4=E5=B1=85=E5=AE=A4?= Date: Sun, 11 Dec 2022 13:50:03 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20unable=20to=20get=20AuthKe?= =?UTF-8?q?y?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/genshin.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/utils/genshin.py b/utils/genshin.py index 963fc87..f60360a 100644 --- a/utils/genshin.py +++ b/utils/genshin.py @@ -1,18 +1,40 @@ from typing import Optional from genshin import Client -from genshin.utility import recognize_genshin_server +from genshin.utility import recognize_genshin_server, generate_dynamic_secret + +from modules.apihelper.utility.helpers import hex_digest AUTHKEY_API = "https://api-takumi.mihoyo.com/binding/api/genAuthKey" +GACHA_HEADERS = { + "User-Agent": "okhttp/4.8.0", + "x-rpc-app_version": "2.28.1", + "x-rpc-sys_version": "12", + "x-rpc-client_type": "5", + "x-rpc-channel": "mihoyo", + "x-rpc-device_id": "", + "x-rpc-device_name": "", + "x-rpc-device_model": "", + "Referer": "https://app.mihoyo.com", + "Host": "api-takumi.mihoyo.com", +} async def get_authkey_by_stoken(client: Client) -> Optional[str]: """ι€šθΏ‡ stoken θŽ·ε– authkey""" + headers = GACHA_HEADERS.copy() json = { "auth_appid": "webview_gacha", "game_biz": "hk4e_cn", "game_uid": client.uid, "region": recognize_genshin_server(client.uid), } - data = await client.request_bbs(AUTHKEY_API, method="POST", data=json) + device_id = hex_digest(str(client.uid)) + headers["x-rpc-device_id"] = device_id + device = "Paimon Build " + device_id[0:5] + headers["x-rpc-device_name"] = device + headers["x-rpc-device_model"] = device + ds = generate_dynamic_secret("ulInCDohgEs557j0VsPDYnQaaz6KJcv5") + headers["ds"] = ds + data = await client.cookie_manager.request(AUTHKEY_API, method="POST", json=json, headers=headers) return data.get("authkey")