fix: make 2024 api easier to use

This commit is contained in:
mokurin000
2025-07-30 03:20:54 +08:00
parent 47dcc2e045
commit 6d234bc2b3
3 changed files with 36 additions and 11 deletions

View File

@@ -16,18 +16,20 @@ from Config import (
proxyUrl, proxyUrl,
) )
use2024Api = False # 是否使用 2024 API
if use2024Api:
AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
AesIV = ";;KjR1C3hgB1ovXa"
ObfuscateParam = "BEs2D5vW"
else:
AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R" AesKey = "a>32bVP7v<63BVLkY[xM>daZ1s9MBP<R"
AesIV = "d6xHIKq]1J]Dt^ue" AesIV = "d6xHIKq]1J]Dt^ue"
ObfuscateParam = "B44df8yT" ObfuscateParam = "B44df8yT"
def use2024Api():
global AesKey, AesIV, ObfuscateParam
AesKey = "n7bx6:@Fg_:2;5E89Phy7AyIcpxEQ:R@"
AesIV = ";;KjR1C3hgB1ovXa"
ObfuscateParam = "BEs2D5vW"
class SDGBApiError(Exception): class SDGBApiError(Exception):
pass pass
@@ -117,11 +119,15 @@ def apiSDGB(
else: else:
httpClient = httpx.Client(verify=False) httpClient = httpx.Client(verify=False)
api_hash = getSDGBApiHash(targetApi)
logger.info(f"hash: {api_hash}")
# 发送请求 # 发送请求
response = httpClient.post( response = httpClient.post(
url=endpoint + getSDGBApiHash(targetApi), url=endpoint + api_hash,
headers={ headers={
"User-Agent": f"{getSDGBApiHash(targetApi)}#{agentExtra}", "User-Agent": f"{api_hash}#{agentExtra}",
"Content-Type": "application/json", "Content-Type": "application/json",
"Mai-Encoding": "1.50", "Mai-Encoding": "1.50",
"Accept-Encoding": "", "Accept-Encoding": "",
@@ -144,8 +150,6 @@ def apiSDGB(
# 处理响应内容 # 处理响应内容
responseContentRaw = response.content responseContentRaw = response.content
print(list(responseContentRaw))
# 先尝试解密 # 先尝试解密
try: try:
responseContentDecrypted = aes.decrypt(responseContentRaw) responseContentDecrypted = aes.decrypt(responseContentRaw)

View File

@@ -7,7 +7,6 @@ from API_TitleServer import apiSDGB
def apiGetUserPreview(userId, noLog: bool = False) -> str: def apiGetUserPreview(userId, noLog: bool = False) -> str:
data = json.dumps({"userId": int(userId)}) data = json.dumps({"userId": int(userId)})
preview_result = apiSDGB(data, "GetUserPreviewApi", userId, noLog) preview_result = apiSDGB(data, "GetUserPreviewApi", userId, noLog)
print(apiSDGB("{}", "Ping", userId, noLog))
return preview_result return preview_result
@@ -16,3 +15,4 @@ if __name__ == "__main__":
userId = input("请输入用户 ID") userId = input("请输入用户 ID")
# userId = testUid8 # userId = testUid8
print(apiGetUserPreview(userId)) print(apiGetUserPreview(userId))
print(apiSDGB("{}", "Ping", userId, False))

21
GetPreview2024.py Normal file
View File

@@ -0,0 +1,21 @@
# 获取用户简略预览数据的 API 实现,此 API 无需任何登录即可调取
import rapidjson as json
from API_TitleServer import apiSDGB_2024, use2024Api
use2024Api()
def apiGetUserPreview(userId, noLog: bool = False) -> str:
data = json.dumps({"userId": int(userId)})
preview_result = apiSDGB_2024(data, "GetUserPreviewApi", userId, noLog)
return preview_result
# CLI 示例
if __name__ == "__main__":
userId = input("请输入用户 ID")
# userId = testUid8
# print(apiGetUserPreview(userId))
print(apiSDGB_2024("{}", "Ping", userId, False))