-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_mini_cookie.py
354 lines (329 loc) · 13.4 KB
/
check_mini_cookie.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
# -*- coding: utf-8 -*-
from config import *
def check_token(token):
headers = {
"authority": AISET2HOME,
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"authorization": "Bearer " + token,
"if-none-match": "W/\"221-syoJ9BkYqkwZhgUeAacHt6kZqtg\"",
"referer": f"https://{AISET2HOME}/",
"sec-ch-ua": "\"Microsoft Edge\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57"
}
url = f"https://{AISET2HOME}/api/auth/getInfo"
try:
response = requests.get(url, headers=headers, proxies=PROXIES)
if '请求成功' in response.text:
return True
else:
return False
except Exception as e:
return False
def get_minitoken():
tdict = redis_pool.hget("minigpt", MINIACCOUNT)
tdict = json.loads(tdict)
token = tdict['token']
# 检测token是否过期
islive = check_token(token)
print("mini token活性状态:", islive)
if islive:
return True
else:
token = login_get_token(MINIACCOUNT, MINIPASSWORD)
if token:
tdict['token'] = token
redis_pool.hset("minigpt", MINIACCOUNT, json.dumps(tdict))
return True
def login_get_token(miniaccount, minipassword):
headers = {
"authority": AISET2HOME,
"accept": "application/json, text/plain, */*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"content-type": "application/json",
"origin": f"https://{AISET2HOME}",
"referer": f"https://{AISET2HOME}/",
"sec-ch-ua": "\"Microsoft Edge\";v=\"113\", \"Chromium\";v=\"113\", \"Not-A.Brand\";v=\"24\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.57"
}
url = f"https://{AISET2HOME}/api/auth/login"
data = {
"username": miniaccount,
"password": minipassword
}
data = json.dumps(data, separators=(',', ':'))
try:
response = requests.post(url, headers=headers, data=data, proxies=PROXIES)
token = response.json()['data']
return token
except Exception as e:
logging.error(f"登录获取token异常: {repr(e)}")
return None
def get_gpt4_by_redis():
try:
for key in redis_pool.hkeys("gpt4plus"):
value = redis_pool.hget("gpt4plus", key)
value_dict = json.loads(value)
token = value_dict['token']
islive = check_4plus_token(token)
print("gpt4plus token活性状态:", islive)
if not islive:
token = login_gpt4p_token(key.decode('utf-8'), MINIPASSWORD)
value_dict['token'] = token
value_dict['info'] = get_4plus_limit(token)
redis_pool.hset("gpt4plus", key, json.dumps(value_dict))
return True
except Exception as e:
logging.error(f"获取gpt4plus账号异常: {repr(e)}")
return False
def login_gpt4p_token(email,password):
headers = {
"authority": AISET5,
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"content-type": "application/json",
"origin": f"https://{AISET5}",
"referer": f"https://{AISET5}/login",
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Microsoft Edge\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.43"
}
url = f"https://{AISET5}/api/user/login"
data = {
"email": email,
"password": password
}
data = json.dumps(data, separators=(',', ':'))
try:
response = requests.post(url, headers=headers, data=data, proxies=PROXIES)
token = response.json()['sessionToken']
return token
except Exception as e:
logging.error(f"登录获取token异常: {repr(e)}")
return None
def check_4plus_token(token):
headers = {
"authority": AISET5,
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"authorization": token,
"referer": f"{AISET5}/profile",
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Microsoft Edge\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.43"
}
url = f"https://{AISET5}/api/user/info"
try:
response = requests.get(url, headers=headers, proxies=PROXIES)
if response.json()['status'] == 0:
return True
else:
return False
except Exception as e:
logging.error(f"检测token异常: {repr(e)}")
return False
def get_4plus_limit(token):
headers = {
"authority": AISET5,
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"authorization": token,
"referer": f"{AISET5}/profile",
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Microsoft Edge\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.79"
}
url1 = f"https://{AISET5}/api/user/info/rate-limit"
url2 = f"https://{AISET5}/api/user/info/subscription"
try:
response = requests.get(url1, headers=headers, proxies=PROXIES)
remaining_gpt4 = response.json()['data']['remaining_gpt4']
response = requests.get(url2, headers=headers, proxies=PROXIES)
gpt4ptime = response.json()['data']
return [remaining_gpt4, gpt4ptime]
except Exception as e:
logging.error(f"获取剩余次数异常: {repr(e)}")
return 0
def get_gpt4199_token():
try:
for key in redis_pool.hkeys("chat199oken"):
value = redis_pool.hget("chat199oken", key)
value_dict = json.loads(value)
token = value_dict['token']
islive,vip = check_4_token(token)
print("gpt4p token活性状态:", islive)
if not islive:
token = login_4_token(key.decode('utf-8'), MINIPASSWORD)
islive, vip = check_4_token(token)
value_dict['token'] = token
value_dict['vip'] = vip
redis_pool.hset("chat199oken", key, json.dumps(value_dict))
return True
except Exception as e:
logging.error(f"获取gpt4账号异常: {repr(e)}")
return False
def check_4_token(token):
headers = {
"authority": AISET10,
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9",
"authorization": "Bearer " + token,
"origin": AISET10HOME,
"referer": AISET10HOME,
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
}
url = f"https://{AISET10}/api/get_user"
try:
response = requests.post(url, headers=headers, proxies=PROXIES)
if response.json()['status'] == 200:
resjson = response.json()
vip = resjson['vip']
vip.update({'last_msg': resjson["last_msg"]})
return True, vip
else:
return False, None
except Exception as e:
logging.error(f"检测token异常: {repr(e)}")
return False
def login_4_token(email,password):
headers = {
"authority": AISET10,
"accept": "*/*",
"accept-language": "zh-CN,zh;q=0.9",
"content-length": "0",
"origin": AISET10HOME,
"referer": AISET10HOME,
"sec-ch-ua": "\"Not.A/Brand\";v=\"8\", \"Chromium\";v=\"114\", \"Google Chrome\";v=\"114\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"Windows\"",
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "cross-site",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36"
}
url = f"https://{AISET10}/api/web_login"
params = {
"email": email,
"password": password
}
try:
response = requests.post(url, headers=headers, params=params, proxies=PROXIES)
token = response.json()['token']
return token
except Exception as e:
logging.error(f"登录获取token异常: {repr(e)}")
return None
def get_gptciyun_token():
try:
for key in redis_pool.hkeys("ciyuntoken"):
value = redis_pool.hget("ciyuntoken", key)
value_dict = json.loads(value)
token = value_dict['token']
islive,vip = check_ciyun_token(token)
print("gpt4p token活性状态:", islive)
if not islive:
token = login_ciyun_token(key.decode('utf-8'), MINIPASSWORD)
islive, vip = check_ciyun_token(token)
value_dict['token'] = token
value_dict['vip'] = vip
redis_pool.hset("ciyuntoken", key, json.dumps(value_dict))
return True
except Exception as e:
logging.error(f"获取慈云账号异常: {repr(e)}")
return False
def check_ciyun_token(token):
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"Content-Length": "0",
"authorization": "Bearer " + token,
"Origin": f"https://ai.{AISET15}",
"Referer": f"https://ai.{AISET15}/",
"Sec-Ch-Ua": "\"Not/A)Brand\";v=\"99\", \"Microsoft Edge\";v=\"115\", \"Chromium\";v=\"115\"",
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "\"Windows\"",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188"
}
url = f"https://gpt.{AISET15}/api/get_user"
try:
response = requests.post(url, headers=headers, proxies=PROXIES)
if response.json()['status'] == 200:
resjson = response.json()
vip = resjson['vip']
vip.update({'last_msg': resjson["last_msg"]})
return True, vip
else:
return False, None
except Exception as e:
logging.error(f"检测token异常: {repr(e)}")
return False
def login_ciyun_token(email,password):
headers = {
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
"Authorization": "Bearer",
"Content-Length": "0",
"Origin": f"https://ai.{AISET15}",
"Referer": f"https://ai.{AISET15}/",
"Sec-Ch-Ua": "\"Not/A)Brand\";v=\"99\", \"Microsoft Edge\";v=\"115\", \"Chromium\";v=\"115\"",
"Sec-Ch-Ua-Mobile": "?0",
"Sec-Ch-Ua-Platform": "\"Windows\"",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-site",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36 Edg/115.0.1901.188"
}
url = f"https://gpt.{AISET15}/api/web_login"
params = {
"email": email,
"password": password
}
try:
response = requests.post(url, headers=headers, params=params, proxies=PROXIES)
token = response.json()['token']
return token
except Exception as e:
logging.error(f"登录获取token异常: {repr(e)}")
return None
if __name__ == '__main__':
if not get_minitoken():
send_msg.send_dingding('小号token过期,请及时处理')
if not get_gpt4_by_redis():
send_msg.send_dingding('gpt4plus token过期,请及时处理')
# if not get_gpt4199_token():
# send_msg.send_dingding('gpt4 token过期,请及时处理')
if not get_gptciyun_token():
send_msg.send_dingding('gpt4p token过期,请及时处理')