上传文件至 /
This commit is contained in:
82
API_AimeDB.py
Normal file
82
API_AimeDB.py
Normal file
@@ -0,0 +1,82 @@
|
||||
import hashlib
|
||||
import time
|
||||
import requests
|
||||
import json
|
||||
import re
|
||||
from loguru import logger
|
||||
|
||||
CHIP_ID = ""
|
||||
COMMON_KEY = "XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW"
|
||||
API_URL = "http://ai.sys-allnet.cn/wc_aime/api/get_data"
|
||||
|
||||
def getSHA256(input_str):
|
||||
return hashlib.sha256(input_str.encode('utf-8')).hexdigest().upper()
|
||||
|
||||
def generateSEGATimestamp():
|
||||
return time.strftime("%y%m%d%H%M%S", time.localtime())
|
||||
|
||||
def calcSEGAAimeDBAuthKey(varString:str, timestamp:str, commonKey:str="XcW5FW4cPArBXEk4vzKz3CIrMuA5EVVW") -> str:
|
||||
return hashlib.sha256((varString + timestamp + commonKey).encode("utf-8")).hexdigest().upper()
|
||||
|
||||
def apiAimeDB(qrCode):
|
||||
timestamp = generateSEGATimestamp()
|
||||
|
||||
currentKey = calcSEGAAimeDBAuthKey(CHIP_ID, timestamp, COMMON_KEY)
|
||||
|
||||
payload = {
|
||||
"chipID": CHIP_ID,
|
||||
"openGameID": "MAID",
|
||||
"key": currentKey,
|
||||
"qrCode": qrCode,
|
||||
"timestamp": timestamp
|
||||
}
|
||||
|
||||
print("Payload:", json.dumps(payload, separators=(',', ':')))
|
||||
|
||||
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:str, isAlreadyFinal:bool=False) -> str:
|
||||
if isAlreadyFinal:
|
||||
qr_code_final = qrCode
|
||||
else:
|
||||
qr_code_final = qrCode[20:]
|
||||
|
||||
response = apiAimeDB(qr_code_final)
|
||||
|
||||
print("implAimeDB: StatusCode is ", response.status_code)
|
||||
print("implAimeDB: Response Body is:", response.text)
|
||||
return response.text
|
||||
|
||||
|
||||
def implGetUID(qr_content:str) -> dict:
|
||||
|
||||
if not isSGWCFormat(qr_content):
|
||||
return {'errorID': 60001}
|
||||
|
||||
try:
|
||||
result = json.loads(implAimeDB(qr_content))
|
||||
logger.info(f"QRScan Got Response {result}")
|
||||
except:
|
||||
return {'errorID': 60002}
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user