-
Notifications
You must be signed in to change notification settings - Fork 31
/
jd_jinli.py
260 lines (227 loc) · 9.97 KB
/
jd_jinli.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''
cron: 1 0,18 * * *
new Env('锦鲤-红叶Python版');
改自jd_jinli_hongbao.ts文件
'''
import os,json,random,time,re,string,functools,asyncio,sys
try:
import requests
except Exception as e:
print(str(e) + "\n缺少requests模块, 请执行命令:pip3 install requests\n")
requests.packages.urllib3.disable_warnings()
## 助力前n个账号
jinliCount = 1
## 锦鲤log (json格式)
jinliLogs = [
{"random":"25076811","log":"1650125108738~1azSH56m6nqMDF0ZWNEUTAyMQ==.RVNWdGBGUFJ0ZkZXVTpmDBY5czYRVyp9L0VJVWhnWFQddi9FGx0=.8d461930~6,1~5ACB2080984BA00B286EA5C9E6B50E9CBA870DAB~1klo6jn~C~ThdBXBQIbWkZF0FfWxAMbxdRABxyahp5DRkEBgYeVxhBFxkTUgUbcG0ZeAkaAw58GVQZRR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xnZVgORGZedwRxSFV2fXZgUnR1DllwZ0VZdFtzAnROeG1/A3daf05zZ3JJe1x0Z3dAVlxnV3FlAAJ4W3dfd3ZCTXNLc18YVgdWDVJTUAFKQhkET0hMdEphd1FmbmBVeXNzYHlxY2NscmBsc3NjQWViTWBncGQHcnNCRmdwSl1jZGdkfHBzf3txQnxpZXd0ZWByBHRwY3tidHRkaX5gYHxzQgFpcHBZYW1gYGdySlJhYVJ4dndVf2JzZ2NjcEUOYHNgUgxIAwZfBF8MSxQeFFlGUhcLFBBL~1v8h2wk"},
]
# 获取pin
cookie_findall=re.compile(r'pt_pin=(.+?);')
def get_pin(cookie):
try:
return cookie_findall.findall(cookie)[0]
except:
print('ck格式不正确,请检查')
# 读取环境变量
def get_env(env):
try:
if env in os.environ:
a=os.environ[env]
elif '/ql' in os.path.abspath(os.path.dirname(__file__)):
try:
a=v4_env(env,'/ql/config/config.sh')
except:
a=eval(env)
elif '/jd' in os.path.abspath(os.path.dirname(__file__)):
try:
a=v4_env(env,'/jd/config/config.sh')
except:
a=eval(env)
else:
a=eval(env)
except:
a=''
return a
# v4
def v4_env(env,paths):
b=re.compile(r'(?:export )?'+env+r' ?= ?[\"\'](.*?)[\"\']', re.I)
with open(paths, 'r') as f:
for line in f.readlines():
try:
c=b.match(line).group(1)
break
except:
pass
return c
# 随机ua
def ua():
sys.path.append(os.path.abspath('.'))
try:
from jdEnv import USER_AGENTS as a
except:
a='jdapp;iPad;10.5.0;;;M/5.0;appBuild/168052;jdSupportDarkMode/0;ef/1;ep/%7B%22ciphertype%22%3A5%2C%22cipher%22%3A%7B%22ud%22%3A%22ZNU0D2VrYWVuEQS5YJu0CzrsYtqyDNYyCtYnZwZrYtUyCNS2Y2TsDq%3D%3D%22%2C%22sv%22%3A%22CJGkDM4n%22%2C%22iad%22%3A%22%22%7D%2C%22ts%22%3A1650125106%2C%22hdid%22%3A%22JM9F1ywUPwflvMIpYPok0tt5k9kW4ArJEU3lfLhxBqw%3D%22%2C%22version%22%3A%221.0.3%22%2C%22appname%22%3A%22com.360buy.jdmobile%22%2C%22ridx%22%3A-1%7D;Mozilla/5.0 (iPad; CPU OS 14_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1;'
return a
# 13位时间戳
def gettimestamp():
return str(int(time.time() * 1000))
## 获取cooie
class Judge_env(object):
def main_run(self):
if '/jd' in os.path.abspath(os.path.dirname(__file__)):
cookie_list=self.v4_cookie()
else:
cookie_list=os.environ["JD_COOKIE"].split('&') # 获取cookie_list的合集
if len(cookie_list)<1:
print('请填写环境变量JD_COOKIE\n')
return cookie_list
def v4_cookie(self):
a=[]
b=re.compile(r'Cookie'+'.*?=\"(.*?)\"', re.I)
with open('/jd/config/config.sh', 'r') as f:
for line in f.readlines():
try:
regular=b.match(line).group(1)
a.append(regular)
except:
pass
return a
cookie_list=Judge_env().main_run()
# 正式代码部分
def postApi(fn, body, cookie):
headers = {
'Cookie': cookie,
# 'User-Agent': 'jdapp;iPad;10.5.0;;;M/5.0;appBuild/168052;jdSupportDarkMode/0;ef/1;ep/%7B%22ciphertype%22%3A5%2C%22cipher%22%3A%7B%22ud%22%3A%22ZNU0D2VrYWVuEQS5YJu0CzrsYtqyDNYyCtYnZwZrYtUyCNS2Y2TsDq%3D%3D%22%2C%22sv%22%3A%22CJGkDM4n%22%2C%22iad%22%3A%22%22%7D%2C%22ts%22%3A1650125106%2C%22hdid%22%3A%22JM9F1ywUPwflvMIpYPok0tt5k9kW4ArJEU3lfLhxBqw%3D%22%2C%22version%22%3A%221.0.3%22%2C%22appname%22%3A%22com.360buy.jdmobile%22%2C%22ridx%22%3A-1%7D;Mozilla/5.0 (iPad; CPU OS 14_4_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1;',
'User-Agent': ua(),
'Host': 'api.m.jd.com',
'Content-Type': 'application/x-www-form-urlencoded',
'Origin': 'https://happy.m.jd.com',
'Accept-Encoding': 'gzip, deflate, br',
'Connection': 'keep-alive',
'Accept': 'application/json, text/plain, */*',
'Referer': 'https://happy.m.jd.com/babelDiy/zjyw/3ugedFa7yA6NhxLN5gw2L3PF9sQC/index.html?asid=448106744',
'Accept-Language': 'zh-cn',
}
params = (
('appid', 'jinlihongbao'),
('functionId', fn),
('loginType', '2'),
('client', 'jinlihongbao'),
('t', gettimestamp()),
('clientVersion', '10.5.0'),
('osVersion', '-1'),
)
data = {
'body': json.dumps(body)
}
print({
'headers': headers,
'params': params,
'data': data
})
response = requests.post('https://api.m.jd.com/api', headers=headers, params=params, data=data, timeout=10)
return response
def api(fn, body, cookie):
for n in range(3):
res = postApi(fn, body, cookie).json()
# print(res)
if res['rtn_code'] != 403:
return res
return ''
def randomItem(a):
length = len(a)
if length < 1:
return ''
return a[random.randint(0, length-1)]
def randomSleep():
time.sleep(random.randint(10, 20))
def getPackets():
# 打开红包
for e,cookie in enumerate(cookie_list,start=1):
if e > jinliCount:
break
print(f'******开始【账号 {e}】 {get_pin(cookie)} *********\n')
try:
packetCount = 1
res = api('h5activityIndex', { "isjdapp": 1 }, cookie)
for t in res['data']['result']['redpacketConfigFillRewardInfo']:
if t['packetStatus'] == 2:
packetAmount = t['packetAmount']
print(f'红包{packetCount}已拆过,获得{packetAmount}')
elif t['packetStatus'] == 1:
print(f'红包{packetCount}可拆')
lg = randomItem(jinliLogs)
body = {
'random': lg['random'],
'log': lg['log'],
'sceneid': 'JLHBhPageh5'
}
res = api('h5receiveRedpacketAll', body, cookie)
print(res['data']['biz_msg'] + res['data']['result']['discount'])
else:
print(packetCount + t['hasAssistNum'] + '/' + t['requireAssistNum'])
packetCount += 1
except:
print('数据异常')
continue
randomSleep()
randomSleep()
def getHelp(redPackets):
fullCode = set()
# 内部助力
print('开始内部助力\n')
for e,cookie in enumerate(cookie_list,start=1):
print(f'******开始【账号 {e}】 {get_pin(cookie)} *********\n')
try:
for code in redPackets:
if code in fullCode:
break
lg = randomItem(jinliLogs)
body = {
'redPacketId': code,
'followShop': 0,
'random': lg['random'],
'log': lg['log'],
'sceneid': 'JLHBhPageh5'
}
res = api('jinli_h5assist', body, cookie)
resStatus = res['data']['result']['status']
if resStatus == 0:
discount = res['data']['result']['assistReward']['discount']
print(f'助力成功:{discount}')
elif resStatus == 3:
print('今日助力次数已满')
elif res['data']['result']['statusDesc'] == '啊偶,TA的助力已满,开启自己的红包活动吧~':
fullCode.add(code)
except:
print('数据异常')
continue
randomSleep()
randomSleep()
def getRedPackets(redPackets):
# 获取红包id
print('开始获取红包\n')
for e,cookie in enumerate(cookie_list,start=1):
if e > jinliCount :
break
try:
print(f'******开始【账号 {e}】 {get_pin(cookie)} *********\n')
res = api('h5activityIndex', { "isjdapp": 1 }, cookie)
redPacket = res['data']['result']['redpacketInfo']['id']
print(f'红包id: {redPacket}\n')
redPackets.add(redPacket)
except:
print('数据异常')
continue
randomSleep()
randomSleep()
def main():
print('锦鲤任务开始!\n')
print(f'====================共{len(cookie_list)}个京东账号Cookie=========\n')
redPackets = set()
getRedPackets(redPackets)
getHelp(redPackets)
getPackets()
if __name__ == '__main__':
main()