From 0edd75f60f2c6e8b1b2f61f19d51961fdbee098f Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 7 Feb 2025 18:36:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=B0=8F=E9=BB=91=E5=B1=8B=E7=8E=B0?= =?UTF-8?q?=E5=8F=AF=E6=8A=95=E5=85=A5=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_TitleServer.py | 22 ++++++++++++---------- Best50_To_Diving_Fish.py | 2 +- Config.py | 2 +- ForceLogout.py | 13 ++++++++++--- GetPreview.py | 4 ++-- HelperLogInOut.py | 4 ++-- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/API_TitleServer.py b/API_TitleServer.py index 324a381..7f71941 100644 --- a/API_TitleServer.py +++ b/API_TitleServer.py @@ -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") diff --git a/Best50_To_Diving_Fish.py b/Best50_To_Diving_Fish.py index 1d1dc99..333d081 100644 --- a/Best50_To_Diving_Fish.py +++ b/Best50_To_Diving_Fish.py @@ -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) diff --git a/Config.py b/Config.py index ebb56ed..f4e779e 100644 --- a/Config.py +++ b/Config.py @@ -11,4 +11,4 @@ loginBonusDBPathFallback = "./maimaiDX-Api/Data/loginBonusDB.json" musicDBPathFallback = "./maimaiDX-Api/Data/musicDB.json" # 日本精工,安全防漏 -from MyConfig import * +#from MyConfig import * diff --git a/ForceLogout.py b/ForceLogout.py index 22a0261..c949bf7 100644 --- a/ForceLogout.py +++ b/ForceLogout.py @@ -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 diff --git a/GetPreview.py b/GetPreview.py index f3aba54..9932771 100644 --- a/GetPreview.py +++ b/GetPreview.py @@ -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 示例 diff --git a/HelperLogInOut.py b/HelperLogInOut.py index cfec1e5..7a8671d 100644 --- a/HelperLogInOut.py +++ b/HelperLogInOut.py @@ -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