TitleServer通讯优化测试

This commit is contained in:
Remik1r3n
2025-07-14 11:40:16 +08:00
parent f53dfef7ca
commit e6d35010e6

View File

@@ -14,16 +14,16 @@ from Config import *
from typing import Optional
import certifi
# 舞萌DX 2024
# omg it's leaking
#AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
#AesIV = ";;KjR1C3hgB1ovXa"
#ObfuscateParam = "BEs2D5vW"
use2024Api = False # 是否使用 2024 API
# 2025
AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R"
AesIV = "d6xHIKq]1J]Dt^ue"
ObfuscateParam = "B44df8yT"
if use2024Api:
AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
AesIV = ";;KjR1C3hgB1ovXa"
ObfuscateParam = "BEs2D5vW"
else:
AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R"
AesIV = "d6xHIKq]1J]Dt^ue"
ObfuscateParam = "B44df8yT"
class SDGBApiError(Exception):
pass
@@ -107,7 +107,6 @@ def apiSDGB(
logger.debug("使用代理")
httpClient = httpx.Client(proxy=proxyUrl, verify=False)
else:
logger.debug("不使用代理")
httpClient = httpx.Client(verify=False)
# 发送请求
@@ -147,14 +146,22 @@ def apiSDGB(
raise SDGBResponseError("解密失败")
# 然后尝试解压
try:
# 看看文件头是否正确
if not responseContentDecrypted.startswith(b'\x78\x9c'):
logger.warning("NOT ZLIB FORMAT")
raise Exception(f"响应内容不是 zlib 压缩格式, 内容: {responseContentDecrypted}")
# 看看文件头是否是压缩过的
if responseContentDecrypted.startswith(b'\x78\x9c'):
logger.debug("响应内容是 zlib 压缩格式")
responseContentFinal = zlib.decompress(responseContentDecrypted).decode('utf-8')
else:
logger.warning(f"响应内容不是 zlib 压缩格式, 内容: {responseContentDecrypted}")
responseContentFinal = responseContentDecrypted.decode('utf-8')
if not noLog:
#logger.debug("成功解压响应!")
logger.debug(f"响应: {responseContentFinal}")
# 最终处理,检查是否是 JSON 格式
if responseContentFinal.startswith('{') and responseContentFinal.endswith('}'):
# 如果是 JSON 格式,直接返回
return responseContentFinal
else:
# 如果不是 JSON 格式,可能是文本或其他格式,直接返回
logger.warning("响应内容不对劲!可能有错误!")
return responseContentFinal
except:
logger.warning(f"解压失败,原始响应: {responseContentDecrypted}")
@@ -190,7 +197,6 @@ def calcPlaySpecial():
num2 >>= 1
return c_int32(result.value).value
class AESPKCS7_2024:
# 实现了 maimai 通讯所用的 AES 加密的类
def __init__(self, key: str, iv: str):