2021-05-24 08:16:52 +00:00
|
|
|
|
import uuid
|
2021-05-23 13:24:20 +00:00
|
|
|
|
import time
|
2021-05-24 08:16:52 +00:00
|
|
|
|
import config
|
2021-05-23 13:24:20 +00:00
|
|
|
|
import random
|
|
|
|
|
import string
|
|
|
|
|
import hashlib
|
|
|
|
|
import setting
|
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
|
|
|
|
|
# md5计算
|
2022-01-06 05:49:25 +00:00
|
|
|
|
def md5(text: str) -> str:
|
2021-05-23 13:24:20 +00:00
|
|
|
|
md5 = hashlib.md5()
|
|
|
|
|
md5.update(text.encode())
|
2021-06-06 13:19:28 +00:00
|
|
|
|
return md5.hexdigest()
|
2021-05-23 13:24:20 +00:00
|
|
|
|
|
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
# 随机文本
|
2022-01-06 05:49:25 +00:00
|
|
|
|
def random_text(num: int) -> str:
|
2021-10-25 14:53:34 +00:00
|
|
|
|
return ''.join(random.sample(string.ascii_lowercase + string.digits, num))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 时间戳
|
2022-01-06 05:49:25 +00:00
|
|
|
|
def timestamp() -> int:
|
2021-06-06 13:19:28 +00:00
|
|
|
|
return int(time.time())
|
2021-05-23 13:24:20 +00:00
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
|
|
|
|
|
# 获取请求Header里的DS 当web为true则生成网页端的DS
|
2022-08-05 04:25:10 +00:00
|
|
|
|
def get_ds(web: bool) -> str:
|
2021-09-30 13:00:12 +00:00
|
|
|
|
if web:
|
2022-08-05 04:25:10 +00:00
|
|
|
|
n = setting.mihoyobbs_Salt_web
|
2021-05-23 13:24:20 +00:00
|
|
|
|
else:
|
|
|
|
|
n = setting.mihoyobbs_Salt
|
2022-01-06 05:49:25 +00:00
|
|
|
|
i = str(timestamp())
|
|
|
|
|
r = random_text(6)
|
|
|
|
|
c = md5("salt=" + n + "&t=" + i + "&r=" + r)
|
2021-06-06 13:19:28 +00:00
|
|
|
|
return f"{i},{r},{c}"
|
2021-05-23 13:24:20 +00:00
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
|
2022-08-18 11:07:35 +00:00
|
|
|
|
# 获取请求Header里的DS(版本2) 这个版本ds之前见到都是查询接口里的
|
|
|
|
|
def get_ds2(q: str, b: str) -> str:
|
|
|
|
|
n = setting.mihoyobbs_Salt2
|
|
|
|
|
i = str(timestamp())
|
|
|
|
|
r = str(random.randint(100001, 200000))
|
|
|
|
|
add = f'&b={b}&q={q}'
|
|
|
|
|
c = md5("salt=" + n + "&t=" + i + "&r=" + r + add)
|
|
|
|
|
return f"{i},{r},{c}"
|
|
|
|
|
|
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
# 生成一个device id
|
2022-01-06 05:49:25 +00:00
|
|
|
|
def get_device_id() -> str:
|
2022-08-13 02:51:04 +00:00
|
|
|
|
return str(uuid.uuid3(uuid.NAMESPACE_URL, config.config["account"]["cookie"]))
|
2021-10-25 14:53:34 +00:00
|
|
|
|
|
2022-08-27 13:51:38 +00:00
|
|
|
|
# 生成一个device id
|
|
|
|
|
def get_cloud_device_id() -> str:
|
|
|
|
|
return str(uuid.uuid3(uuid.NAMESPACE_URL, "ai=4;ci=1;oi=74192553;ct=78851ef4251e14fb45659a5276370b819ab9f47b;si=f8bc714db618c290b05c1949c654e6e4fb38edb49831e3a2b75455dfa8812320;bi=hk4e_cn"))
|
2021-05-24 08:16:52 +00:00
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
# 获取签到的奖励名称
|
2022-01-06 05:49:25 +00:00
|
|
|
|
def get_item(raw_data: dict) -> str:
|
|
|
|
|
temp_name = raw_data["name"]
|
|
|
|
|
temp_cnt = raw_data["cnt"]
|
|
|
|
|
return f"{temp_name}x{temp_cnt}"
|
2021-06-06 13:58:03 +00:00
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
|
|
|
|
|
# 获取明天早晨0点的时间戳
|
2022-04-24 05:06:26 +00:00
|
|
|
|
def next_day() -> int:
|
2021-05-23 13:24:20 +00:00
|
|
|
|
now_time = int(time.time())
|
2022-04-24 05:06:26 +00:00
|
|
|
|
next_day_time = now_time - now_time % 86400 + time.timezone + 86400
|
|
|
|
|
return next_day_time
|
2021-06-14 00:05:37 +00:00
|
|
|
|
|
2021-10-25 14:53:34 +00:00
|
|
|
|
|
|
|
|
|
# 获取Openssl版本
|
2022-01-06 05:49:25 +00:00
|
|
|
|
def get_openssl_version() -> int:
|
2021-06-18 13:41:30 +00:00
|
|
|
|
try:
|
|
|
|
|
import ssl
|
|
|
|
|
except ImportError:
|
2022-01-06 05:49:25 +00:00
|
|
|
|
from loghelper import log
|
2021-06-18 13:41:30 +00:00
|
|
|
|
log.error("Openssl Lib Error !!")
|
2021-10-25 14:53:34 +00:00
|
|
|
|
# return -99
|
|
|
|
|
# 建议直接更新Python的版本,有特殊情况请提交issues
|
2021-06-18 13:41:30 +00:00
|
|
|
|
exit(-1)
|
2022-01-06 05:49:25 +00:00
|
|
|
|
temp_list = ssl.OPENSSL_VERSION_INFO
|
|
|
|
|
return int(f"{str(temp_list[0])}{str(temp_list[1])}{str(temp_list[2])}")
|