[Python] 纯文本查看 复制代码 import json
import requests
import re
import time
COOKIE = "cookie信息"#注意,一定要填写
DINGTALK_WEBHOOK = "YOUR_DINGTALK_WEBHOOK"
WXWORK_WEBHOOK = "YOUR_WXWORK_WEBHOOK"
SERVER_CHAN_KEY = "YOUR_SERVER_CHAN_KEY"
def main():
try:
if COOKIE is None:
print("COOKIE 环境变量未设置")
return
startTime = time.time()
cookie = format_cookie(COOKIE)
sign_result = send_sign_in_request(cookie)
endTime = time.time()
print("耗时: {}ms".format(int((endTime - startTime) * 1000)))
print("签到结果: {}".format(json.dumps(sign_result).encode().decode('unicode_escape').encode('utf-8').decode('utf-8')))
#publish_wechat(SERVER_CHAN_KEY, sign_result, int((endTime - startTime) * 1000))##推送信息函数
except Exception as e:
print(e)
def send_sign_in_request(cookie):
sign = get_sign_key(cookie)
url = "https://www.hifini.com/sg_sign.htm"
headers = {
"Cookie": cookie,
"User-Agent": "YOUR_USER_AGENT",
"X-Requested-With": "XMLHttpRequest"
}
data = {
"sign": sign
}
response = requests.post(url, headers=headers, data=data)
response_data = response.json()
return response_data
def get_sign_key(cookie):
url = "https://www.hifini.com/sg_sign.htm"
headers = {
"Cookie": cookie,
"User-Agent": "YOUR_USER_AGENT"
}
response = requests.get(url, headers=headers)
response_text = response.text
if "请登录" in response_text:
raise Exception("cookie失效")
pattern = re.compile(r'var sign = "(.*?)"')
match = pattern.search(response_text)
if match:
sign_value = match.group(1)
print("Sign的值是: {}".format(sign_value))
return sign_value
else:
raise Exception("未能获取sign,请检查cookie是否失效")
def format_cookie(cookie):
bbs_sid = None
bbs_token = None
cookie_split = cookie.split(";")
for item in cookie_split:
item = item.strip()
if "bbs_sid" in item:
bbs_sid = item
elif "bbs_token" in item:
bbs_token = item
if bbs_sid is not None and bbs_token is not None:
return bbs_sid + ";" + bbs_token + ";"
else:
raise Exception("未能解析cookie")
def publish_wechat(server_chan_key, sign_result_vo, duration):
if server_chan_key is None:
print("SERVER_CHAN 未设置")
return
title = "HiFiNi签到成功" if "成功签到" in sign_result_vo["message"] else "HiFiNi签到失败"
if duration is not None:
title += f",耗时 {duration}ms"
try:
title_encoded = urllib.parse.quote(title)
message_encoded = urllib.parse.quote(sign_result_vo["message"])
url = f"https://sctapi.ftqq.com/{server_chan_key}.send?title={title_encoded}&desp={message_encoded}"
response = requests.get(url)
response.raise_for_status()
except Exception as e:
print(e)
# 其他方法的定义,如 generate_dynamic_key, simple_encrypt, publish_wechat 等
if __name__ == "__main__":
main()
|