2022-07-26 10:07:31 +00:00
|
|
|
import hashlib
|
2022-11-12 12:59:42 +00:00
|
|
|
import json
|
2022-07-26 10:07:31 +00:00
|
|
|
import random
|
|
|
|
import string
|
|
|
|
import time
|
|
|
|
import uuid
|
2022-11-14 07:47:44 +00:00
|
|
|
from typing import Mapping, Any, Optional
|
2022-07-26 10:07:31 +00:00
|
|
|
|
2022-12-10 12:37:43 +00:00
|
|
|
__all__ = ("get_device_id", "hex_digest", "get_ds", "get_recognize_server", "get_ua")
|
|
|
|
|
2022-07-26 10:07:31 +00:00
|
|
|
RECOGNIZE_SERVER = {
|
|
|
|
"1": "cn_gf01",
|
|
|
|
"2": "cn_gf01",
|
|
|
|
"5": "cn_qd01",
|
|
|
|
"6": "os_usa",
|
|
|
|
"7": "os_euro",
|
|
|
|
"8": "os_asia",
|
|
|
|
"9": "os_cht",
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-11-14 07:35:09 +00:00
|
|
|
def get_device_id(name: str = ""):
|
2022-11-12 12:59:42 +00:00
|
|
|
return str(uuid.uuid3(uuid.NAMESPACE_URL, name))
|
2022-07-26 10:07:31 +00:00
|
|
|
|
|
|
|
|
2022-11-14 07:35:09 +00:00
|
|
|
def hex_digest(text):
|
2022-11-12 12:59:42 +00:00
|
|
|
_md5 = hashlib.md5() # nosec B303
|
|
|
|
_md5.update(text.encode())
|
|
|
|
return _md5.hexdigest()
|
|
|
|
|
|
|
|
|
2022-11-14 07:47:44 +00:00
|
|
|
def get_ds(ds_type: str = None, new_ds: bool = False, data: Any = None, params: Optional[Mapping[str, Any]] = None):
|
2022-11-14 06:06:07 +00:00
|
|
|
"""DS 算法
|
2022-11-23 01:11:29 +00:00
|
|
|
|
2022-11-14 06:06:07 +00:00
|
|
|
代码来自 https://github.com/y1ndan/genshinhelper
|
|
|
|
:param ds_type: 1:ios 2:android 4:pc web 5:mobile web
|
|
|
|
:param new_ds: 是否为DS2算法
|
|
|
|
:param data: 需要签名的Data
|
|
|
|
:param params: 需要签名的Params
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
|
2022-11-12 12:59:42 +00:00
|
|
|
def new():
|
|
|
|
t = str(int(time.time()))
|
|
|
|
r = str(random.randint(100001, 200000)) # nosec
|
2022-11-23 01:11:29 +00:00
|
|
|
b = json.dumps(data) if data else ""
|
|
|
|
q = "&".join(f"{k}={v}" for k, v in sorted(params.items())) if params else ""
|
|
|
|
c = hex_digest(f"salt={salt}&t={t}&r={r}&b={b}&q={q}")
|
|
|
|
return f"{t},{r},{c}"
|
2022-11-12 12:59:42 +00:00
|
|
|
|
|
|
|
def old():
|
|
|
|
t = str(int(time.time()))
|
2022-11-23 01:11:29 +00:00
|
|
|
r = "".join(random.sample(string.ascii_lowercase + string.digits, 6))
|
|
|
|
c = hex_digest(f"salt={salt}&t={t}&r={r}")
|
|
|
|
return f"{t},{r},{c}"
|
2022-11-12 12:59:42 +00:00
|
|
|
|
2023-01-26 09:29:27 +00:00
|
|
|
app_version = "2.44.1"
|
2022-11-23 01:11:29 +00:00
|
|
|
client_type = "5"
|
2023-01-26 09:29:27 +00:00
|
|
|
salt = "IEIZiKYaput2OCKQprNuGsog1NZc1FkS"
|
2022-11-12 12:59:42 +00:00
|
|
|
ds = old()
|
2022-12-27 09:28:04 +00:00
|
|
|
if ds_type in {"android", "2"}:
|
2022-11-23 01:11:29 +00:00
|
|
|
client_type = "2"
|
2023-01-26 09:29:27 +00:00
|
|
|
salt = "dZAwGk4e9aC0MXXItkwnHamjA1x30IYw"
|
2022-11-12 12:59:42 +00:00
|
|
|
ds = old()
|
2022-12-27 09:28:04 +00:00
|
|
|
elif ds_type == "android_new":
|
2022-11-23 01:11:29 +00:00
|
|
|
client_type = "2"
|
|
|
|
salt = "t0qEgfub6cvueAPgR5m9aQWWVciEer7v"
|
2022-11-12 12:59:42 +00:00
|
|
|
ds = new()
|
|
|
|
if new_ds:
|
2022-11-23 01:11:29 +00:00
|
|
|
client_type = "5"
|
|
|
|
salt = "xV8v4Qu54lUKrEYFZkJhB8cuOh9Asafs"
|
2022-11-12 12:59:42 +00:00
|
|
|
ds = new()
|
|
|
|
|
|
|
|
return app_version, client_type, ds
|
2022-07-26 10:07:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_recognize_server(uid: int) -> str:
|
|
|
|
server = RECOGNIZE_SERVER.get(str(uid)[0])
|
|
|
|
if server:
|
|
|
|
return server
|
|
|
|
else:
|
|
|
|
raise TypeError(f"UID {uid} isn't associated with any recognize server")
|
|
|
|
|
|
|
|
|
2022-11-14 06:13:22 +00:00
|
|
|
def get_ua(device: str = "Paimon Build", version: str = "2.36.1"):
|
2022-11-14 06:06:07 +00:00
|
|
|
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 "
|
2022-12-10 12:37:43 +00:00
|
|
|
f"{'miHoYoBBS/' + version if version else ''}"
|
2022-11-14 06:13:22 +00:00
|
|
|
)
|