From 0ca0739903ea1fbe6af37d479dc031212e604184 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 23 Dec 2022 23:44:40 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Update=20ds=20salt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/apihelper/client/components/signin.py | 14 +++++++------- modules/apihelper/utility/helpers.py | 9 +++------ plugins/genshin/cookies.py | 2 +- utils/genshin.py | 12 ++++++------ utils/patch/genshin.py | 6 +++--- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/modules/apihelper/client/components/signin.py b/modules/apihelper/client/components/signin.py index 8ee8fea6..d036a653 100644 --- a/modules/apihelper/client/components/signin.py +++ b/modules/apihelper/client/components/signin.py @@ -1,16 +1,15 @@ import asyncio import json import random +import qrcode + from io import BytesIO from string import ascii_letters, digits from typing import Dict - -import qrcode -from genshin.utility import generate_cn_dynamic_secret from httpx import AsyncClient from ...logger import logger -from ...utility.helpers import get_device_id +from ...utility.helpers import get_device_id, get_ds __all__ = ("SignIn",) @@ -66,8 +65,6 @@ class SignIn: async def get_ltoken_by_game_token(self, game_token: str): data = {"account_id": self.uid, "game_token": game_token} headers = { - "x-rpc-app_version": "2.41.2", - "DS": generate_cn_dynamic_secret(body=data, salt="osgT0DljLarYxgebPPHJFjdaxPfoiHGt"), "x-rpc-aigis": "", "Content-Type": "application/json", "Accept": "application/json", @@ -78,9 +75,12 @@ class SignIn: "x-rpc-device_name": "Chrome 108.0.0.0", "x-rpc-device_model": "Windows 10 64-bit", "x-rpc-app_id": "bll8iq97cem8", - "x-rpc-client_type": "4", "User-Agent": "okhttp/4.8.0", } + app_version, client_type, ds_sign = get_ds(new_ds=True, data=data) + headers["x-rpc-app_version"] = app_version + headers["x-rpc-client_type"] = client_type + headers["DS"] = ds_sign res = await self.client.post( self.GAME_LTOKEN_API, headers=headers, diff --git a/modules/apihelper/utility/helpers.py b/modules/apihelper/utility/helpers.py index 3da1f3c0..fa09674d 100644 --- a/modules/apihelper/utility/helpers.py +++ b/modules/apihelper/utility/helpers.py @@ -54,22 +54,19 @@ def get_ds(ds_type: str = None, new_ds: bool = False, data: Any = None, params: c = hex_digest(f"salt={salt}&t={t}&r={r}") return f"{t},{r},{c}" - app_version = "2.36.1" + app_version = "2.41.2" client_type = "5" - salt = "YVEIkzDFNHLeKXLxzqCA9TzxCpWwbIbk" + salt = "osgT0DljLarYxgebPPHJFjdaxPfoiHGt" ds = old() if ds_type in ("android", "2"): - app_version = "2.36.1" client_type = "2" - salt = "n0KjuIrKgLHh08LWSCYP0WXlVXaYvV64" + salt = "TsmyHpZg8gFAVKTtlPaL6YwMldzxZJxQ" ds = old() if ds_type == "android_new": - app_version = "2.36.1" client_type = "2" salt = "t0qEgfub6cvueAPgR5m9aQWWVciEer7v" ds = new() if new_ds: - app_version = "2.36.1" client_type = "5" salt = "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs" ds = new() diff --git a/plugins/genshin/cookies.py b/plugins/genshin/cookies.py index 03271258..f580e5fa 100644 --- a/plugins/genshin/cookies.py +++ b/plugins/genshin/cookies.py @@ -51,7 +51,7 @@ class SetUserCookies(Plugin.Conversation, BasePlugin.Conversation): cookies = {} v1_keys = ["ltoken", "ltuid", "login_uid", "cookie_token"] - v2_keys = ["ltoken_v2", "ltmid_v2", "account_mid_v2", "cookie_token", "cookie_token_v2", "login_ticket"] + v2_keys = ["ltoken_v2", "ltmid_v2", "account_mid_v2", "cookie_token_v2", "login_ticket", "stoken"] cookie_is_v1 = None diff --git a/utils/genshin.py b/utils/genshin.py index f60360ad..65d135c4 100644 --- a/utils/genshin.py +++ b/utils/genshin.py @@ -1,16 +1,14 @@ from typing import Optional from genshin import Client -from genshin.utility import recognize_genshin_server, generate_dynamic_secret +from genshin.utility import recognize_genshin_server -from modules.apihelper.utility.helpers import hex_digest +from modules.apihelper.utility.helpers import hex_digest, get_ds 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": "", @@ -34,7 +32,9 @@ async def get_authkey_by_stoken(client: Client) -> Optional[str]: 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 + app_version, client_type, ds_sign = get_ds() + headers["x-rpc-app_version"] = app_version + headers["x-rpc-client_type"] = client_type + headers["ds"] = ds_sign data = await client.cookie_manager.request(AUTHKEY_API, method="POST", json=json, headers=headers) return data.get("authkey") diff --git a/utils/patch/genshin.py b/utils/patch/genshin.py index 883931a6..885b96ea 100644 --- a/utils/patch/genshin.py +++ b/utils/patch/genshin.py @@ -204,13 +204,13 @@ class BaseClient: else: device_id = DEVICE_ID - ds_sign = generate_dynamic_secret("ulInCDohgEs557j0VsPDYnQaaz6KJcv5") - ua = get_ua(device="Paimon Build " + device_id[0:5], version="2.40.0") + app_version, _, ds_sign = get_ds() + ua = get_ua(device="Paimon Build " + device_id[0:5], version=app_version) add_headers = { "User-Agent": ua, "Referer": "https://www.miyoushe.com/ys/", "x-rpc-device_id": get_device_id(device_id), - "x-rpc-app_version": "2.40.0", + "x-rpc-app_version": app_version, "x-rpc-client_type": "4", "ds": ds_sign, }