refactor: module imports
This commit is contained in:
@@ -1,60 +1,81 @@
|
||||
# 登录·登出实现
|
||||
# 一般作为模块使用,但也可以作为 CLI 程序运行以强制登出账号。
|
||||
|
||||
import rapidjson as json
|
||||
import time
|
||||
from loguru import logger
|
||||
import random
|
||||
|
||||
from Config import *
|
||||
from API_TitleServer import apiSDGB
|
||||
import rapidjson as json
|
||||
from loguru import logger
|
||||
|
||||
def apiLogin(timestamp:int, userId:int, noLog:bool=False) -> dict:
|
||||
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,
|
||||
})
|
||||
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))
|
||||
logger.info("登录:结果:" + str(login_result))
|
||||
return login_result
|
||||
|
||||
def apiLogout(timestamp:int, userId:int, noLog:bool=False) -> dict:
|
||||
|
||||
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
|
||||
})
|
||||
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))
|
||||
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)
|
||||
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))}")
|
||||
logger.info(
|
||||
f"此时间戳对应的时间为: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp))}"
|
||||
)
|
||||
return timestamp
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("强制登出 CLI")
|
||||
uid = testUid
|
||||
|
||||
Reference in New Issue
Block a user