🎨 Update get_ua function for requests

This commit is contained in:
洛水居室 2022-11-14 14:13:22 +08:00
parent 3b9596c6af
commit e96da60d0c
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
3 changed files with 7 additions and 10 deletions

View File

@ -83,7 +83,7 @@ def get_recognize_server(uid: int) -> str:
raise TypeError(f"UID {uid} isn't associated with any recognize server") 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 ( return (
f"Mozilla/5.0 (Linux; Android 12; {device}; wv) " 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 " "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/103.0.5060.129 Mobile Safari/537.36 "

View File

@ -13,7 +13,7 @@ from httpx import AsyncClient
from pydantic import BaseModel, validator from pydantic import BaseModel, validator
from modules.apihelper.base import ArtworkImage, PostInfo 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 modules.apihelper.request.hoyorequest import HOYORequest
from utils.typedefs import JSONDict from utils.typedefs import JSONDict
@ -366,11 +366,7 @@ class Verification:
VERIFY_VERIFICATION_URL = "/game_record/app/card/wapi/verifyVerification" VERIFY_VERIFICATION_URL = "/game_record/app/card/wapi/verifyVerification"
AJAX_URL = "/ajax.php" AJAX_URL = "/ajax.php"
USER_AGENT = ( USER_AGENT = get_ua()
"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"
)
BBS_HEADERS = { BBS_HEADERS = {
"Accept": "application/json, text/plain, */*", "Accept": "application/json, text/plain, */*",
"Accept-Encoding": "gzip, deflate", "Accept-Encoding": "gzip, deflate",

View File

@ -7,7 +7,7 @@ from genshin import constants, types
from genshin.client import routes from genshin.client import routes
from genshin.utility import ds 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 from utils.patch.methods import patch, patchable
@ -80,11 +80,12 @@ class BaseClient:
} }
elif region == types.Region.CHINESE: elif region == types.Region.CHINESE:
_app_version, _client_type, _ds = get_ds(new_ds=True, data=data, params=params) _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 = { headers = {
"User-Agent": ua, "User-Agent": ua,
"X_Requested_With": "com.mihoyo.hoyolab", "X_Requested_With": "com.mihoyo.hoyolab",
"Referer": "https://webstatic-sea.hoyolab.com", "Referer": "https://webstatic-sea.hoyolab.com",
"x-rpc-device_id": get_device_id(ua),
"x-rpc-app_version": _app_version, "x-rpc-app_version": _app_version,
"x-rpc-client_type": _client_type, "x-rpc-client_type": _client_type,
"ds": _ds, "ds": _ds,