chore: totally fix lint issues
This commit is contained in:
@@ -8,25 +8,36 @@ import requests
|
||||
import json
|
||||
import re
|
||||
from loguru import logger
|
||||
|
||||
# 常量
|
||||
CHIP_ID = "A63E-01E68606624"
|
||||
COMMON_KEY = "XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW"
|
||||
API_URL = "http://ai.sys-allnet.cn/wc_aime/api/get_data"
|
||||
|
||||
|
||||
# 计算 SHA256
|
||||
def getSHA256(input_str):
|
||||
"""SHA256计算"""
|
||||
return hashlib.sha256(input_str.encode('utf-8')).hexdigest().upper()
|
||||
return hashlib.sha256(input_str.encode("utf-8")).hexdigest().upper()
|
||||
|
||||
|
||||
# 生成时间戳
|
||||
def generateSEGATimestamp():
|
||||
"""SEGA格式的 YYMMDDHHMMSS 时间戳(sb玩意)"""
|
||||
return time.strftime("%y%m%d%H%M%S", time.localtime())
|
||||
|
||||
|
||||
# 计算认证 key
|
||||
def calcSEGAAimeDBAuthKey(varString:str, timestamp:str, commonKey:str="XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW") -> str:
|
||||
def calcSEGAAimeDBAuthKey(
|
||||
varString: str, timestamp: str, commonKey: str = "XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW"
|
||||
) -> str:
|
||||
"""计算 SEGA AimeDB 的认证 key"""
|
||||
return hashlib.sha256((varString + timestamp + commonKey).encode("utf-8")).hexdigest().upper()
|
||||
return (
|
||||
hashlib.sha256((varString + timestamp + commonKey).encode("utf-8"))
|
||||
.hexdigest()
|
||||
.upper()
|
||||
)
|
||||
|
||||
|
||||
def apiAimeDB(qrCode):
|
||||
"""AimeDB 扫码 API 实现"""
|
||||
@@ -42,11 +53,11 @@ def apiAimeDB(qrCode):
|
||||
"openGameID": "MAID",
|
||||
"key": currentKey,
|
||||
"qrCode": qrCode,
|
||||
"timestamp": timestamp
|
||||
"timestamp": timestamp,
|
||||
}
|
||||
|
||||
# 输出准备好的请求数据
|
||||
print("Payload:", json.dumps(payload, separators=(',', ':')))
|
||||
print("Payload:", json.dumps(payload, separators=(",", ":")))
|
||||
|
||||
# 发送 POST 请求
|
||||
headers = {
|
||||
@@ -55,7 +66,9 @@ def apiAimeDB(qrCode):
|
||||
"User-Agent": "WC_AIME_LIB",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
response = requests.post(API_URL, data=json.dumps(payload, separators=(',', ':')), headers=headers)
|
||||
response = requests.post(
|
||||
API_URL, data=json.dumps(payload, separators=(",", ":")), headers=headers
|
||||
)
|
||||
|
||||
# 返回服务器的响应
|
||||
return response
|
||||
@@ -64,16 +77,16 @@ def apiAimeDB(qrCode):
|
||||
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 #有效字符
|
||||
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:str, isAlreadyFinal:bool=False) -> str:
|
||||
|
||||
def implAimeDB(qrCode: str, isAlreadyFinal: bool = False) -> str:
|
||||
"""
|
||||
Aime DB 的请求的参考实现。
|
||||
提供完整 QRCode 内容,返回响应的字符串(Json格式)
|
||||
@@ -93,7 +106,7 @@ def implAimeDB(qrCode:str, isAlreadyFinal:bool=False) -> str:
|
||||
return response.text
|
||||
|
||||
|
||||
def implGetUID(qr_content:str) -> dict:
|
||||
def implGetUID(qr_content: str) -> dict:
|
||||
"""
|
||||
包装后的 UID 扫码器实现。
|
||||
此函数会返回 AimeDB 传回的 Json 转成 Python 字典的结果。
|
||||
@@ -101,18 +114,19 @@ def implGetUID(qr_content:str) -> dict:
|
||||
"""
|
||||
# 检查格式
|
||||
if not isSGWCFormat(qr_content):
|
||||
return {'errorID': 60001} # 二维码内容明显无效
|
||||
|
||||
return {"errorID": 60001} # 二维码内容明显无效
|
||||
|
||||
# 发送请求并处理响应
|
||||
try:
|
||||
result = json.loads(implAimeDB(qr_content))
|
||||
logger.info(f"QRScan Got Response {result}")
|
||||
except:
|
||||
return {'errorID': 60002} # 无法解码 Response 的内容
|
||||
|
||||
except Exception:
|
||||
return {"errorID": 60002} # 无法解码 Response 的内容
|
||||
|
||||
# 返回结果
|
||||
return result
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
userInputQR = input("QRCode: ")
|
||||
print(implAimeDB(userInputQR))
|
||||
|
||||
Reference in New Issue
Block a user