-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoSign.py
303 lines (272 loc) · 9.17 KB
/
autoSign.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
# -*- coding: utf-8 -*-
import requests
import sys
import json
from datetime import datetime, timedelta, timezone
import time
from dingtalkchatbot.chatbot import DingtalkChatbot
def getTimeStr():
utc_dt = datetime.utcnow().replace(tzinfo=timezone.utc)
bj_dt = utc_dt.astimezone(timezone(timedelta(hours=8)))
return bj_dt.strftime("%Y-%m-%d %H:%M:%S")
def log(content):
print(getTimeStr() + ' ' + str(content))
sys.stdout.flush()
urls = {
'login': 'https://xcx.xybsyw.com/login/login!wx.action',
'loadAccount': 'https://xcx.xybsyw.com/account/LoadAccountInfo.action',
'ip': 'https://xcx.xybsyw.com/behavior/Duration!getIp.action',
'trainId': 'https://xcx.xybsyw.com/student/clock/GetPlan!getDefault.action',
# 'position':'https://xcx.xybsyw.com/student/clock/GetPlan!detail.action',
'sign': 'https://app.xybsyw.com/behavior/Duration.action',
'autoSign': 'https://xcx.xybsyw.com/student/clock/Post!autoClock.action',
'newSign': 'https://xcx.xybsyw.com/student/clock/PostNew!updateClock.action',
'status': 'https://xcx.xybsyw.com/student/clock/GetPlan!detail.action'
}
host1 = 'xcx.xybsyw.com'
host2 = 'app.xybsyw.com'
# 获取小程序用户唯一标识openId
def getOpenId(userInfo):
data = {
'openId': userInfo['token']['openId'],
'unionId': userInfo['token']['unionId']
}
return data
# 获取Header
def getHeader(host):
userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36 MicroMessenger/7.0.9.501 NetType/WIFI MiniProgramEnv/Windows WindowsWechat'
contentType = 'application/x-www-form-urlencoded'
headers = {
'user-agent': userAgent,
'content-type': contentType,
'host': host,
'Connection': 'keep-alive'
}
return headers
# 登录获取sessionId和loginerId
def login(userInfo):
data = getOpenId(userInfo)
headers = getHeader(host1)
url = urls['login']
resp = requests.post(url=url, headers=headers, data=data).json()
if('成功' in resp['msg']):
ret = {
'sessionId': resp['data']['sessionId'],
'loginerId': resp['data']['loginerId']
}
log(f"sessionId:{resp['data']['sessionId']}获取成功")
log(f"loginerId:{resp['data']['loginerId']}获取成功")
return ret
else:
log('登录失败')
exit(-1)
# 获取username
def getUsername(sessionId):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['loadAccount']
resp = requests.post(url=url, headers=headers).json()
if('成功' in resp['msg']):
ret = resp['data']['loginer']
log(f"username:{ret}获取成功")
return ret
else:
log('获取username失败')
exit(-1)
# 获取ip
def getIP(sessionId):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['ip']
resp = requests.post(url=url, headers=headers).json()
if('success' in resp['msg']):
ret = resp['data']['ip']
log(f'ip:{ret}获取成功')
return ret
else:
log('ip获取失败')
exit(-1)
# 获取trainID
def getTrainID(sessionId):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['trainId']
resp = requests.post(url=url, headers=headers).json()
if('成功' in resp['msg']):
ret = resp['data']['clockVo']['traineeId']
log(f'traineeId:{ret}获取成功')
return ret
else:
log('trainid获取失败')
exit(-1)
# 获取经纬度\签到地址
def getPosition(sessionId, trainId):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['status']
data = {
'traineeId': trainId
}
resp = requests.post(url=url, headers=headers, data=data).json()
if('成功' in resp['msg']):
address = resp['data']['postInfo']['address']
lat = resp['data']['postInfo']['lat']
lng = resp['data']['postInfo']['lng']
ret = {
'lat': lat,
'lng': lng
}
log(f'经度:{lng}|纬度:{lat}')
log(f'签到地址:{address}')
return ret
else:
log('经纬度获取失败')
exit(-1)
def getSignForm(data, user):
timeStamp = int(time.time())
form = {
'login': '1',
'appVersion': '1.5.75',
'operatingSystemVersion': '10',
'deviceModel': 'microsoft',
'operatingSystem': 'android',
'screenWidth': '415',
'screenHeight': '692',
'reportSrc': '2',
'eventTime': timeStamp,
'eventType': 'click',
'eventName': 'clickSignEvent',
'clientIP': data['ip'],
'pageId': data['pageId'], # 30
'itemID': 'none',
'itemType': '其他',
'stayTime': 'none',
'deviceToken': user['token']['openId'],
'netType': 'WIFI',
'app': 'wx_student',
'preferName': '成长',
'pageName': '成长-签到',
'userName': data['userName'],
'userId': data['loginerId'],
'province': user['location']['province'],
'country': user['location']['country'],
'city': user['location']['city'],
}
return form
# 判断userinfo.json信息是否完整
def isComplete():
with open('../user.json', 'r', encoding='utf8') as fp:
user = json.load(fp)
if(user['location']['province'] == "" or user['location']['province'] == "" or user['locatuin']['city'] == ""):
log("请完善user.json中的location信息")
exit(-1)
if(user['token']['openId'] == "" or user['token']['unionId'] == ""):
log("请完善user.json中的token信息")
exit(-1)
fp.close()
return True
# 签到请求
def signReq(sessionId, data):
headers = getHeader(host2)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['sign']
resp = requests.post(url=url, headers=headers, data=data).json()
if ('success' in resp['msg']):
log(f'签到请求执行成功')
else:
log('签到请求执行失败')
exit(-1)
# 执行签到
def autoSign(sessionId, data):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['autoSign']
resp = requests.post(url=url, headers=headers, data=data).json()
log(resp['msg'])
return resp['msg']
# 重新签到
def newSign(sessionId, data):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['newSign']
resp = requests.post(url=url, headers=headers, data=data).json()
log(resp['msg'])
return resp['msg']
# 获取签到状态
def getSignStatus(sessionId, trainId):
headers = getHeader(host1)
headers['cookie'] = f'JSESSIONID={sessionId}'
url = urls['status']
data = {
'traineeId': trainId
}
resp = requests.post(url=url, headers=headers, data=data).json()
# if(resp['data']['clockInfo']['status'] == 0):
if(len(resp['data']['clockInfo']['inTime']) > 0):
return True
else:
return False
# 获取用户信息
def getUserInfo():
with open('user.json', 'r', encoding='utf8') as fp:
user = json.load(fp)
fp.close()
return user
# 钉钉机器人通知
def sendDingDing(msg):
log('正在发送钉钉机器人通知...')
userInfo = getUserInfo()
# WebHook地址
webhook = 'https://oapi.dingtalk.com/robot/send?access_token={0}'.format(userInfo['DingDingtoken'])
secret = '{0}'.format(userInfo['DingDingsecret'])
# 可选:创建机器人勾选“加签”选项时使用
# 初始化机器人
xiaoding = DingtalkChatbot(webhook, secret=secret) # 方式二:勾选“加签”选项时使用(v1.5以上新功能)
xiaoding.send_text(str(msg), is_at_all=False)
def main():
userInfo = getUserInfo()
sessions = login(userInfo)
sessionId = sessions['sessionId']
loginerId = sessions['loginerId']
trainId = getTrainID(sessionId)
userName = getUsername(sessionId)
ip = getIP(sessionId)
position = getPosition(sessionId, trainId)
lng = position['lng']
lat = position['lat']
data = {
'pageId': '30',
'userName': userName,
'loginerId': loginerId,
'ip': ip
}
formData = getSignForm(data, userInfo)
signReq(sessionId, formData)
signFormData = {
'traineeId': trainId,
'adcode': userInfo['location']['adcode'],
'lat': lat,
'lng': lng,
'address': userInfo['location']['address'],
'deviceName': 'microsoft',
'punchInStatus': '1',
'clockStatus': '2',
'imgUrl': '',
'reason': userInfo['reason']
}
if(getSignStatus(sessionId, trainId)):
log('已签到,执行重新签到')
newSign(sessionId, signFormData)
else:
autoSign(sessionId, signFormData)
if (getSignStatus(sessionId, trainId)):
sendDingDing('校友邦实习任务已签到')
log('校友邦实习任务已签到')
else:
sendDingDing('校友邦实习任务签到失败!')
log('校友邦实习任务签到失败!')
#腾讯云函数使用
def main_handler(event, context):
main()
if __name__ == '__main__':
main()