forked from ReaJason/17wanxiaoCheckin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17wanxiao.py
461 lines (419 loc) · 17.1 KB
/
17wanxiao.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
import time
import datetime
import json
import logging
import requests
from login import CampusCard
def initLogging():
logging.getLogger().setLevel(logging.INFO)
logging.basicConfig(format="[%(levelname)s]; %(message)s")
def get_token(username, password):
"""
获取用户令牌,模拟登录获取:https://github.com/zhongbr/wanmei_campus
:param username: 账号
:param password: 密码
:return:
"""
user_dict = CampusCard(username, password).user_info
if not user_dict['login']:
return None
return user_dict["sessionId"]
def get_post_json(jsons):
"""
获取打卡数据
:param jsons: 用来获取打卡数据的json字段
:return:
"""
retry = 0
while retry < 3:
try:
res = requests.post(url="https://reportedh5.17wanxiao.com/sass/api/epmpics", json=jsons, timeout=10).json()
# print(res)
except:
retry += 1
logging.warning('获取完美校园打卡post参数失败,正在重试...')
time.sleep(1)
continue
if res['code'] != '10000':
# logging.warning(res)
return None
data = json.loads(res['data'])
# print(data)
post_dict = {
"areaStr": data['areaStr'],
"deptStr": data['deptStr'],
"deptid": data['deptStr']['deptid'],
"customerid": data['customerid'],
"userid": data['userid'],
"username": data['username'],
"stuNo": data['stuNo'],
"phonenum": data['phonenum'],
"templateid": data['templateid'],
"updatainfo": [{"propertyname": i["propertyname"], "value": i["value"]} for i in
data['cusTemplateRelations']],
"checkbox": [{"description": i["decription"], "value": i["value"]} for i in
data['cusTemplateRelations']],
}
# print(json.dumps(post_dict, sort_keys=True, indent=4, ensure_ascii=False))
logging.info('获取完美校园打卡post参数成功')
return post_dict
return None
def receive_check_in(token, custom_id, post_dict):
"""
第二类健康打卡
:param token: 用户令牌
:param custom_id: 健康打卡id
:param post_dict: 健康打卡数据
:return:
"""
check_json = {
"userId": post_dict['userId'],
"name": post_dict['name'],
"stuNo": post_dict['stuNo'],
"whereabouts": post_dict['whereabouts'],
"familyWhereabouts": "",
"beenToWuhan": post_dict['beenToWuhan'],
"contactWithPatients": post_dict['contactWithPatients'],
"symptom": post_dict['symptom'],
"fever": post_dict['fever'],
"cough": post_dict['cough'],
"soreThroat": post_dict['soreThroat'],
"debilitation": post_dict['debilitation'],
"diarrhea": post_dict['diarrhea'],
"cold": post_dict['cold'],
"staySchool": post_dict['staySchool'],
"contacts": post_dict['contacts'],
"emergencyPhone": post_dict['emergencyPhone'],
"address": post_dict['address'],
"familyForAddress": "",
"collegeId": post_dict['collegeId'],
"majorId": post_dict['majorId'],
"classId": post_dict['classId'],
"classDescribe": post_dict['classDescribe'],
"temperature": post_dict['temperature'],
"confirmed": post_dict['confirmed'],
"isolated": post_dict['isolated'],
"passingWuhan": post_dict['passingWuhan'],
"passingHubei": post_dict['passingHubei'],
"patientSide": post_dict['patientSide'],
"patientContact": post_dict['patientContact'],
"mentalHealth": post_dict['mentalHealth'],
"wayToSchool": post_dict['wayToSchool'],
"backToSchool": post_dict['backToSchool'],
"haveBroadband": post_dict['haveBroadband'],
"emergencyContactName": post_dict['emergencyContactName'],
"helpInfo": "",
"passingCity": "",
"longitude": "", # 请在此处填写需要打卡位置的longitude
"latitude": "", # 请在此处填写需要打卡位置的latitude
"token": token,
}
headers = {
'referer': f'https://reportedh5.17wanxiao.com/nCovReport/index.html?token={token}&customerId={custom_id}',
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8'
}
try:
res = requests.post("https://reportedh5.17wanxiao.com/api/reported/receive", headers=headers, data=check_json).json()
# 以json格式打印json字符串
# print(res)
if res['code'] == 0:
logging.info(res)
return dict(status=1, res=res, post_dict=post_dict, check_json=check_json, type='healthy')
else:
logging.warning(res)
return dict(status=1, res=res, post_dict=post_dict, check_json=check_json, type='healthy')
except:
errmsg = f"```打卡请求出错```"
logging.warning('打卡请求出错,网络不稳定')
return dict(status=0, errmsg=errmsg)
def get_recall_data(token):
"""
获取第二类健康打卡的打卡数据
:param token: 用户令牌
:return: 返回dict数据
"""
retry = 0
while retry < 3:
try:
res = requests.post(url="https://reportedh5.17wanxiao.com/api/reported/recall", data={"token": token}, timeout=10).json()
except:
retry += 1
logging.warning('获取完美校园打卡post参数失败,正在重试...')
time.sleep(1)
continue
if res['code'] == 0:
logging.info('获取完美校园打卡post参数成功')
return res['data']
return None
return None
def healthy_check_in(token, post_dict):
"""
第一类健康打卡
:param token: 用户令牌
:param post_dict: 打卡数据
:return:
"""
check_json = {"businessType": "epmpics", "method": "submitUpInfo",
"jsonData": {"deptStr": post_dict['deptStr'], "areaStr": post_dict['areaStr'],
"reportdate": round(time.time() * 1000), "customerid": post_dict['customerid'],
"deptid": post_dict['deptid'], "source": "app",
"templateid": post_dict['templateid'], "stuNo": post_dict['stuNo'],
"username": post_dict['username'], "phonenum": post_dict['phonenum'],
"userid": post_dict['userid'], "updatainfo": post_dict['updatainfo'],
"gpsType": 1, "token": token},
}
try:
res = requests.post("https://reportedh5.17wanxiao.com/sass/api/epmpics", json=check_json).json()
# 以json格式打印json字符串
if res['code'] != '10000':
logging.warning(res)
return dict(status=1, res=res, post_dict=post_dict, check_json=check_json, type='healthy')
else:
logging.info(res)
return dict(status=1, res=res, post_dict=post_dict, check_json=check_json, type='healthy')
except:
errmsg = f"```打卡请求出错```"
logging.warning('校内打卡请求出错')
return dict(status=0, errmsg=errmsg)
def campus_check_in(username, token, post_dict, id):
"""
校内打卡
:param username: 电话号
:param token: 用户令牌
:param post_dict: 校内打卡数据
:param id: 校内打卡id
:return:
"""
check_json = {"businessType": "epmpics", "method": "submitUpInfoSchool",
"jsonData": {"deptStr": post_dict['deptStr'],
"areaStr": post_dict['areaStr'],
"reportdate": round(time.time() * 1000), "customerid": post_dict['customerid'],
"deptid": post_dict['deptid'], "source": "app",
"templateid": post_dict['templateid'], "stuNo": post_dict['stuNo'],
"username": post_dict['username'], "phonenum": username,
"userid": post_dict['userid'], "updatainfo": post_dict['updatainfo'],
"customerAppTypeRuleId": id, "clockState": 0, "token": token},
"token": token
}
# print(check_json)
try:
res = requests.post("https://reportedh5.17wanxiao.com/sass/api/epmpics", json=check_json).json()
# 以json格式打印json字符串
if res['code'] != '10000':
logging.warning(res)
return dict(status=1, res=res, post_dict=post_dict, check_json=check_json, type=post_dict['templateid'])
else:
logging.info(res)
return dict(status=1, res=res, post_dict=post_dict, check_json=check_json, type=post_dict['templateid'])
except BaseException:
errmsg = f"```校内打卡请求出错```"
logging.warning('校内打卡请求出错')
return dict(status=0, errmsg=errmsg)
def check_in(username, password):
# 登录获取token用于打卡
token = get_token(username, password)
# print(token)
check_dict_list = []
# 获取现在是上午,还是下午,还是晚上
ape_list = get_ap()
# 获取学校使用打卡模板Id
custom_id_dict = get_custom_id(token)
if not token:
errmsg = f"{username[:4]},获取token失败,打卡失败"
logging.warning(errmsg)
return False
# 获取第一类健康打卡的参数
json1 = {"businessType": "epmpics",
"jsonData": {"templateid": "pneumonia", "token": token},
"method": "userComeApp"}
post_dict = get_post_json(json1)
if post_dict:
# 第一类健康打卡
# print(post_dict)
# 修改温度等参数
# for j in post_dict['updatainfo']: # 这里获取打卡json字段的打卡信息,微信推送的json字段
# if j['propertyname'] == 'temperature': # 找到propertyname为temperature的字段
# j['value'] = '36.2' # 由于原先为null,这里直接设置36.2(根据自己学校打卡选项来)
# if j['propertyname'] == '举一反三即可':
# j['value'] = '举一反三即可'
# 修改地址,依照自己完美校园,查一下地址即可
# post_dict['areaStr'] = '{"streetNumber":"89号","street":"建设东路","district":"","city":"新乡市","province":"河南省",' \
# '"town":"","pois":"河南师范大学(东区)","lng":113.91572178314209,' \
# '"lat":35.327695868943984,"address":"牧野区建设东路89号河南师范大学(东区)","text":"河南省-新乡市",' \
# '"code":""} '
healthy_check_dict = healthy_check_in(token, post_dict)
check_dict_list.append(healthy_check_dict)
else:
# 获取第二类健康打卡参数
post_dict = get_recall_data(token)
# 第二类健康打卡
healthy_check_dict = receive_check_in(token, custom_id_dict['customerId'], post_dict)
check_dict_list.append(healthy_check_dict)
# 获取校内打卡ID
id_list = get_id_list(token, custom_id_dict['customerAppTypeId'])
# print(id_list)
if not id_list:
return check_dict_list
# 校内打卡
for index, i in enumerate(id_list):
if ape_list[index]:
# print(i)
logging.info(f"-------------------------------{i['templateid']}-------------------------------")
json2 = {"businessType": "epmpics",
"jsonData": {"templateid": i['templateid'], "customerAppTypeRuleId": i['id'],
"stuNo": post_dict['stuNo'],
"token": token}, "method": "userComeAppSchool",
"token": token}
campus_dict = get_post_json(json2)
campus_dict['areaStr'] = post_dict['areaStr']
for j in campus_dict['updatainfo']:
if j['propertyname'] == 'temperature':
j['value'] = '36.4'
if j['propertyname'] == 'symptom':
j['value'] = '无症状'
campus_check_dict = campus_check_in(username, token, campus_dict, i['id'])
check_dict_list.append(campus_check_dict)
logging.info("--------------------------------------------------------------")
return check_dict_list
def server_push(sckey, desp):
"""
Server酱推送:https://sc.ftqq.com/3.version
:param sckey: 通过官网注册获取,获取教程:https://github.com/ReaJason/17wanxiaoCheckin-Actions/blob/master/README_LAST.md#%E4%BA%8Cserver%E9%85%B1%E6%9C%8D%E5%8A%A1%E7%9A%84%E7%94%B3%E8%AF%B7
:param desp: 需要推送的内容
:return:
"""
send_url = f"https://sc.ftqq.com/{sckey}.send"
params = {
"text": "健康打卡推送通知",
"desp": desp
}
# 发送消息
res = requests.post(send_url, data=params)
# {"errno":0,"errmsg":"success","dataset":"done"}
# logging.info(res.text)
try:
if not res.json()['errno']:
logging.info('Server酱推送服务成功')
else:
logging.warning('Server酱推送服务失败')
except:
logging.warning("Server酱不起作用了,可能是你的sckey出现了问题")
def get_custom_id(token):
"""
用来获取custom_id,即类似与打卡模板id
:param token: 用户令牌
:return: return {
'customerId': res.json()['userInfo'].get('customerId'), # 健康打卡模板id
'customerAppTypeId': res.json()['userInfo'].get('customerAppTypeId') # 校内打卡模板id
}
"""
data = {
"appClassify": "DK",
"token": token
}
try:
res = requests.post("https://reportedh5.17wanxiao.com/api/clock/school/getUserInfo", data=data)
# print(res.text)
return {
'customerId': res.json()['userInfo'].get('customerId'),
'customerAppTypeId': res.json()['userInfo'].get('customerAppTypeId')
}
except:
return None
def get_id_list(token, custom_id):
"""
通过校内模板id获取校内打卡具体的每个时间段id
:param token: 用户令牌
:param custom_id: 校内打卡模板id
:return: 返回校内打卡id列表
"""
post_data = {
"customerAppTypeId": custom_id,
"longitude": "",
"latitude": "",
"token": token
}
try:
res = requests.post("https://reportedh5.17wanxiao.com/api/clock/school/rules", data=post_data)
# print(res.text)
return res.json()['customerAppTypeDto']['ruleList']
except:
return None
def get_id_list_v1(token):
"""
通过校内模板id获取校内打卡具体的每个时间段id(初版,暂留)
:param token: 用户令牌
:return: 返回校内打卡id列表
"""
post_data = {
"appClassify": "DK",
"token": token
}
try:
res = requests.post("https://reportedh5.17wanxiao.com/api/clock/school/childApps", data=post_data)
if res.json()['appList']:
id_list = sorted(res.json()['appList'][-1]['customerAppTypeRuleList'], key=lambda x: x['id'])
res_dict = [{'id': j['id'], "templateid": f"clockSign{i + 1}"} for i, j in enumerate(id_list)]
return res_dict
return None
except:
return None
def get_ap():
"""
获取当前时间,用于校内打卡
:return: 返回布尔列表:[am, pm, ev]
"""
now_time = datetime.datetime.now() + datetime.timedelta(hours=8)
am = 0 <= now_time.hour < 12
pm = 12 <= now_time.hour < 17
ev = 17 <= now_time.hour <= 23
return [am, pm, ev]
def run():
initLogging()
now_time = datetime.datetime.now()
bj_time = now_time + datetime.timedelta(hours=8)
log_info = [f"""
------
#### 现在时间:
```
{bj_time.strftime("%Y-%m-%d %H:%M:%S %p")}
```"""]
username_list = input().split(',')
password_list = input().split(',')
sckey = input()
for username, password in zip([i.strip() for i in username_list if i != ''],
[i.strip() for i in password_list if i != '']):
check_dict = check_in(username, password)
if not check_dict:
return
else:
for check in check_dict:
if check['post_dict'].get('checkbox'):
post_msg = "\n".join(
[f"| {i['description']} | {i['value']} |" for i in check['post_dict'].get('checkbox')])
else:
post_msg = "暂无详情"
name = check['post_dict'].get('username')
if not name:
name = check['post_dict']['name']
log_info.append(f"""#### {name}{check['type']}打卡信息:
```
{json.dumps(check['check_json'], sort_keys=True, indent=4, ensure_ascii=False)}
```
------
| Text | Message |
| :----------------------------------- | :--- |
{post_msg}
------
```
{check['res']}
```""")
log_info.append(f"""
>
> [GitHub项目地址](https://github.com/ReaJason/17wanxiaoCheckin-Actions)
>
>期待你给项目的star✨
""")
server_push(sckey, "\n".join(log_info))
if __name__ == '__main__':
run()