解小黑屋现可投入测试

This commit is contained in:
Your Name 2025-02-07 18:36:47 +08:00
parent 5c7414d173
commit 0edd75f60f
6 changed files with 28 additions and 19 deletions

View File

@ -20,9 +20,6 @@ ObfuscateParam = "BEs2D5vW"
class SDGBApiError(Exception):
pass
class SDGBMaxRetriesError(SDGBApiError):
pass
class SDGBRequestError(SDGBApiError):
pass
@ -97,8 +94,8 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
verify=False,
timeout=timeout
)
logger.info(f"{targetApi} 请求结果: {response.status_code}")
if not noLog:
logger.info(f"{targetApi} 请求结果: {response.status_code}")
if response.status_code == 200:
logger.debug("200 OK!")
@ -112,11 +109,16 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
try:
responseDecompressed = zlib.decompress(responseRAWContent)
logger.debug("成功解压响应!")
except zlib.error:
except:
logger.warning(f"无法解压,得到的原始响应: {responseRAWContent}")
raise SDGBResponseError("Decompression failed")
resultResponse = unpad(aes.decrypt(responseDecompressed), 16).decode()
raise SDGBResponseError("解压失败")
try:
resultResponse = unpad(aes.decrypt(responseDecompressed), 16).decode()
logger.debug(f"成功解密响应!")
except:
logger.warning(f"解密失败,得到的原始响应: {responseDecompressed}")
raise SDGBResponseError("解密失败")
if not noLog:
logger.debug(f"响应: {resultResponse}")
return resultResponse
@ -134,7 +136,7 @@ def apiSDGB(data:str, targetApi:str, userAgentExtraData:str, noLog:bool=False, t
# 其他错误,重试
logger.warning(f"Will now retry. {e}")
retries += 1
time.sleep(3)
time.sleep(2)
raise SDGBApiError("Multiple retries failed to make a successful request")

View File

@ -111,7 +111,7 @@ def implUserMusicToDivingFish(userId:int, fishImportToken:str):
logger.info("成功得到成绩!转换成水鱼格式..")
divingFishData = maimaiUserMusicDetailToDivingFishFormat(userFullMusicDetailList)
logger.info("转换成功!开始上传水鱼..")
if not updateFishRecords(fishImportToken, divingFishData)
if not updateFishRecords(fishImportToken, divingFishData):
logger.error("上传失败!")
return False
return len(divingFishData)

View File

@ -11,4 +11,4 @@ loginBonusDBPathFallback = "./maimaiDX-Api/Data/loginBonusDB.json"
musicDBPathFallback = "./maimaiDX-Api/Data/musicDB.json"
# 日本精工,安全防漏
from MyConfig import *
#from MyConfig import *

View File

@ -9,12 +9,19 @@ import json
from loguru import logger
import time
from datetime import datetime
import asyncio
def isUserLoggedIn(userId):
isLogin = json.loads(apiGetUserPreview(userId))['isLogin']
logger.info(f"用户 {userId} 是否登录: {isLogin}")
isLogin = json.loads(apiGetUserPreview(userId, True))['isLogin']
logger.debug(f"用户 {userId} 是否登录: {isLogin}")
return isLogin
def getHumanReadableTime(unixTime):
'''将 Unix 时间戳转换为人类可读的时间'''
# 减一个小时,因为舞萌貌似是 UTC+9
timestamp = int(unixTime) - 3600
return datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S')
def getMaimaiUNIXTime(mmddhhmmss, year=2025):
"""
解析用户输入的 MMDDHHMMSS 格式的时间返回 Unix 时间戳
@ -37,7 +44,7 @@ def logOut(userId, Timestamp):
"""极其简单的登出实现,成功返回 True失败返回 False
注意不会检查用户是否真的登出了只会尝试登出"""
try:
if apiLogout(Timestamp, userId)['returnCode'] == 1:
if apiLogout(Timestamp, userId, True)['returnCode'] == 1:
# 成功送出了登出请求
logger.debug(f"已成功尝试登出用户 {userId}")
return True

View File

@ -6,11 +6,11 @@ from Config import *
import time
import random
def apiGetUserPreview(userId) -> str:
def apiGetUserPreview(userId, noLog:bool=False) -> str:
data = json.dumps({
"userId": int(userId)
})
preview_result = apiSDGB(data, "GetUserPreviewApi", userId)
preview_result = apiSDGB(data, "GetUserPreviewApi", userId, noLog)
return preview_result
# CLI 示例

View File

@ -20,7 +20,7 @@ def apiLogin(timestamp:int, userId:int, noLog:bool=False) -> dict:
"isContinue": False,
"genericFlag": 0,
})
login_result = json.loads(apiSDGB(data, "UserLoginApi", userId))
login_result = json.loads(apiSDGB(data, "UserLoginApi", userId, noLog))
if not noLog:
logger.info("登录:结果:"+ str(login_result))
return login_result
@ -36,7 +36,7 @@ def apiLogout(timestamp:int, userId:int, noLog:bool=False) -> dict:
"dateTime": timestamp,
"type": 1
})
logout_result = json.loads(apiSDGB(data, "UserLogoutApi", userId))
logout_result = json.loads(apiSDGB(data, "UserLogoutApi", userId, noLog))
if not noLog:
logger.info("登出:结果:"+ str(logout_result))
return logout_result