mirror of
https://github.com/Remik1r3n/maimaiDX-Api.git
synced 2025-05-20 04:17:28 +08:00
51 lines
1.7 KiB
Python
51 lines
1.7 KiB
Python
from Config import *
|
|
from API_TitleServer import *
|
|
from GetPreview import apiGetUserPreview
|
|
from HelperLogInOut import apiLogout
|
|
import json
|
|
from loguru import logger
|
|
import time
|
|
import datetime
|
|
|
|
def isUserLoggedIn(userId):
|
|
return json.loads(apiGetUserPreview(userId))['isLogin']
|
|
|
|
def logOut(userId, Timestamp):
|
|
try:
|
|
result = apiLogout(Timestamp, userId)
|
|
loadedResult = json.loads(result)
|
|
if loadedResult['returnCode'] == 1:
|
|
return True
|
|
except:
|
|
return False
|
|
|
|
def forceLogout(userId, beginTimestamp):
|
|
# 将人类可读的时间转换为 Unix 时间戳
|
|
original_timestamp = beginTimestamp
|
|
|
|
# 定义时间范围(前后 20 分钟)
|
|
time_range = 20 * 60 # 20 分钟,以秒为单位
|
|
|
|
# 尝试从原始时间戳开始,逐步向两边扩展
|
|
for offset in range(0, time_range + 1):
|
|
# 尝试往前 offset 秒
|
|
timestamp = original_timestamp - offset
|
|
logger.info(f"尝试时间戳: {timestamp}")
|
|
if logout_user(timestamp, userid):
|
|
if not is_user_logged_in(userid):
|
|
print(f"用户 {userid} 已成功登出,使用的时间戳: {timestamp}")
|
|
return
|
|
# 尝试往后 offset 秒
|
|
timestamp = original_timestamp + offset
|
|
if logout_user(timestamp, userid):
|
|
if not is_user_logged_in(userid):
|
|
print(f"用户 {userid} 已成功登出,使用的时间戳: {timestamp}")
|
|
return
|
|
|
|
print(f"无法在前后 20 分钟内登出用户 {userid}")
|
|
|
|
# 示例使用
|
|
userId = testUid
|
|
human_time = "2023-10-01 12:00:00" # 用户输入的人类可读时间
|
|
force_logout(userId, human_time)
|