Created
January 18, 2023 10:48
-
-
Save monsterxcn/24a09fe5b0a0a55f567efa4c706405b6 to your computer and use it in GitHub Desktop.
fetch enka data from mirror teyvat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from time import time | |
from hashlib import md5 | |
from typing import Dict | |
from httpx import AsyncClient | |
SALT = "c098828gy1h7k6oillopj223w15se3" | |
def get_server(uid: str) -> str: | |
"""获取提瓦特小助手使用的服务器标记""" | |
if uid[0] == "5": | |
return "cn_qd01" | |
if uid[0] == "6": | |
return "us" | |
if uid[0] == "7": | |
return "eur" | |
if uid[0] == "8": | |
return "asia" | |
if uid[0] == "9": | |
return "hk" | |
return "cn_gf01" | |
def get_params(uid: str) -> Dict[str, str]: | |
"""获取提瓦特小助手请求参数""" | |
timestamp = str(int(time() * 1000)) | |
authkey = md5(f"{SALT}{uid}{timestamp}".encode()).hexdigest() | |
return { | |
"uid": uid, | |
"server": get_server(uid), | |
"unionid": "", | |
"from": "normal", | |
"timestamp": timestamp, | |
"authkey": authkey, | |
} | |
async def teyvat_panel(uid: str) -> Dict: | |
"""从提瓦特小助手获取角色展柜数据""" | |
async with AsyncClient() as client: | |
res = await client.get( | |
"https://api.lelaer.com/ys/getPlayerCard.php", | |
params=get_params(uid), | |
headers={ | |
"referer": "https://servicewechat.com/wx2ac9dce11213c3a8/205/page-frame.html", | |
"user-agent": ( | |
"Mozilla/5.0 (Linux; Android 12; SM-G977N Build/SP1A.210812.016; wv) " | |
"AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/86.0.4240.99 " | |
"XWEB/4375 MMWEBSDK/20221011 Mobile Safari/537.36 MMWEBID/4357 " | |
"MicroMessenger/8.0.30.2244(0x28001E44) WeChat/arm64 Weixin GPVersion/1 " | |
"NetType/WIFI Language/zh_CN ABI/arm64 MiniProgramEnv/android" | |
), | |
}, | |
) | |
return res.json() | |
if __name__ == "__main__": | |
print(asyncio.run(teyvat_panel("134266985"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment