-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.py
216 lines (204 loc) · 7.64 KB
/
submit.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
from requests import Session
from requests.utils import cookiejar_from_dict, dict_from_cookiejar
from re import compile, sub
from json import loads, dumps
from os import path
from random import uniform
from datetime import datetime, timedelta
from urllib.parse import quote
from Crypto.Cipher import AES
from base64 import b64encode
from config import HEADERS, PATH
class Submit(object):
def __init__(self, cookies: dict, session = None):
self.headers = HEADERS
self.key = '2knV5VGRTScU7pOq'
self.iv = 'UmNWaNtM0PUdtFCs'
self.cookies = cookies
self.external_session = False
self.session = None
if session == None:
self.external_session = False
self.session = Session() # 请求会话
self.session.cookies = cookiejar_from_dict(self.cookies)
self.session.keep_alive = False
self.session.headers = self.headers
else:
self.external_session = True
self.session = session
self.date = str(datetime.now().strftime('%Y-%m-%d %H:%M'))
def __del__(self):
if self.external_session == False:
self.session.close()
def get(self) -> dict:
task = dict()
self.session.headers['Origin'] = 'https://app.uyiban.com'
self.session.headers['Referer'] = 'https://app.uyiban.com/'
result = loads(
self.session.get(
url = 'https://api.uyiban.com/officeTask/client/index/uncompletedList',
params = {
'StartTime': datetime.strftime(
datetime.now() - timedelta(days = 20),
'%Y-%m-%d %H:%M'
),
'EndTime': datetime.strftime(
datetime.now() + timedelta(days = 5),
'%Y-%m-%d %H:%M'
),
'CSRF': self.cookies['csrf_token']
},
allow_redirects = False
).content
)
if result['code'] != 0: return dict(errmsg = result['msg'])
for i in result['data']: task[i['TaskId']] = i['Title']
return task
def get_wfid(self, taskId: str) -> dict:
self.session.headers['Origin'] = 'https://app.uyiban.com'
self.session.headers['Referer'] = 'https://app.uyiban.com/'
return loads(
self.session.get(
url = 'https://api.uyiban.com/officeTask/client/index/detail',
params = {
'TaskId': taskId,
'CSRF': dict_from_cookiejar(self.session.cookies)['csrf_token']
},
allow_redirects = False
).content
)
def get_processid(self, wfid: str) -> str:
self.session.headers['Origin'] = 'https://app.uyiban.com'
self.session.headers['Referer'] = 'https://app.uyiban.com/'
return loads(
self.session.post(
url = 'https://api.uyiban.com/workFlow/c/my/getProcessDetail',
params = {
'WFId': wfid,
'CSRF': dict_from_cookiejar(self.session.cookies)['csrf_token']
},
allow_redirects = False
).content
)
def get_task(self, wfid) -> dict:
self.session.headers['Origin'] = 'https://app.uyiban.com'
self.session.headers['Referer'] = 'https://app.uyiban.com/'
return loads(
self.session.get(
url = f'https://api.uyiban.com/workFlow/c/my/form/{wfid}',
params = {
'CSRF': dict_from_cookiejar(self.session.cookies)['csrf_token']
},
allow_redirects = False
).content
)['data']['Form']
# 获取任务细节和加密任务Key
def submit(self,
name: str,
wfid: dict,
quest: dict,
processId: str,
taskId: str,
title: str,
longitude: float,
latitude: float,
address: str,
returnSchool: bool,
lock
) -> str:
errmsg = ''
data = 'Str=' + self.encrypt_data({
'WFId': wfid['WFId'],
'Data': dumps({
quest[1]['id']: '是' if returnSchool else '否',
quest[2]['id']: str(round((36 + uniform(0, 0.9)), 1)),
quest[3]['id']: ['以上都无'],
quest[4]['id']: '好',
quest[5]['id']: {
'time': self.date,
'longitude': str(longitude),
'latitude': str(latitude),
'address': address
}
}, ensure_ascii = False),
'WfprocessId': processId,
'Extend': dumps({
'TaskId': taskId,
'title': '任务信息',
'content':[
{
'label': '任务名称',
'value': title
}, {
'label': '发布机构',
'value': wfid['PubOrgName']
}, {
'label': '发布人',
'value': wfid['PubPersonName']
}
]
}, ensure_ascii = False),
'CustomProcess': dumps({
'ApplyPersonIds': [],
'CCPersonId': []
}, ensure_ascii = False)
}, self.key, self.iv)
self.session.headers['Origin'] = 'https://app.uyiban.com'
self.session.headers['Referer'] = 'https://app.uyiban.com/'
submit = loads(self.session.post(
url = 'https://api.uyiban.com/workFlow/c/my/apply',
params = {
'CSRF': self.cookies['csrf_token']
},
data = data,
allow_redirects = False
).content)
if submit['code'] == 0: # 请求成功
lock.acquire()
f = open(path.join(PATH, 'run.log'), 'a+')
f.write(
'\n====\t====\t====\n' +
'Date: ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
'\nTitle: ' + title +
'\nAccount: ' + name +
'\nTaskId: ' + taskId +
'\nWFId: ' + wfid['WFId'] +
'\nProcessId: ' + processId +
'\nContent: ' + wfid['Content'] +
'\nPubOrg: ' + wfid['PubOrgName'] +
'\nPubPerson: ' + wfid['PubPersonName'] +
'\n====\t====\t====\n'
)
f.close()
lock.release()
print(f'{name}\t\033[1;32mDone.\033[0m')
else: # 请求失败
errmsg += (
'\n====\t====\t====\n' +
'Date: ' + datetime.now().strftime('%Y-%m-%d %H:%M:%S') +
'\nSubmit error.' +
'\nAccount: ' + name +
'\nLog: \n' +
str(submit['code']) + '\n' + submit['msg'] +
'\n====\t====\t====\n'
)
return errmsg
def encrypt_data(self, data: str, key: str, iv: str) -> str:
data = dumps(data, ensure_ascii = False).replace(' ', '')
res = sub(compile(r'(\d{4}-\d+-\d{2,}:\d{2,})'), str(self.date), data)
res = res + (
AES.block_size - len(res.encode()) % AES.block_size
) * chr(
AES.block_size - len(res.encode()) % AES.block_size
)
cipher = AES.new(
key.encode('UTF-8'),
AES.MODE_CBC,
iv.encode('UTF-8')
)
result = b64encode(
b64encode(
cipher.encrypt(res.encode('UTF-8'))
)
)
return quote(result.decode('UTF-8'))