mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
66 lines
1.5 KiB
Python
66 lines
1.5 KiB
Python
import uuid
|
|
import time
|
|
import random
|
|
import string
|
|
import hashlib
|
|
from .setting import *
|
|
|
|
|
|
# md5计算
|
|
def md5(text: str) -> str:
|
|
md5 = hashlib.md5()
|
|
md5.update(text.encode())
|
|
return md5.hexdigest()
|
|
|
|
|
|
# 随机文本
|
|
def random_text(num: int) -> str:
|
|
return ''.join(random.sample(string.ascii_lowercase + string.digits, num))
|
|
|
|
|
|
# 时间戳
|
|
def timestamp() -> int:
|
|
return int(time.time())
|
|
|
|
|
|
# 获取请求Header里的DS 当web为true则生成网页端的DS
|
|
def get_ds(web: bool) -> str:
|
|
if web:
|
|
n = mihoyobbs_Salt_web
|
|
else:
|
|
n = mihoyobbs_Salt
|
|
i = str(timestamp())
|
|
r = random_text(6)
|
|
c = md5("salt=" + n + "&t=" + i + "&r=" + r)
|
|
return f"{i},{r},{c}"
|
|
|
|
|
|
# 获取请求Header里的DS(版本2) 这个版本ds之前见到都是查询接口里的
|
|
def get_ds2(q: str, b: str) -> str:
|
|
n = 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}"
|
|
|
|
|
|
# 生成一个device id
|
|
def get_device_id(cookie) -> str:
|
|
return str(uuid.uuid3(uuid.NAMESPACE_URL, cookie))
|
|
|
|
|
|
# 获取签到的奖励名称
|
|
def get_item(raw_data: dict) -> str:
|
|
temp_name = raw_data["name"]
|
|
temp_cnt = raw_data["cnt"]
|
|
return f"{temp_name}x{temp_cnt}"
|
|
|
|
|
|
# 获取明天早晨0点的时间戳
|
|
def next_day() -> int:
|
|
now_time = int(time.time())
|
|
next_day_time = now_time - now_time % 86400 + time.timezone + 86400
|
|
return next_day_time
|
|
|