暂时能用了 吧

This commit is contained in:
Remik1r3n 2025-06-11 09:38:17 +08:00
parent dc12cb40ff
commit 472844474f
2 changed files with 52 additions and 17 deletions

View File

@ -15,9 +15,9 @@ import certifi
# 舞萌DX 2024 # 舞萌DX 2024
# omg it's leaking # omg it's leaking
AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@" #AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
AesIV = ";;KjR1C3hgB1ovXa" #AesIV = ";;KjR1C3hgB1ovXa"
ObfuscateParam = "BEs2D5vW" #ObfuscateParam = "BEs2D5vW"
# 2025 # 2025
AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R" AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R"
@ -33,28 +33,38 @@ class SDGBRequestError(SDGBApiError):
class SDGBResponseError(SDGBApiError): class SDGBResponseError(SDGBApiError):
pass pass
class AESPKCS7: class aes_pkcs7(object):
# 实现了 maimai 通讯所用的 AES 加密的类
def __init__(self, key: str, iv: str): def __init__(self, key: str, iv: str):
self.key = key.encode('utf-8') self.key = key.encode('utf-8')
self.iv = iv.encode('utf-8') self.iv = iv.encode('utf-8')
self.mode = AES.MODE_CBC self.mode = AES.MODE_CBC
# 加密
def encrypt(self, content) -> bytes: def encrypt(self, content: bytes) -> bytes:
# if content is str, convert to bytes
#if isinstance(content, str):
# encodedData = content.encode('utf-8')
cipher = AES.new(self.key, self.mode, self.iv) cipher = AES.new(self.key, self.mode, self.iv)
content_padded = pad(content, AES.block_size) content_padded = pad(content, AES.block_size)
encrypted_bytes = cipher.encrypt(content_padded) encrypted_bytes = cipher.encrypt(content_padded)
return encrypted_bytes return encrypted_bytes
# 解密
def decrypt(self, encrypted_content: bytes) -> str: def decrypt(self, content):
cipher = AES.new(self.key, self.mode, self.iv) cipher = AES.new(self.key, self.mode, self.iv)
decrypted_padded = cipher.decrypt(encrypted_content) decrypted_padded = cipher.decrypt(content)
decrypted = unpad(decrypted_padded, AES.block_size) decrypted = unpad(decrypted_padded, AES.block_size)
return decrypted return decrypted
def pkcs7unpadding(self, text):
length = len(text)
unpadding = ord(text[length - 1])
return text[0:length - unpadding]
def pkcs7padding(self, text):
bs = 16
length = len(text)
bytes_length = len(text.encode('utf-8'))
padding_size = length if (bytes_length == length) else bytes_length
padding = bs - padding_size % bs
padding_text = chr(padding) * padding
return text + padding_text
def getSDGBApiHash(api): def getSDGBApiHash(api):
# API 的 Hash 的生成 # API 的 Hash 的生成
# 有空做一下 Hash 的彩虹表? # 有空做一下 Hash 的彩虹表?
@ -70,7 +80,32 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
""" """
maxRetries = 3 maxRetries = 3
agentExtra = str(userAgentExtraData) agentExtra = str(userAgentExtraData)
aes = AESPKCS7(AesKey, AesIV) aes = aes_pkcs7(AesKey,AesIV)
data = bytes(data, encoding="utf-8")
data_def = zlib.compress(data)
data_enc = aes.encrypt(data_def)
endpoint = "https://maimai-gm.wahlap.com:42081/Maimai2Servlet/"
r = httpx.post(
endpoint + getSDGBApiHash(targetApi),
headers = {
"User-Agent": f"{getSDGBApiHash(targetApi)}#{agentExtra}",
"Content-Type": "application/json",
"Mai-Encoding": "1.50",
"Accept-Encoding": "",
"Charset": "UTF-8",
"Content-Encoding": "deflate",
"Expect": "100-continue"
},
data = data_enc
)
resp_enc = r.content
try:
resp_def = aes.decrypt(resp_enc)
except:
resp_def = resp_enc
return zlib.decompress(resp_def).decode('utf-8')
# Begin Build # Begin Build
requestDataFinal = aes.encrypt(zlib.compress(data.encode('utf-8'))) requestDataFinal = aes.encrypt(zlib.compress(data.encode('utf-8')))
# End Build # End Build
@ -127,7 +162,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
logger.warning(f"解密失败,得到的原始响应: {responseContentRaw}") logger.warning(f"解密失败,得到的原始响应: {responseContentRaw}")
raise SDGBResponseError("解密失败") raise SDGBResponseError("解密失败")
try: try:
responseDataFinal = zlib.decompress(responseContentDecrypted) zlib.decompress(responseContentDecrypted).decode('utf-8')
logger.debug("成功解压响应!") logger.debug("成功解压响应!")
except: except:
logger.warning(f"无法解压,解密的原始响应: {responseContentDecrypted}") logger.warning(f"无法解压,解密的原始响应: {responseContentDecrypted}")
@ -136,7 +171,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
if not noLog: if not noLog:
logger.debug(f"响应: {responseContentDecrypted}") logger.debug(f"响应: {responseContentDecrypted}")
return responseContentDecrypted return responseContentDecrypted.decode('utf-8')
# 异常处理 # 异常处理
except SDGBRequestError as e: except SDGBRequestError as e:

View File

@ -160,7 +160,7 @@ def generateUserAllData(userId, currentLoginResult, currentLoginTimestamp, curre
"userGamePlaylogList": [ "userGamePlaylogList": [
{ {
"playlogId": currentLoginResult['loginId'], "playlogId": currentLoginResult['loginId'],
"version": "1.41.00", "version": "1.50.00",
"playDate": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S') + '.0', "playDate": datetime.now(pytz.timezone('Asia/Shanghai')).strftime('%Y-%m-%d %H:%M:%S') + '.0',
"playMode": 0, "playMode": 0,
"useTicketId": -1, "useTicketId": -1,