forked from 01121531/new-elm
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathelm_lybzl.py
362 lines (336 loc) · 14.1 KB
/
elm_lybzl.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
import json
import os
import requests
from urllib.parse import quote
import datetime
host = 'https://acs.m.goofish.com'
zlck = os.environ.get('elmck')
ck = ''
def tq(txt):
try:
txt = txt.replace(" ", "")
pairs = txt.split(";")[:-1]
ck_json = {}
for i in pairs:
ck_json[i.split("=")[0]] = i.split("=")[1]
return ck_json
except Exception as e:
print(f'❎Cookie解析错误: {e}')
return {}
class LYB:
def __init__(self, cki):
self.ck1 = tq(cki)
self.uid = self.ck1.get("unb")
self.sid = self.ck1.get("cookie2")
self.name = self.uid
def xsign(self, api, data, wua, v):
url = "http://mzkj666.cn:18848/api/getXSign"
body = {
"data": data,
"api": api,
"pageId": '',
"uid": self.uid,
'sid': self.sid,
"deviceId": '',
"utdid": '',
"wua": wua,
'ttid': '1551089129819@eleme_android_10.14.3',
"v": v
}
max_retries = 5
retries = 0
while retries < max_retries:
try:
r = requests.post(url, json=body, timeout=9)
return r.json()
except requests.exceptions.HTTPError as e:
print(f'❎请求签名服务器失败: {e}')
except requests.exceptions.Timeout:
print("❎签名接口请求超时")
except requests.exceptions.RequestException as e:
print(f'❎请求签名服务器错误: {e}')
retries += 1
print(f"❎重试次数: {retries}")
if retries >= max_retries:
print("❎重试次数上限,尝试使用备用通道1")
return self.xsign1(api, data, wua, v)
def xsign1(self, api, data, wua, v):
url = "http://124.71.214.109:9999/api/getXSign"
body = {
"data": data,
"api": api,
"pageId": '',
"uid": self.uid,
'sid': self.sid,
"deviceId": '',
"utdid": '',
"wua": wua,
'ttid': '1551089129819@eleme_android_10.14.3',
"v": v
}
max_retries = 5
retries = 0
while retries < max_retries:
try:
r = requests.post(url, json=body, timeout=9)
return r.json()
except requests.exceptions.HTTPError as e:
print(f'❎请求签名服务器失败: {e}')
except requests.exceptions.Timeout:
print("❎签名接口请求超时")
except requests.exceptions.RequestException as e:
print(f'❎请求签名服务器错误: {e}')
retries += 1
print(f"❎重试次数: {retries}")
if retries >= max_retries:
print("❎通道1尝试次数上限,尝试使用备用通道2")
return self.xsign2(api, data, wua, v)
def xsign2(self, api, data, wua, v):
url = "http://x111.bdwl.asia/api/getXSign"
body = {
"data": data,
"api": api,
"pageId": '',
"uid": self.uid,
'sid': self.sid,
"deviceId": '',
"utdid": '',
"wua": wua,
'ttid': '1551089129819@eleme_android_10.14.3',
"v": v
}
max_retries = 5
retries = 0
while retries < max_retries:
try:
r = requests.post(url, json=body, timeout=9)
return r.json()
except requests.exceptions.HTTPError as e:
print(f'❎请求签名服务器失败: {e}')
except requests.exceptions.Timeout:
print("❎签名接口请求超时")
except requests.exceptions.RequestException as e:
print(f'❎请求签名服务器错误: {e}')
retries += 1
print(f"❎重试次数: {retries}")
if retries >= max_retries:
print("❎通道2尝试次数上限,哦豁,签名通道都不可用!")
return None
def req(self, api, data, wua='False', v="1.0"):
try:
if type(data) == dict:
data = json.dumps(data)
wua = str(wua)
sign = self.xsign(api, data, wua, v)
url = f"{host}/gw/{api}/{v}/"
headers = {
"x-sgext": quote(sign.get('x-sgext')),
"x-sign": quote(sign.get('x-sign')),
'x-sid': self.sid,
'x-uid': self.uid,
'x-pv': '6.3',
'x-features': '1051',
'x-mini-wua': quote(sign.get('x-mini-wua')),
'content-type': 'application/x-www-form-urlencoded;charset=UTF-8',
'x-t': sign.get('x-t'),
'x-extdata': 'openappkey%3DDEFAULT_AUTH',
'x-ttid': '1551089129819@eleme_android_10.14.3',
'x-utdid': '',
'x-appkey': '24895413',
'x-devid': '',
}
params = {"data": data}
if 'wua' in sign:
params["wua"] = sign.get('wua')
max_retries = 5
retries = 0
while retries < max_retries:
try:
res = requests.post(url, headers=headers, data=params, timeout=15)
return res
except requests.exceptions.Timeout:
print("❎接口请求超时")
except requests.exceptions.RequestException as e:
print(f"❎请求异常: {e}")
retries += 1
print(f"❎重试次数: {retries}")
if retries >= max_retries:
print("❎重试次数上限")
return None
except Exception as e:
print(f'❎请求接口失败: {e}')
return None
def yqm(self):
api = 'mtop.ele.biz.growth.task.core.querytask'
data = json.dumps({"missionCollectionId": "839",
"locationInfos": "[\"{\\\"lng\\\":\\\"105.75325090438128\\\",\\\"lat\\\":\\\"30.597472842782736\\\"}\"]",
"bizScene": "game_center", "accountPlan": "HAVANA_COMMON"})
try:
res = self.req(api, data, 'False' "1.0")
if res.json()["ret"][0] == "SUCCESS::接口调用成功":
for y in res.json()['data']['mlist']:
print(y['name'])
if y['name'] == "邀请好友助力":
actId = y['actionConfig']['ext']['actId']
ShareId = y['actionConfig']['ext']['shareId']
return actId, ShareId
else:
if res.json()["ret"][0] == "FAIL_SYS_SESSION_EXPIRED::Session过期":
print("❎cookie已过期,请重新获取")
return None, None
else:
print(res.text)
return None, None
except Exception:
print(f'❎请求错误')
return None, None
def share(self, actid1, shareId1):
api = 'mtop.koubei.interactioncenter.share.common.triggershare'
data = json.dumps(
{"actId": actid1, "shareId": shareId1, "bizScene": "DEFAULT", "requestId": "1719848804784"})
try:
res = self.req(api, data, 'False' "1.0")
if res is None:
return None
if res.json()["ret"][0] == "SUCCESS::调用成功":
print(f"[{self.name}] ✅助力成功")
return True
else:
if res.json()["ret"][0] == "FAIL_SYS_SESSION_EXPIRED::Session过期":
print(f"[{self.name}] ❎cookie已过期,请重新获取")
return False
else:
if res.json()["data"]['errorMsg'] == "助力次数已用完":
print(f"[{self.name}] ❎助力次数已用完")
return False
if res.json()["data"]['errorMsg'] == "今日助力次数已用完":
print(f"[{self.name}] ❎哦豁,莫得次数咯")
return False
if res.json()["data"]['errorMsg'] == " 人传人关系已达上限":
print(f"[{self.name}] ❎助力上限\n")
return 'SX'
if res.json()["data"]['errorMsg'] == "分享者已被助力成功,客态重复助力":
print(f"[{self.name}] ❎重复助力")
return None
else:
print(f"[{self.name}] ❎助力失败")
print(res.text)
return None
except Exception:
print(f'请求错误')
return None
def prize(self):
api1 = 'mtop.ele.biz.growth.task.core.querytask'
data1 = json.dumps({"missionCollectionId": "839",
"locationInfos": "[\"{\\\"lng\\\":\\\"105.75325090438128\\\",\\\"lat\\\":\\\"30.597472842782736\\\"}\"]",
"bizScene": "game_center", "accountPlan": "HAVANA_COMMON"})
try:
res1 = self.req(api1, data1, 'False' "1.0")
if res1 is None:
return None
if res1.json()["ret"][0] == "SUCCESS::接口调用成功":
for y in res1.json()['data']['mlist']:
if y['name'] == "邀请好友助力":
for o in y['missionStageDTOS']:
if o['rewardStatus'] == "TODO" and o['status'] == "FINISH":
api = 'mtop.ele.biz.growth.task.core.receiveprize'
data2 = json.dumps({
"missionCollectionId": "839",
"missionId": "20544001",
"count": o['stageCount']
})
try:
res = self.req(api, data2, 'False' "1.0")
if res is None:
continue
data = res.json()["data"]
if data.get('errorMsg') is not None:
print(f"[{self.name}] ❎领取奖励失败: {data['errorMsg']}")
else:
rlist = data.get('rlist')
if rlist is not None:
print(f"[{self.name}] ✅领取奖励成功--{rlist[0]['value']}乐园币")
else:
print(f"[{self.name}] ❎{res.json()['ret'][0]}")
except Exception:
print(f'请求错误')
return None
else:
if res1.json()["ret"][0] == "FAIL_SYS_SESSION_EXPIRED::Session过期":
print(f"[{self.name}] ❎cookie已过期,请重新获取")
else:
print(f"[{self.name}] ❎获取列表失败:", res1.json()["data"]['errorMsg'])
except Exception:
print(f'请求错误')
return None
def get_ck_usid(ck1):
try:
key_value_pairs = ck1.split(";")
for pair in key_value_pairs:
key, value = pair.split("=")
if key.lower() == "unb":
return value
except Exception:
return 'y'
if __name__ == '__main__':
today = datetime.date.today()
today_str = today.strftime('%Y%m%d')
filename = f'{today_str}.json'
if not os.path.exists(filename):
with open(filename, 'w') as f:
json.dump({}, f)
print("今日助力json文件不存在,已创建")
else:
print("今日助力json文件已存在")
with open(filename, 'r') as file:
data = json.load(file)
if 'elmck' in os.environ:
cookie = os.environ.get('elmck')
else:
print("❎环境变量中不存在[elmck],启用本地变量模式")
cookie = ck
if cookie == "":
print("❎本地变量为空,请设置其中一个变量后再运行")
exit(-1)
# cookie_str = ck['elmck']
cookies = cookie.split("&")
zlck_list = zlck.split("&")
print(f"获取到 {len(zlck_list)} 个被助力账号")
dzl_num = 0
for zlck in zlck_list:
dzl_num += 1
lyb = LYB(zlck)
actid, shareId = lyb.yqm()
print(actid)
if actid is None or shareId is None:
print("❎获取助力id失败")
else:
print(f"======被助力账号{dzl_num}获取邀请码成功,开始助力======")
for i, ck in enumerate(cookies):
usid = get_ck_usid(ck)
zlcs = data.get(f"{usid}", 0)
if zlcs < 3:
print(f"======被助力账号{dzl_num}-开始第{i + 1}/{len(cookies)}个账号助力======")
a = LYB(ck).share(actid, shareId)
if a == 'SX':
break
elif a:
data[f"{usid}"] = zlcs + 1
with open(filename, 'w') as file:
json.dump(data, file, indent=4)
print("2s后进行下一个账号")
continue
elif a is False:
data[f"{usid}"] = 3
with open(filename, 'w') as file:
json.dump(data, file, indent=4)
print("2s后进行下一个账号")
continue
else:
print("2s后进行下一个账号")
continue
else:
continue
print(f"======被助力账号{dzl_num}-领取奖励======")
lyb.prize()
print(f"======被助力账号{dzl_num}-助力结束======\n\n")