From 99a29305166c557b8c176c4febe691617dee2fc1 Mon Sep 17 00:00:00 2001 From: RBAmeto <46624927+RBAmeto@users.noreply.github.com> Date: Thu, 18 May 2023 19:21:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=E5=86=8D=E6=AC=A1=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=AA=8C=E8=AF=81=E7=A0=81=E9=97=AE=E9=A2=98=20(#37)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复验证码问题以及抽卡记录绘图重叠bug * 尝试修复验证码问题 * 尝试修复验证码问题 * 尝试修复验证码问题 * 🚨 `pre-commit-ci`修复格式错误 * 尝试修复验证码问题 * 🚨 `pre-commit-ci`修复格式错误 * 尝试修复验证码问题 * 尝试修复验证码问题 * 🚨 `pre-commit-ci`修复格式错误 * 该死的merge和pre-commit --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- StarRailUID/sruid_utils/api/mys/api.py | 2 +- StarRailUID/utils/mys_api.py | 53 +++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/StarRailUID/sruid_utils/api/mys/api.py b/StarRailUID/sruid_utils/api/mys/api.py index 2e30f27..e26141d 100644 --- a/StarRailUID/sruid_utils/api/mys/api.py +++ b/StarRailUID/sruid_utils/api/mys/api.py @@ -28,7 +28,7 @@ CHALLENGE_INFO_URL = f'{NEW_URL}/game_record/app/hkrpg/api/challenge' STAR_RAIL_GACHA_LOG_URL = f'{OLD_URL}/common/gacha_record/api/getGachaLog' - +GET_FP_URL = 'https://public-data-api.mihoyo.com/device-fp/api/getFp' # CREATE_QRCODE = f'{OLD_URL}/event/bbs_sign_reward/gen_auth_code' _API = locals() diff --git a/StarRailUID/utils/mys_api.py b/StarRailUID/utils/mys_api.py index 70027c6..6cc2a70 100644 --- a/StarRailUID/utils/mys_api.py +++ b/StarRailUID/utils/mys_api.py @@ -2,6 +2,7 @@ import copy import time import uuid import random +import asyncio from string import digits, ascii_letters from typing import Dict, Union, Optional, cast @@ -37,10 +38,12 @@ RECOGNIZE_SERVER = { class MysApi(_MysApi): + device_id = uuid.uuid4().hex + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - self._HEADER['x-rpc-device_id'] = uuid.uuid4().hex - self._HEADER['x-rpc-device_fp'] = random_hex(14) + asyncio.run(self.get_fp()) + self._HEADER['x-rpc-device_id'] = self.device_id self._HEADER['x-rpc-page'] = '3.1.3_#/rpg' async def create_qrcode_url(self) -> Union[Dict, int]: @@ -215,7 +218,6 @@ class MysApi(_MysApi): if int(str(uid)[0]) < 6: HEADER = copy.deepcopy(self._HEADER) HEADER['Cookie'] = ck - HEADER['x-rpc-device_id'] = random_hex(32) HEADER['x-rpc-app_version'] = '2.44.1' HEADER['x-rpc-client_type'] = '5' HEADER['X_Requested_With'] = 'com.mihoyo.hyperion' @@ -248,7 +250,6 @@ class MysApi(_MysApi): HEADER = copy.deepcopy(self._HEADER) HEADER['Cookie'] = ck HEADER['DS'] = get_web_ds_token(True) - HEADER['x-rpc-device_id'] = random_hex(32) data = await self._mys_request( url=_API['STAR_RAIL_MONTH_INFO_URL'], method='GET', @@ -258,7 +259,6 @@ class MysApi(_MysApi): else: HEADER = copy.deepcopy(self._HEADER_OS) HEADER['Cookie'] = ck - HEADER['x-rpc-device_id'] = random_hex(32) HEADER['DS'] = generate_os_ds() data = await self._mys_request( url=_API['STAR_RAIL_MONTH_INFO_URL'], @@ -281,6 +281,49 @@ class MysApi(_MysApi): data = cast(RoleBasicInfo, data['data']) return data + def generate_seed(self, length: int): + characters = '0123456789abcdef' + result = ''.join(random.choices(characters, k=length)) + return result + + async def get_fp(self): + seed_id = self.generate_seed(16) + seed_time = str(int(time.time() * 1000)) + ext_fields = f'{{"userAgent":"{self._HEADER["User-Agent"]}",\ +"browserScreenSize":281520,"maxTouchPoints":5,\ +"isTouchSupported":true,"browserLanguage":"zh-CN","browserPlat":"iPhone",\ +"browserTimeZone":"Asia/Shanghai","webGlRender":"Apple GPU",\ +"webGlVendor":"Apple Inc.",\ +"numOfPlugins":0,"listOfPlugins":"unknown","screenRatio":3,"deviceMemory":"unknown",\ +"hardwareConcurrency":"4","cpuClass":"unknown","ifNotTrack":"unknown","ifAdBlock":0,\ +"hasLiedResolution":1,"hasLiedOs":0,"hasLiedBrowser":0}}' + body = { + 'seed_id': seed_id, + 'device_id': self.device_id, + 'platform': '5', + 'seed_time': seed_time, + 'ext_fields': ext_fields, + 'app_name': 'account_cn', + 'device_fp': '38d7ee834d1e9', + } + HEADER = copy.deepcopy(self._HEADER) + res = await self._mys_request( + url=_API['GET_FP_URL'], + method='POST', + header=HEADER, + data=body, + ) + if res["retcode"] != 0: + print("获取fp连接失败") + print(res) + self._HEADER['x-rpc-device_fp'] = random_hex(13).lower() + elif res["data"]["code"] != 200: + print("获取fp参数不正确") + print(res["data"]["msg"]) + self._HEADER['x-rpc-device_fp'] = random_hex(13).lower() + else: + self._HEADER['x-rpc-device_fp'] = res["data"]["device_fp"] + mys_api = MysApi() mys_api.dbsqla = srdbsqla