From 07601a4387cc565a85b23785e17c97cde0abcae2 Mon Sep 17 00:00:00 2001 From: luoshuijs Date: Wed, 17 Jan 2024 16:47:06 +0800 Subject: [PATCH] :sparkles: Add Get FP --- simnet/client/components/auth.py | 76 ++++++++++++++++++++++++++++++++ simnet/client/routes.py | 3 ++ simnet/utils/hex.py | 20 +++++++++ 3 files changed, 99 insertions(+) create mode 100644 simnet/utils/hex.py diff --git a/simnet/client/components/auth.py b/simnet/client/components/auth.py index 565e2f2..eecd78d 100644 --- a/simnet/client/components/auth.py +++ b/simnet/client/components/auth.py @@ -1,4 +1,5 @@ import json as jsonlib +import time from typing import Optional, Tuple, Union from simnet.client.base import BaseClient @@ -11,9 +12,11 @@ from simnet.client.routes import ( WEB_ACCOUNT_URL, QRCODE_URL, URL, + GET_FP_URL, ) from simnet.errors import RegionNotSupported from simnet.utils.enums import Region +from simnet.utils.hex import get_random_hex_string_of_length from simnet.utils.player import recognize_game_biz, recognize_server __all__ = ("AuthClient",) @@ -590,3 +593,76 @@ class AuthClient(BaseClient): "uid": account_id, } await self.request_lab(url, method="POST", headers=headers, data=data) + + async def get_fp( + self, + device_id: Optional[str] = None, + device_fp: Optional[str] = None, + extend_properties: Optional[dict] = None, + app_name: str = "bbs_cn", + platform: int = 2, + ) -> str: + """ + Get Device Fingerprint + + Args: + device_id (Optional[str]): Device ID, if not provided, use `get_device_id()`. + device_fp (Optional[int]): Device fingerprint, if not provided, use `get_device_fp()`. + extend_properties (Optional[dict]): Device extension information, + defaults to auto-generated if not provided. + app_name (str): APP name, defaults to "bbs_cn" if not provided. + platform (int): Device platform code, same as client_type in the DS algorithm. + + Returns: + str: The device fingerprint. + """ + seed_time = int(time.time() * 1000) + seed_id = get_random_hex_string_of_length(13) + if extend_properties is None: + model = get_random_hex_string_of_length(6) + extend_properties = { + "cpuType": "arm64-v8a", + "romCapacity": "512", + "productName": model, + "romRemain": "256", + "manufacturer": "XiaoMi", + "appMemory": "512", + "hostname": "dg02-pool03-kvm87", + "screenSize": "1080x1920", + "osVersion": "13", + "vendor": "中国移动", + "accelerometer": "1.4883357x7.1712894x6.2847486", + "buildTags": "release-keys", + "model": model, + "brand": "XiaoMi", + "oaid": "", + "hardware": "qcom", + "deviceType": "OP5913L1", + "devId": "REL", + "serialNumber": "unknown", + "buildTime": "1687848011000", + "buildUser": "root", + "ramCapacity": "469679", + "magnetometer": "20.081251x-27.487501x2.1937501", + "display": f"{model}_13.1.0.181(CN01)", + "ramRemain": "215344", + "deviceInfo": f"XiaoMi/{model}/OP5913L1:13/SKQ1.221119.001/T.118e6c7-5aa23-73911:user/release-keys", + "gyroscope": "0.030226856x0.014647375x0.010652636", + "vaid": "", + "buildType": "user", + "sdkVersion": "33", + "board": "taro", + } + ext_fields = jsonlib.dumps(extend_properties) + data = { + "app_name": app_name, + "device_fp": device_fp or self.get_device_fp(), + "device_id": device_id or self.get_device_fp(), + "ext_fields": ext_fields, + "platform": platform, + "seed_id": seed_id, + "seed_time": seed_time, + } + new_device_fp = await self.request_lab(GET_FP_URL, method="POST", data=data) + self.device_fp = new_device_fp + return new_device_fp diff --git a/simnet/client/routes.py b/simnet/client/routes.py index b0892ca..9a121ed 100644 --- a/simnet/client/routes.py +++ b/simnet/client/routes.py @@ -31,6 +31,7 @@ __all__ = ( "CODE_HOYOLAB_URL", "YSULOG_URL", "QRCODE_URL", + "GET_FP_URL", ) @@ -317,3 +318,5 @@ CODE_HOYOLAB_URL = GameRoute( ) QRCODE_URL = Route("https://hk4e-sdk.mihoyo.com/hk4e_cn/combo/panda/qrcode") + +GET_FP_URL = Route("https://public-data-api.mihoyo.com/device-fp/api/getFp") diff --git a/simnet/utils/hex.py b/simnet/utils/hex.py new file mode 100644 index 0000000..286f6f2 --- /dev/null +++ b/simnet/utils/hex.py @@ -0,0 +1,20 @@ +import random + + +__all__ = ("get_random_hex_string_of_length",) + + +def get_random_hex_string_of_length(length: int): + """ + Generate a random hexadecimal string of a specified length. + + This function creates a string consisting of randomly selected hexadecimal characters (0-9, a-f). + + Args: + length (int): The length of the hexadecimal string to be generated. + + Returns: + str: A string containing random hexadecimal characters of the given length. + """ + random_range = "0123456789abcdef" + return "".join(random.choice(random_range) for _ in range(length)) # nosec