diff --git a/modules/apihelper/helpers.py b/modules/apihelper/helpers.py index 72199b47..0098ee5d 100644 --- a/modules/apihelper/helpers.py +++ b/modules/apihelper/helpers.py @@ -83,9 +83,9 @@ def get_recognize_server(uid: int) -> str: raise TypeError(f"UID {uid} isn't associated with any recognize server") -def get_headers(device: str = "Paimon Build", version: str = "2.36.1"): +def get_ua(device: str = "Paimon Build", version: str = "2.36.1"): return ( f"Mozilla/5.0 (Linux; Android 12; {device}; wv) " "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36 " f"miHoYoBBS/{version}" - ) \ No newline at end of file + ) diff --git a/modules/apihelper/hyperion.py b/modules/apihelper/hyperion.py index 95b7bdf3..f6bac570 100644 --- a/modules/apihelper/hyperion.py +++ b/modules/apihelper/hyperion.py @@ -13,7 +13,7 @@ from httpx import AsyncClient from pydantic import BaseModel, validator from modules.apihelper.base import ArtworkImage, PostInfo -from modules.apihelper.helpers import get_device_id, get_ds +from modules.apihelper.helpers import get_device_id, get_ds, get_ua from modules.apihelper.request.hoyorequest import HOYORequest from utils.typedefs import JSONDict @@ -366,11 +366,7 @@ class Verification: VERIFY_VERIFICATION_URL = "/game_record/app/card/wapi/verifyVerification" AJAX_URL = "/ajax.php" - USER_AGENT = ( - "User-Agent: Mozilla/5.0 (Linux; Android 12; Mi 10 Build/SKQ1.211006.001; wv) " - "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36 " - "miHoYoBBS/2.36.1" - ) + USER_AGENT = get_ua() BBS_HEADERS = { "Accept": "application/json, text/plain, */*", "Accept-Encoding": "gzip, deflate", diff --git a/utils/patch/genshin.py b/utils/patch/genshin.py index 3de045bb..61740b51 100644 --- a/utils/patch/genshin.py +++ b/utils/patch/genshin.py @@ -7,7 +7,7 @@ from genshin import constants, types from genshin.client import routes from genshin.utility import ds -from modules.apihelper.helpers import get_ds, get_headers +from modules.apihelper.helpers import get_ds, get_ua, get_device_id from utils.patch.methods import patch, patchable @@ -80,11 +80,12 @@ class BaseClient: } elif region == types.Region.CHINESE: _app_version, _client_type, _ds = get_ds(new_ds=True, data=data, params=params) - ua = get_headers(version=_app_version) + ua = get_ua(version=_app_version) headers = { "User-Agent": ua, "X_Requested_With": "com.mihoyo.hoyolab", "Referer": "https://webstatic-sea.hoyolab.com", + "x-rpc-device_id": get_device_id(ua), "x-rpc-app_version": _app_version, "x-rpc-client_type": _client_type, "ds": _ds,