forked from 6dylan6/jdm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjd_yqhy.py
343 lines (321 loc) · 15 KB
/
jd_yqhy.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
"""
# 邀好友赢大礼 create by doubi 通用模板
# 17:/椋东送福利,邀请好友,争排行榜排位,大礼送不停,(E1Y7RAtC4b) ,升级新版猄·=·Dσσōngαpρ
# https://prodev.m.jd.com/mall/active/dVF7gQUVKyUcuSsVhuya5d2XD4F/index.html?code=16dde1860f1b4f1b9a93db6612abf0b9&invitePin=pin值
# 注意事项 pin 为助力pin 必须保证ck在里面
环境变量说明:
export yhypin="需要助力的pin值"
export yhyactivityId="活动类型ID"
export yhyauthorCode="活动ID"
cron: 6 6 6 6 *
new Env('邀请赢大礼');
"""
import json
import requests,random,time,asyncio,re,os
from urllib.parse import quote_plus,unquote_plus
from functools import partial
print = partial(print, flush=True)
activatyname = '邀请赢大礼'
activityId = os.environ["yhyactivityId"] # 活动类型
authorCode = os.environ["yhyauthorCode"] # 活动id
invitePin = os.environ["yhypin"] # pin 填写cookie后面的pin
activityUrl = f'https://prodev.m.jd.com/mall/active/{activityId}/index.html?code={authorCode}&invitePin={invitePin}'
# 随机ua
def randomuserAgent():
global uuid, addressid, iosVer, iosV, clientVersion, iPhone, area, ADID, lng, lat
uuid = ''.join(random.sample(
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'z'], 40))
addressid = ''.join(random.sample('1234567898647', 10))
iosVer = ''.join(random.sample(["15.1.1", "14.5.1", "14.4", "14.3", "14.2", "14.1", "14.0.1"], 1))
iosV = iosVer.replace('.', '_')
clientVersion = ''.join(random.sample(["10.3.0", "10.2.7", "10.2.4"], 1))
iPhone = ''.join(random.sample(["8", "9", "10", "11", "12", "13"], 1))
area = ''.join(random.sample('0123456789', 2)) + '_' + ''.join(random.sample('0123456789', 4)) + '_' + ''.join(
random.sample('0123456789', 5)) + '_' + ''.join(random.sample('0123456789', 4))
ADID = ''.join(random.sample('0987654321ABCDEF', 8)) + '-' + ''.join(
random.sample('0987654321ABCDEF', 4)) + '-' + ''.join(random.sample('0987654321ABCDEF', 4)) + '-' + ''.join(
random.sample('0987654321ABCDEF', 4)) + '-' + ''.join(random.sample('0987654321ABCDEF', 12))
lng = '119.31991256596' + str(random.randint(100, 999))
lat = '26.1187118976' + str(random.randint(100, 999))
UserAgent = ''
if not UserAgent:
return f'jdapp;iPhone;10.0.4;{iosVer};{uuid};network/wifi;ADID/{ADID};model/iPhone{iPhone},1;addressid/{addressid};appBuild/167707;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS {iosV} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/null;supportJDSHWK/1'
else:
return UserAgent
# 检测ck状态
async def check(ua, ck):
try:
url = 'https://me-api.jd.com/user_new/info/GetJDUserInfoUnion'
header = {
"Host": "me-api.jd.com",
"Accept": "*/*",
"Connection": "keep-alive",
"Cookie": ck,
"User-Agent": ua,
"Accept-Language": "zh-cn",
"Referer": "https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&",
"Accept-Encoding": "gzip, deflate",
}
result = requests.get(url=url, headers=header, timeout=2).text
codestate = json.loads(result)
if codestate['retcode'] == '1001':
msg = "当前ck已失效,请检查"
return {'code': 1001, 'data': msg}
elif codestate['retcode'] == '0' and 'userInfo' in codestate['data']:
nickName = codestate['data']['userInfo']['baseInfo']['nickname']
return {'code': 200, 'name': nickName, 'ck': ck}
except Exception as e:
return {'code': 0, 'data': e}
# 获取当前时间
def get_time():
time_now = round(time.time()*1000)
return time_now
# 登录plogin
async def plogin(ua,cookie):
now = get_time()
url = f'https://plogin.m.jd.com/cgi-bin/ml/islogin?time={now}&callback=__jsonp{now-2}&_={now+2}'
header = {
'Accept':'*/*',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'zh-CN,zh-Hans;q=0.9',
'Connection': 'keep-alive',
'Cookie': cookie,
'Host': 'plogin.m.jd.com',
'Referer': 'https://prodev.m.jd.com/',
'User-Agent':ua
}
response = requests.get(url=url,headers=header,timeout=30).text
return response
# 活动接口
async def jdjoy(ua,cookie):
url = f'https://jdjoy.jd.com/member/bring/getActivityPage?code={authorCode}&invitePin={invitePin}&_t={get_time()}'
header = {
'Accept':'*/*',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-Hans-US;q=1,en-US;q=0.9',
'Connection':'keep-alive',
'Content-Type':'application/json',
'Cookie':cookie,
"Host":'jdjoy.jd.com',
'Origin':'https://prodev.m.jd.com',
"Referer":'https://prodev.m.jd.com/',
'User-Agent':ua
}
response = requests.get(url=url,headers=header).text
return json.loads(response)
# go开卡
async def ruhui(ua,cookie):
url = f'https://jdjoy.jd.com/member/bring/joinMember?code={authorCode}&invitePin={invitePin}'
header = {
'Host': 'jdjoy.jd.com',
'Content-Type': 'application/json',
'Origin': 'https://prodev.m.jd.com',
'Accept-Encoding': 'gzip, deflate, br',
'Cookie': cookie,
'Connection': 'keep-alive',
'Accept': '*/*',
'User-Agent': ua,
'Referer': activityUrl,
'Accept-Language': 'zh-cn',
'request-from': 'native'
}
response = requests.get(url=url,headers=header).text
return json.loads(response)
# 检查开卡状态
async def check_ruhui(body,cookie,venderId,ua):
url = f'https://api.m.jd.com/client.action?appid=jd_shop_member&functionId=getShopOpenCardInfo&body={json.dumps(body)}&client=H5&clientVersion=9.2.0&uuid=88888'
headers = {
'Host': 'api.m.jd.com',
'Accept': '*/*',
'Connection': 'keep-alive',
'Cookie': cookie,
'User-Agent': ua,
'Accept-Language': 'zh-cn',
'Referer': f'https://shopmember.m.jd.com/shopcard/?venderId={venderId}&channel=801&returnUrl={json.dumps(activityUrl)}',
'Accept-Encoding': 'gzip, deflate'
}
response = requests.get(url=url,headers=headers,timeout=30000).text
return json.loads(response)
# 领取奖励
async def getInviteReward(cookie,ua,number):
url = f'https://jdjoy.jd.com/member/bring/getInviteReward?code={authorCode}&stage={number}'
header = {
'Accept':'*/*',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-Hans-US;q=1,en-US;q=0.9',
'Connection':'keep-alive',
'Content-Type':'application/json',
'Cookie':cookie,
"Host":'jdjoy.jd.com',
'Origin':'https://prodev.m.jd.com',
"Referer":'https://prodev.m.jd.com/',
'User-Agent':ua
}
response = requests.get(url=url,headers=header).text
return json.loads(response)
# 开启活动
async def firstInvite(cookie,ua):
url = f'https://jdjoy.jd.com/member/bring/firstInvite?code={authorCode}'
header = {
'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding':'gzip, deflate',
'Accept-Language':'zh-Hans-US;q=1,en-US;q=0.9',
'Connection':'keep-alive',
'Cookie':cookie,
"Host":'jdjoy.jd.com',
'User-Agent':ua
}
response = requests.get(url=url,headers=header).text
print(response)
return json.loads(response)
async def get_ck(data):
cklist = []
if data['code']!=200:
return {'code': 0, 'data':data}
else:
env_data = data['data']
for ck in env_data:
if 'remarks' in ck and ck['name']=='JD_COOKIE':
cklist.append(ck['value'])
else:
pass
return cklist
# 检查pin
def checkpin(cks:list,pin):
for ck in cks:
if pin in ck:
return ck
else:
None
# 主程序
async def main():
try:
cks = os.environ["JD_COOKIE"].split("&")
except:
with open('cklist1.txt','r') as f:
cks = f.read().split('\n')
success = 0 # 计算成功数
inveteck = checkpin(cks,invitePin) # 根据设定的pin返回对应ck
needinviteNum = [] # 需要助力次数
needdel = []
need = []
if inveteck:
print(f'🔔{activatyname}', flush=True)
print(f'==================共{len(cks)}个京东账号Cookie==================')
print(f'==================脚本执行- 北京时间(UTC+8):{get_time()}=====================\n')
print(f'您好!{invitePin},正在获取您的活动信息',)
ua = randomuserAgent() # 获取ua
result = await check(ua, inveteck) # 检测ck
if result['code'] == 200:
await plogin(ua,inveteck) # 获取登录状态
await asyncio.sleep(2)
result = await jdjoy(ua,inveteck) # 获取活动信息
await firstInvite(inveteck,ua) # 开启活动
if result['success']:
brandName = result['data']['brandName'] # 店铺名字
venderId = result['data']['venderId'] # 店铺入会id
rewardslist =[] # 奖品
successCount = result['data']['successCount'] # 当前成功数
success += successCount
result_data = result['data']['rewards'] # 奖品数据
print(f'您好!账号[{invitePin}],开启{brandName}邀请好友活动\n去开活动')
for i in result_data:
stage = i['stage']
inviteNum = i['inviteNum'] # 单次需要拉新人数
need.append(inviteNum)
rewardName = i['rewardName'] # 奖品名
rewardNum = i['rewardStock']
if rewardNum !=0:
needinviteNum.append(inviteNum)
needdel.append(inviteNum)
rewardslist.append(f'级别{stage}: 需助力{inviteNum}人,奖品: {rewardName},库存:{rewardNum}件\n')
if len(rewardslist)!=0:
print('当前活动奖品如下: \n'+str('\n'.join(rewardslist))+f'\n当前已助力{successCount}次\n')
for nmubers in needdel:
if success >= nmubers:
print("您当前助力已经满足了,可以去领奖励了")
print(f'\n这就去领取奖励{need.index(nmubers)+1}')
result = await getInviteReward(inveteck,ua,need.index(nmubers)+1)
print(result)
needinviteNum.remove(nmubers)
await asyncio.sleep(10)
needdel = needinviteNum
if needinviteNum == []:
print('奖励已经全部获取啦,退出程序')
return
for n,ck in enumerate(cks,1):
ua = randomuserAgent() # 获取ua
try:
pin = re.findall(r'(pt_pin=([^; ]+)(?=;))',str(ck))[0]
pin = (unquote_plus(pin[1]))
except IndexError:
pin = f'用户{n}'
print(f'******开始【京东账号{n}】{pin} *********\n')
for n,nmubers in enumerate(needinviteNum,1):
for nmubers in needdel:
if success >= nmubers:
print(nmubers)
print("您当前助力已经满足了,可以去领奖励了")
print(f'\n这就去领取奖励{need.index(nmubers)+1}')
result = await getInviteReward(inveteck,ua,need.index(nmubers)+1)
print(result)
needinviteNum.remove(nmubers)
await asyncio.sleep(10)
needdel = needinviteNum
if needinviteNum == []:
print('奖励已经全部获取啦,退出程序')
return
await plogin(ua,ck) # 获取登录状态
result = await check(ua, ck) # 检测ck
if result['code'] == 200:
result = await jdjoy(ua,ck) # 调用ck
if result['success']:
print(f'账户[{pin}]已开启{brandName}邀请好友活动\n')
await asyncio.sleep(3)
result= await check_ruhui({"venderId":str(venderId), "channel": "401" },ck,venderId,ua) # 检查入会状态
try:
if result['result']['userInfo']['openCardStatus']==0: # 0 未开卡
await asyncio.sleep(2)
print(f'您还不是会员哦,这就去去助力{invitePin}\n')
result = await ruhui(ua,ck)
if result['success']:
success +=1
print(f'助力成功! 当前成功助力{success}个\n')
if '交易失败' in str(result):
success +=1
print(f'助力成功! 当前成功助力{success}个\n')
else:
print(result)
await asyncio.sleep(2)
else:
print('您已经是会员啦,不去请求了入会了\n')
continue
except TypeError as e:
print(e)
result = await ruhui(ua,ck)
if result['success']:
success +=1
print(f'助力成功! 当前成功助力{success}个\n')
if '交易失败' in result:
success +=1
print(f'助力成功! 当前成功助力{success}个\n')
else:
print(result['errorMessage'])
await asyncio.sleep(2)
else: # 没有获取到活动信息
print('未获取到活动参数信息\n')
break
else:
print(result['data'])
continue
else:
print('未能获取到活动信息\n')
return
else:
print(result['data'])
return
else:
print(f'pin填写有误,请重试')
if __name__ == "__main__":
asyncio.run(main())