84 lines
2.2 KiB
Python
84 lines
2.2 KiB
Python
# 登录·登出实现
|
|
# 一般作为模块使用,但也可以作为 CLI 程序运行以强制登出账号。
|
|
|
|
import time
|
|
import random
|
|
|
|
import rapidjson as json
|
|
from loguru import logger
|
|
|
|
from API_TitleServer import apiSDGB
|
|
from Config import (
|
|
clientId,
|
|
placeId,
|
|
regionId,
|
|
)
|
|
from MyConfig import testUid
|
|
|
|
|
|
def apiLogin(timestamp: int, userId: int, noLog: bool = False) -> dict:
|
|
"""登录,返回 dict"""
|
|
data = json.dumps(
|
|
{
|
|
"userId": userId,
|
|
"accessCode": "",
|
|
"regionId": regionId,
|
|
"placeId": placeId,
|
|
"clientId": clientId,
|
|
"dateTime": timestamp,
|
|
"isContinue": False,
|
|
"genericFlag": 0,
|
|
}
|
|
)
|
|
login_result = json.loads(apiSDGB(data, "UserLoginApi", userId, noLog))
|
|
if not noLog:
|
|
logger.info("登录:结果:" + str(login_result))
|
|
return login_result
|
|
|
|
|
|
def apiLogout(timestamp: int, userId: int, noLog: bool = False) -> dict:
|
|
"""登出,返回 dict"""
|
|
data = json.dumps(
|
|
{
|
|
"userId": userId,
|
|
"accessCode": "",
|
|
"regionId": regionId,
|
|
"placeId": placeId,
|
|
"clientId": clientId,
|
|
"dateTime": timestamp,
|
|
"type": 1,
|
|
}
|
|
)
|
|
logout_result = json.loads(apiSDGB(data, "UserLogoutApi", userId, noLog))
|
|
if not noLog:
|
|
logger.info("登出:结果:" + str(logout_result))
|
|
return logout_result
|
|
|
|
|
|
def generateTimestampLegacy() -> int:
|
|
"""生成一个凑合用的时间戳"""
|
|
timestamp = int(time.time()) - 60
|
|
logger.info(f"生成时间戳: {timestamp}")
|
|
return timestamp
|
|
|
|
|
|
def generateTimestamp() -> int:
|
|
"""生成一个今天早上 10:00 随机偏移的时间戳"""
|
|
timestamp = int(
|
|
time.mktime(
|
|
time.strptime(time.strftime("%Y-%m-%d 10:00:00"), "%Y-%m-%d %H:%M:%S")
|
|
)
|
|
) + random.randint(-600, 600)
|
|
logger.info(f"生成时间戳: {timestamp}")
|
|
logger.info(
|
|
f"此时间戳对应的时间为: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))}"
|
|
)
|
|
return timestamp
|
|
|
|
|
|
if __name__ == "__main__":
|
|
print("强制登出 CLI")
|
|
uid = testUid
|
|
timestamp = input("Timestamp: ")
|
|
apiLogout(int(timestamp), int(uid))
|