-
Notifications
You must be signed in to change notification settings - Fork 40
/
fudanDaily-gkj.py
125 lines (96 loc) · 3.76 KB
/
fudanDaily-gkj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import os
import sys
import json
import time
import hashlib
import requests
from bs4 import BeautifulSoup
USERNAME = os.getenv("USERNAME")
PASSWORD = os.getenv("PASSWORD")
PUSH_KEY = os.getenv("PUSH_KEY")
fudan_daily_url = "https://zlapp.fudan.edu.cn/site/ncov/fudanDaily"
login_url = "https://uis.fudan.edu.cn/authserver/login?service=https%3A%2F%2Fzlapp.fudan.edu.cn%2Fa_fudanzlapp%2Fapi%2Fsso%2Findex%3Fredirect%3Dhttps%253A%252F%252Fzlapp.fudan.edu.cn%252Fsite%252Fncov%252FfudanDaily%26from%3Dwap"
get_info_url = "https://zlapp.fudan.edu.cn/ncov/wap/fudan/get-info"
save_log_url = "https://zlapp.fudan.edu.cn/wap/log/save-log"
save_url = "https://zlapp.fudan.edu.cn/ncov/wap/fudan/save"
def get_session(_login_info):
_session = requests.Session()
_session.headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/7.0.18(0x17001229) NetType/WIFI Language/zh_CN miniProgram"
_response = _session.get(login_url)
soup = BeautifulSoup(_response.text, "lxml")
inputs = soup.find_all("input")
for i in inputs:
if i.get("name") and i.get("name") not in ["username", "password", "captchaResponse"]:
_login_info[i.get("name")] = i.get("value")
_session.post(login_url, data=_login_info)
_session.headers["Origin"] = "https://zlapp.fudan.edu.cn"
_session.headers["Referer"] = fudan_daily_url
return _session
def get_historical_info(_session):
response = session.get(get_info_url)
return json.loads(response.text)["d"]
def save_log(_session):
_data = {
"appkey": "ncov",
"url": fudan_daily_url,
"timestamp": int(time.time())
}
_data["signature"] = hashlib.md5((_data["appkey"] + str(_data["timestamp"]) + _data["url"]).encode()).hexdigest()
_session.post(save_log_url, data=_data)
def get_payload(_historical_info):
_payload = _historical_info["info"]
if "jrdqjcqk" in _payload:
_payload.pop("jrdqjcqk")
if "jrdqtlqk" in _payload:
_payload.pop("jrdqtlqk")
_payload.update({
"ismoved": 0,
"number": _historical_info["uinfo"]["role"]["number"],
"realname": _historical_info["uinfo"]["realname"],
"area": _historical_info["oldInfo"]["area"],
"city": _historical_info["oldInfo"]["city"],
"province": _historical_info["oldInfo"]["province"],
"sfhbtl": 0,
"sfjcgrq": 0
})
return _payload
def get_payload_str(_payload):
_ = _payload.copy()
_["geo_api_info"] = json.loads(_["geo_api_info"])
return json.dumps(_, ensure_ascii=False)
def save(_session, _payload):
return _session.post(save_url, data=_payload)
def notify(_status, _message):
if not PUSH_KEY:
return
_d = {
"desp": _message
}
if _status:
_d["text"] = "打卡成功-GKJ"
else:
_d["text"] = "打卡失败,请手动打卡-GKJ"
requests.post(f"https://sc.ftqq.com/{PUSH_KEY}.send", data=_d)
if __name__ == "__main__":
if not USERNAME or not PASSWORD:
notify(False, "GKJ-请正确配置用户名和密码!")
sys.exit()
login_info = {
"username": USERNAME,
"password": PASSWORD
}
try:
session = get_session(login_info)
historical_info = get_historical_info(session)
save_log(session)
payload = get_payload(historical_info)
payload_str = get_payload_str(payload)
# print(payload_str)
time.sleep(5)
response = save(session, payload)
if response.status_code == 200 and response.text == '{"e":0,"m":"GKJ-操作成功","d":{}}':
notify(True, payload_str)
else:
notify(False, response.text)
except Exception as e:
notify(False, str(e))