forked from Steve0x2a/GZHU_JDSD
-
Notifications
You must be signed in to change notification settings - Fork 7
/
fuck_jdsd.py
296 lines (253 loc) · 8.35 KB
/
fuck_jdsd.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
import os
import sys
import requests
import json
import random
import time
import timeout_decorator
# 小程序key
# key_list = ['']
key_list = [str(os.environ['KEY'])]
pushplus_token = str(os.environ['TOKEN'])
serverchan_key = str(os.environ['SKEY'])
bark_url = str(os.environ['BURL'])
session = requests.session()
headers = {
'Host': 'jdsd.gzhu.edu.cn',
'Accept': '*/*',
'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) '
'Mobile/15E148 MicroMessenger/8.0.2(0x18000233) NetType/WIFI Language/en',
'Referer': 'https://servicewechat.com/wxb78a5743a9eed5bf/15/page-frame.html',
'Accept-Language': 'en-us'
}
session.headers = headers
url = "https://jdsd.gzhu.edu.cn/coctl_gzhu/index_wx.php"
def get_info():
# 获取个人信息 name:名字 today:今日获得积分 total:总积分
flag = False
info_data = {
'route': 'user_info',
'key': key
}
res = session.post(url, data=info_data).json()
info = {}
if res['status'] == 1:
flag = True
info['name'] = res['re']['user_name']
info['today'] = res['re']['per_day_credits']
info['total'] = res['re']['credits']
return flag, info
def signin():
# 签到
signin_data = {
'route': 'signin',
'key': key
}
res = session.post(url, data=signin_data).json()
def train():
# 每日一题函数, 可以直接获取每日一题题目编号, 构造编号和"1"的数组发送即可完成每日一题
get_id_data = {
'route': 'train_list_get',
'diff': '0',
'key': key
}
question = session.post(url, data=get_id_data).json()
ans = []
for i in question['re']['question_bag']:
ans.append([i['num'], "1"])
train_id = question['re']['train_id']
train_data = {
'route': 'train_finish',
'train_id': train_id,
'train_result': json.dumps(ans),
'key': key
}
res = session.post(url, data=train_data).json()
if res['status'] == 1:
return True
else:
return False
def read():
# 阅读函数 type从1到5 开始先发送一个开始的数据包, 结束把addtime换成91再发一次
read_data = {
'route': 'classic_time',
'addtime': 0,
'type': 1,
'key': key
}
for i in range(1, 6):
read_data['type'] = i
read_data['addtime'] = 0
begin = session.post(url, data=read_data)
read_data['addtime'] = 91
end = session.post(url, data=read_data)
# 最多匹配60分钟 此注解在Linux下可用
@timeout_decorator.timeout(3600)
def vs():
"""
朴实无华的匹配函数, 先变换counter找到对手, 后150秒内每隔一秒发送心跳包
利用了一个bug, 在比赛结束后若继续发送心跳包, 会直接获得段位分和积分
但是段位分无上限, 容易造成段位分过高
这里判定了开始加分后, 会只执行五次加分操作
"""
print('即将开始匹配 需要花费一定时间 请耐心等待')
vs_find_data = {
'route': 'get_counterpart',
'key': key,
'counter': 0,
'find_type': 0
}
add = 0
while (1):
i = 0
vs_find_data['counter'] = i
res = session.post(url, data=vs_find_data).json()
if res['status'] == 1:
game_key = res['question_bag']['gaming_key']
break
i += 1
if i > 10:
i = 0
question_num = get_question_num(res)
alive_data = {
'route': 'ask_opponent_score',
'key': key,
'gaming_key': game_key
}
for i in range(150):
time.sleep(1)
alive_res = session.post(url, alive_data)
if alive_res.json()['status'] == 2:
add += 1
if add >= 5:
break
'''
下面两个函数是获取题目num和对应答案和提交匹配时答案的接口 但基本用不到 因为我们根本不需要提交...
'''
def get_question_num(res):
# res是获取匹配成功后的json
question = []
for i in res['question_bag']['question_arr']:
question.append(i['num'])
return question
def get_answer(num):
get_answer_data = {
'route': 'ascertain_answer',
'key': key,
'gaming_key': '777777',
'question_id': '.coctl',
'answer_id': 'q',
'question_num': num,
'current_time': '0'
}
ans_data = session.post(url, data=get_answer_data).json()
return ans_data['test_item2']['answer']
def post_answer(num, answer):
post_answer_data = {
'route': 'ascertain_answer',
'key': key,
'gaming_key': '777777',
'question_id': '.coctl',
'answer_id': answer,
'question_num': num,
'current_time': str(random.randint(100, 180))
}
ans_data = session.post(url, data=post_answer_data).json()
def bark(value, message=None):
# 接入bark通知 可以修改bark_url推送到自己手机(iOS only)
b_url = bark_url
global title, content
if value:
title = '{}刷分成功/'.format(time.strftime("%Y-%m-%d", time.localtime()))
content = '返回信息:{}'.format(message)
else:
title = '{}刷分失败/'.format(time.strftime("%Y-%m-%d", time.localtime()))
content = '刷分失败,有异常抛出'
requests.post(b_url + '/' + title + content)
print('已推送bark:')
def serverchan(value, message=None):
# 接入Serverchan通知
key = serverchan_key
global title, content
if value:
title = '{}刷分成功'.format(time.strftime("%Y-%m-%d", time.localtime()))
content = '返回信息:{}'.format(message)
else:
title = '{}刷分失败'.format(time.strftime("%Y-%m-%d", time.localtime()))
content = '刷分失败,有异常抛出'
s_url = f"https://sc.ftqq.com/{key}.send"
data = {
"text": title,
"desp": content
}
requests.post(s_url, data=data)
print('已推送serverchan:')
def pushplus(value, message=None):
# 接入pushplus通知
token = pushplus_token
if value:
title = content = message
else:
title = content = "刷分失败,有异常抛出"
data = {"token": token, "title": title, "content": content}
p_url = "http://www.pushplus.plus/send/"
requests.post(p_url, data=data)
print('已推送pushplus:')
if __name__ == '__main__':
for key in key_list:
push_done = False
'''已推送标记'''
try:
# 先验证登录
flag, info = get_info()
if not flag:
raise Exception("登录失败 请验证key")
# print("姓名:{},当前积分:{}".format(info['name'], info['total']))
print("当前积分:{}".format(info['total']))
# 签到
signin()
print('已完成签到')
# 每日一题
for i in range(15):
train()
print('已完成每日一题')
# 阅读
read()
print('已完成阅读')
# 匹配
try:
vs()
print('已完成匹配')
# 捕获异常 超时后可以继续运行
except Exception as e:
print(e)
# 返回
flag, info = get_info()
string = "今日获得:{} 总积分:{}".format(info['today'], info['total'])
print(string)
# 通知 需要填入key或token
if pushplus_token:
pushplus(1, message=string)
push_done = True
if serverchan_key:
serverchan(1, message=string)
push_done = True
if bark_url:
bark(1, message=string)
push_done = True
elif pushplus_token == serverchan_key == bark_url:
sys.exit('无需推送')
except Exception as e:
print(e)
# 通知 需要填入key或token
if pushplus_token:
if not push_done:
pushplus(0, message=e)
if serverchan_key:
if not push_done:
serverchan(0, message=e)
if bark_url:
if not push_done:
bark(0, message=e)
elif pushplus_token == serverchan_key == bark_url:
sys.exit('无需推送')