Initial restarted commit

This commit is contained in:
Remik1r3n
2025-01-23 18:52:09 +08:00
commit 83da4636ac
18 changed files with 1753 additions and 0 deletions

110
API_AimeDB.py Normal file
View File

@@ -0,0 +1,110 @@
import hashlib
import time
import requests
import json
import re
# 计算 SHA256
def compute_sha256(input_str):
"""SHA256计算"""
return hashlib.sha256(input_str.encode('utf-8')).hexdigest().upper()
# 生成时间戳
def get_timestamp():
"""SEGA格式的 YYMMDDHHMMSS 时间戳sb玩意"""
return time.strftime("%y%m%d%H%M%S", time.localtime())
# 计算认证 key
def calculate_auth_key(time_stamp: str, chip_id: str, auth_key_param: str) -> str:
"""计算 Key"""
return hashlib.sha256((chip_id + time_stamp + auth_key_param).encode("utf-8")).hexdigest().upper()
def apiAimeDB(qr_code, chip_id, auth_key_param, game_id, api_url):
"""AimeDB API 实现"""
# 生成一个时间戳
time_stamp = get_timestamp()
# 使用时间戳计算 key
auth_key = calculate_auth_key(time_stamp, chip_id, auth_key_param)
# 构造请求数据
payload = {
"chipID": chip_id,
"openGameID": game_id,
"key": auth_key,
"qrCode": qr_code,
"timestamp": time_stamp
}
# 输出准备好的请求数据
print("Payload:", json.dumps(payload, separators=(',', ':')))
# 发送 POST 请求
headers = {
"Connection": "Keep-Alive",
"Host": api_url.split("//")[-1].split("/")[0],
"User-Agent": "WC_AIME_LIB",
"Content-Type": "application/json",
}
response = requests.post(api_url, data=json.dumps(payload, separators=(',', ':')), headers=headers)
# 返回服务器的响应
return response
def isSGWCFormat(input_string: str) -> bool:
'''简单检查二维码字符串是否符合格式'''
if (
len(input_string) != 84 #长度
or not input_string.startswith("SGWCMAID") #识别字
or re.match("^[0-9A-F]+$", input_string[20:]) is None #有效字符
):
return False
else:
return True
def implAimeDB(qrcode_content_full:str) -> str:
'''
Aime DB 的请求的参考实现。
提供完整 QRCode 内容返回响应的字符串Json格式
'''
CHIP_ID = "A63E-01E68606624"
AUTH_KEY_PARAM = "XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW"
GAME_ID = "MAID"
API_URL = "http://ai.sys-allnet.cn/wc_aime/api/get_data"
qr_code_final = qrcode_content_full[20:]
# 发送请求
response = apiAimeDB(qr_code_final, CHIP_ID, AUTH_KEY_PARAM, GAME_ID, API_URL)
# 获得结果
print("implAimeDB: StatusCode is ", response.status_code)
print("implAimeDB: Response Body is:", response.text)
return(response.text)
def implGetUID(qr_content:str) -> dict:
'''
包装后的 UID 扫码器实现。
此函数会返回 AimeDB 传回的 Json 转成 Python 字典的结果。
主要特点是添加了几个新的错误码(6000x)用来应对程序的错误。
'''
# 检查格式
if not isSGWCFormat(qr_content):
return {'errorID': 60001} # 二维码内容明显无效
# 发送请求并处理响应
try:
result_string = implAimeDB(qr_content)
result_dict = json.loads(result_string)
except:
return {'errorID': 60002} # 无法解码 Response 的内容
# 返回结果
return result_dict
if __name__ == "__main__":
userInputQR = input("QRCode: ")
print(implAimeDB(userInputQR))