forked from Kohaku/maimaiDX-Api
解小黑屋第一版 + 爬UID功能
This commit is contained in:
parent
486da8a4c7
commit
5c7414d173
@ -10,15 +10,20 @@ from loguru import logger
|
|||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def isUserLoggedIn(userId):
|
def isUserLoggedIn(userId):
|
||||||
return True
|
isLogin = json.loads(apiGetUserPreview(userId))['isLogin']
|
||||||
return json.loads(apiGetUserPreview(userId))['isLogin']
|
logger.info(f"用户 {userId} 是否登录: {isLogin}")
|
||||||
|
return isLogin
|
||||||
|
|
||||||
def getUNIXTime(mmddhhmmss, year=2025):
|
def getMaimaiUNIXTime(mmddhhmmss, year=2025):
|
||||||
# 解析 MMDDHHMMSS 格式的时间,返回 Unix 时间戳
|
"""
|
||||||
|
解析用户输入的 MMDDHHMMSS 格式的时间,返回 Unix 时间戳
|
||||||
|
时间会被推后一个小时,因为舞萌貌似是 UTC+9
|
||||||
|
"""
|
||||||
try:
|
try:
|
||||||
date_time_str = f"{year}{mmddhhmmss}"
|
#date_time_str = f"{year}{mmddhhmmss}"
|
||||||
|
# 舞萌需要把小时按往后推一个小时来计算,加上一个小时
|
||||||
|
date_time_str = f"{year}{mmddhhmmss[:4]}{int(mmddhhmmss[4:6])+1:02}{mmddhhmmss[6:]}"
|
||||||
date_time_obj = datetime.strptime(date_time_str, '%Y%m%d%H%M%S')
|
date_time_obj = datetime.strptime(date_time_str, '%Y%m%d%H%M%S')
|
||||||
# 将 datetime 对象转换为 Unix 时间戳
|
# 将 datetime 对象转换为 Unix 时间戳
|
||||||
unix_timestamp = int(time.mktime(date_time_obj.timetuple()))
|
unix_timestamp = int(time.mktime(date_time_obj.timetuple()))
|
||||||
@ -29,27 +34,27 @@ def getUNIXTime(mmddhhmmss, year=2025):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def logOut(userId, Timestamp):
|
def logOut(userId, Timestamp):
|
||||||
DEBUGMODE = True
|
"""极其简单的登出实现,成功返回 True,失败返回 False
|
||||||
if DEBUGMODE:
|
注意:不会检查用户是否真的登出了,只会尝试登出"""
|
||||||
# 用于调试的时间戳
|
|
||||||
debugRealTimestamp = 1738663945
|
|
||||||
logger.info(f"调试模式: 传入的时间戳和调试时间戳之差: {Timestamp - debugRealTimestamp}")
|
|
||||||
time.sleep(0.2)
|
|
||||||
return True
|
|
||||||
try:
|
try:
|
||||||
result = apiLogout(Timestamp, userId)
|
if apiLogout(Timestamp, userId)['returnCode'] == 1:
|
||||||
loadedResult = json.loads(result)
|
# 成功送出了登出请求
|
||||||
if loadedResult['returnCode'] == 1:
|
logger.debug(f"已成功尝试登出用户 {userId}")
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
|
logger.error(f"登出用户 {userId} 的时候发生了错误")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def isCorrectTimestamp(timestamp, userId):
|
def isCorrectTimestamp(timestamp, userId):
|
||||||
'''暴力的检查时间戳是否正确'''
|
'''
|
||||||
logoutResult = logOut(userId, timestamp)
|
动作:给定一个时间戳,用它尝试登出用户,然后检查用户是否成功登出。
|
||||||
if not logoutResult:
|
如果用户成功登出,返回 True;否则返回 False。
|
||||||
|
'''
|
||||||
|
if not logOut(userId, timestamp):
|
||||||
|
logger.error(f"用时间戳 {timestamp} 登出用户 {userId} 的时候发生了错误")
|
||||||
return False
|
return False
|
||||||
isLoggedOut = not isUserLoggedIn(userId)
|
isLoggedOut = not isUserLoggedIn(userId)
|
||||||
|
logger.debug(f"时间戳 {timestamp} 是否正确: {isLoggedOut}")
|
||||||
return isLoggedOut
|
return isLoggedOut
|
||||||
|
|
||||||
def findCorrectTimestamp(timestamp, userId, max_attempts=1200):
|
def findCorrectTimestamp(timestamp, userId, max_attempts=1200):
|
||||||
@ -59,28 +64,32 @@ def findCorrectTimestamp(timestamp, userId, max_attempts=1200):
|
|||||||
|
|
||||||
while attempts < max_attempts:
|
while attempts < max_attempts:
|
||||||
# 尝试当前时间戳
|
# 尝试当前时间戳
|
||||||
if isCorrectTimestamp(timestamp, userId):
|
currentTryTimestamp = timestamp
|
||||||
print(f"Found correct timestamp: {timestamp}")
|
if isCorrectTimestamp(currentTryTimestamp, userId):
|
||||||
return timestamp
|
logger.info(f"正确的时间戳: {currentTryTimestamp}")
|
||||||
|
return currentTryTimestamp
|
||||||
|
|
||||||
# 增加偏移量尝试
|
# 增加偏移量尝试
|
||||||
if isCorrectTimestamp(timestamp + offset, userId):
|
currentTryTimestamp = timestamp + offset
|
||||||
print(f"Found correct timestamp: {timestamp + offset}")
|
if isCorrectTimestamp(currentTryTimestamp, userId):
|
||||||
return timestamp + offset
|
logger.info(f"正确的时间戳(在给定时间以后): {currentTryTimestamp}")
|
||||||
|
return currentTryTimestamp
|
||||||
|
|
||||||
# 减少偏移量尝试
|
# 减少偏移量尝试
|
||||||
if isCorrectTimestamp(timestamp - offset, userId):
|
currentTryTimestamp = timestamp - offset
|
||||||
print(f"Found correct timestamp: {timestamp - offset}")
|
if isCorrectTimestamp(currentTryTimestamp, userId):
|
||||||
return timestamp - offset
|
logger.info(f"正确的时间戳(在给定时间以前): {currentTryTimestamp}")
|
||||||
|
return currentTryTimestamp
|
||||||
|
|
||||||
# 增加尝试次数和偏移量
|
# 增加尝试次数和偏移量
|
||||||
attempts += 2
|
attempts += 2
|
||||||
offset += 1
|
offset += 1
|
||||||
|
|
||||||
print("尝试多次后未找到正确时间戳")
|
logger.error(f"无法找到正确的时间戳,尝试次数超过了 {max_attempts}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
human_time = "0204061500"
|
if __name__ == "__main__":
|
||||||
beginTimestamp = getUNIXTime(human_time)
|
human_time = "0207155500"
|
||||||
print(f"我们将开始用这个时间戳开始尝试: {beginTimestamp}")
|
beginTimestamp = getMaimaiUNIXTime(human_time)
|
||||||
correctTimestamp = findCorrectTimestamp(beginTimestamp, testUid)
|
print(f"我们将开始用这个时间戳开始尝试: {beginTimestamp}")
|
||||||
|
correctTimestamp = findCorrectTimestamp(beginTimestamp, testUid2)
|
||||||
|
@ -16,7 +16,7 @@ def apiGetUserPreview(userId) -> str:
|
|||||||
# CLI 示例
|
# CLI 示例
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
#userId = input("请输入用户 ID:")
|
#userId = input("请输入用户 ID:")
|
||||||
userId = testUid
|
userId = testUid2
|
||||||
print(apiGetUserPreview(userId))
|
print(apiGetUserPreview(userId))
|
||||||
|
|
||||||
|
|
||||||
@ -47,5 +47,5 @@ def crawlAllUserPreview():
|
|||||||
|
|
||||||
print('Finished!')
|
print('Finished!')
|
||||||
|
|
||||||
if __name__ == "__main__":
|
#if __name__ == "__main__":
|
||||||
crawlAllUserPreview()
|
# crawlAllUserPreview()
|
||||||
|
@ -8,8 +8,8 @@ from loguru import logger
|
|||||||
from Config import *
|
from Config import *
|
||||||
from API_TitleServer import apiSDGB
|
from API_TitleServer import apiSDGB
|
||||||
|
|
||||||
def apiLogin(timestamp:int, userId:int) -> dict:
|
def apiLogin(timestamp:int, userId:int, noLog:bool=False) -> dict:
|
||||||
"""登录,返回服务器给的 Json 的 dict"""
|
"""登录,返回 dict"""
|
||||||
data = json.dumps({
|
data = json.dumps({
|
||||||
"userId": userId,
|
"userId": userId,
|
||||||
"accessCode": "",
|
"accessCode": "",
|
||||||
@ -21,11 +21,12 @@ def apiLogin(timestamp:int, userId:int) -> dict:
|
|||||||
"genericFlag": 0,
|
"genericFlag": 0,
|
||||||
})
|
})
|
||||||
login_result = json.loads(apiSDGB(data, "UserLoginApi", userId))
|
login_result = json.loads(apiSDGB(data, "UserLoginApi", userId))
|
||||||
logger.info("登录:结果:"+ str(login_result))
|
if not noLog:
|
||||||
|
logger.info("登录:结果:"+ str(login_result))
|
||||||
return login_result
|
return login_result
|
||||||
|
|
||||||
def apiLogout(timestamp:int, userId:int) -> dict:
|
def apiLogout(timestamp:int, userId:int, noLog:bool=False) -> dict:
|
||||||
"""登出,返回 Json dict"""
|
"""登出,返回 dict"""
|
||||||
data = json.dumps({
|
data = json.dumps({
|
||||||
"userId": userId,
|
"userId": userId,
|
||||||
"accessCode": "",
|
"accessCode": "",
|
||||||
@ -36,12 +37,12 @@ def apiLogout(timestamp:int, userId:int) -> dict:
|
|||||||
"type": 1
|
"type": 1
|
||||||
})
|
})
|
||||||
logout_result = json.loads(apiSDGB(data, "UserLogoutApi", userId))
|
logout_result = json.loads(apiSDGB(data, "UserLogoutApi", userId))
|
||||||
logger.info("登出:结果:"+ str(logout_result))
|
if not noLog:
|
||||||
|
logger.info("登出:结果:"+ str(logout_result))
|
||||||
return logout_result
|
return logout_result
|
||||||
|
|
||||||
|
|
||||||
def generateTimestamp() -> int:
|
def generateTimestamp() -> int:
|
||||||
"""生成时间戳"""
|
"""生成一个凑合用的时间戳"""
|
||||||
timestamp = int(time.time()) - 60
|
timestamp = int(time.time()) - 60
|
||||||
logger.info(f"生成时间戳: {timestamp}")
|
logger.info(f"生成时间戳: {timestamp}")
|
||||||
return timestamp
|
return timestamp
|
||||||
|
@ -8,8 +8,18 @@
|
|||||||
# 0 返回本地生成的假结果
|
# 0 返回本地生成的假结果
|
||||||
# 1 原样返回官方服务器的结果
|
# 1 原样返回官方服务器的结果
|
||||||
useOfficialServer = 0
|
useOfficialServer = 0
|
||||||
# 本地生成假结果时候,总是返回这个UID
|
|
||||||
DUMMY_USER_ID = 10086
|
from loguru import logger
|
||||||
|
# 解析命令行参数,作为用户 ID
|
||||||
|
import argparse
|
||||||
|
try:
|
||||||
|
parser = argparse.ArgumentParser(description="舞萌DX AimeDB 服务器模拟实现")
|
||||||
|
parser.add_argument("userId", type=int, help="用户 ID")
|
||||||
|
args = parser.parse_args()
|
||||||
|
DUMMY_USER_ID = args.userId
|
||||||
|
except:
|
||||||
|
logger.warning("未传入用户 ID,使用默认值")
|
||||||
|
DUMMY_USER_ID = 1
|
||||||
|
|
||||||
from fastapi import (
|
from fastapi import (
|
||||||
FastAPI,
|
FastAPI,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user