-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjd_khc.py
327 lines (292 loc) · 13.5 KB
/
jd_khc.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
#!/bin/env python3
# -*- coding: utf-8 -*
'''
cron: 5 0 0 * * * jd_khc.py
new Env('京手机狂欢城只助力');
'''
# export jd818_pins=["pt_pin1","pt_pin2"]
import os, re, sys
import random
try:
import requests
except Exception as e:
print(e, "\n缺少requests 模块,请执行命令安装:pip3 install requests")
exit(3)
from urllib.parse import unquote, quote
import json
import time, datetime
import threading
UserAgent = ''
script_name = '手机狂欢城只助力'
def printT(msg):
print("[{}]: {}".format(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), msg))
sys.stdout.flush()
def delEnvs(label):
try:
if label == 'True' or label == 'yes' or label == 'true' or label == 'Yes':
return True
elif label == 'False' or label == 'no' or label == 'false' or label == 'No':
return False
except:
pass
try:
if '.' in label:
return float(label)
elif '&' in label:
return label.split('&')
elif '@' in label:
return label.split('@')
else:
return int(label)
except:
return label
class getJDCookie():
# 适配青龙平台环境ck
def getckfile(self):
ql_new = '/ql/config/env.sh'
ql_old = '/ql/config/cookie.sh'
if os.path.exists(ql_new):
printT("当前环境青龙面板新版")
return ql_new
elif os.path.exists(ql_old):
printT("当前环境青龙面板旧版")
return ql_old
# 获取cookie
def getallCookie(self):
cookies = ''
ckfile = self.getckfile()
try:
if os.path.exists(ckfile):
with open(ckfile, "r", encoding="utf-8") as f:
cks_text = f.read()
if 'pt_key=' in cks_text and 'pt_pin=' in cks_text:
r = re.compile(r"pt_key=.*?pt_pin=.*?;", re.M | re.S | re.I)
cks_list = r.findall(cks_text)
if len(cks_list) > 0:
for ck in cks_list:
cookies += ck
return cookies
except Exception as e:
printT(f"【getCookie Error】{e}")
# 检测cookie格式是否正确
# def getUserInfo(self, ck, user_order, pinName):
# url = 'https://me-api.jd.com/user_new/info/GetJDUserInfoUnion?orgFlag=JD_PinGou_New&callSource=mainorder&channel=4&isHomewhite=0&sceneval=2&sceneval=2&callback='
# headers = {
# 'Cookie': ck,
# 'Accept': '*/*',
# 'Connection': 'close',
# 'Referer': 'https://home.m.jd.com/myJd/home.action',
# 'Accept-Encoding': 'gzip, deflate, br',
# 'Host': 'me-api.jd.com',
# 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.2 Mobile/15E148 Safari/604.1',
# 'Accept-Language': 'zh-cn'
# }
# try:
# resp = requests.get(url=url, headers=headers, timeout=60).json()
# if resp['retcode'] == "0":
# nickname = resp['data']['userInfo']['baseInfo']['nickname']
# return ck, nickname
# else:
# context = f"账号{user_order}【{pinName}】Cookie 已失效!请重新获取。"
# print(context)
# return ck, False
# except Exception:
# context = f"账号{user_order}【{pinName}】Cookie 已失效!请重新获取。"
# print(context)
# return ck, False
def getcookies(self):
"""
:return: cookiesList,userNameList,pinNameList
"""
cookiesList = []
pinNameList = []
nickNameList = []
cookies = self.getallCookie()
if 'pt_key=' in cookies and 'pt_pin=' in cookies:
r = re.compile(r"pt_key=.*?pt_pin=.*?;", re.M | re.S | re.I)
result = r.findall(cookies)
if len(result) >= 1:
printT("您已配置{}个账号".format(len(result)))
user_order = 1
for ck in result:
r = re.compile(r"pt_pin=(.*?);")
pinName = r.findall(ck)
pinName = unquote(pinName[0])
cookiesList.append(ck)
pinNameList.append(pinName)
# # 获取账号名
# ck, nickname = self.getUserInfo(ck, user_order, pinName)
# if nickname != False:
# cookiesList.append(ck)
# pinNameList.append(pinName)
# nickNameList.append(nickname)
# user_order += 1
# else:
# user_order += 1
# continue
if len(cookiesList) > 0:
return cookiesList, pinNameList
else:
printT("没有可用Cookie,已退出")
exit(4)
else:
printT("没有可用Cookie,已退出")
exit(4)
def getPinEnvs():
if "jd818_pins" in os.environ:
if len(os.environ["jd818_pins"]) != 0:
jd818_pins = os.environ["jd818_pins"]
jd818_pins = jd818_pins.replace('[', '').replace(']', '').replace('\'', '').replace(' ', '').split(',')
printT(f"已获取并使用Env环境 jd818_pins:{jd818_pins}")
return jd818_pins
else:
printT('请先配置export jd818_pins=["pt_pin1","pt_pin2"]')
exit(4)
printT('请先配置export jd818_pins=["pt_pin1","pt_pin2"]')
exit(4)
# 随机UA
def userAgent():
"""
随机生成一个UA
:return: jdapp;iPhone;9.4.8;14.3;xxxx;network/wifi;ADID/201EDE7F-5111-49E8-9F0D-CCF9677CD6FE;supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone13,4;addressid/2455696156;supportBestPay/0;appBuild/167629;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS 14_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1
"""
if not UserAgent:
uuid = ''.join(random.sample('123456789abcdef123456789abcdef123456789abcdef123456789abcdef', 40))
addressid = ''.join(random.sample('1234567898647', 10))
iosVer = ''.join(
random.sample(["14.5.1", "14.4", "14.3", "14.2", "14.1", "14.0.1", "13.7", "13.1.2", "13.1.1"], 1))
iosV = iosVer.replace('.', '_')
iPhone = ''.join(random.sample(["8", "9", "10", "11", "12", "13"], 1))
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))
return f'jdapp;iPhone;10.0.4;{iosVer};{uuid};network/wifi;ADID/{ADID};supportApplePay/0;hasUPPay/0;hasOCPay/0;model/iPhone{iPhone},1;addressid/{addressid};supportBestPay/0;appBuild/167629;jdSupportDarkMode/0;Mozilla/5.0 (iPhone; CPU iPhone OS {iosV} like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148;supportJDSHWK/1'
else:
return UserAgent
# 设置请求头
def setHeaders(cookie):
headers = {
"Host": "api.m.jd.com",
"cookie": cookie,
"charset": "UTF-8",
"accept-encoding": "br,gzip,deflate",
"user-agent": "okhttp/3.12.1;jdmall;android;version/10.0.8;build/89053;screen/1080x2029;os/10;network/wifi;",
"cache-control": "no-cache",
"content-type": "application/x-www-form-urlencoded; charset\u003dUTF-8",
"content-length": "48"
}
return headers
# 获取邀请码
def share(my_cookie,pin):
url = 'https://api.m.jd.com/api'
UA = userAgent()
headers = {
"Host": "api.m.jd.com",
"content-length": "172",
"accept": "application/json, text/plain, */*",
"origin": "https://carnivalcity.m.jd.com",
"user-agent": UA,
"content-type": "application/x-www-form-urlencoded",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"referer": "https://carnivalcity.m.jd.com/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q\u003d0.9,en-US;q\u003d0.8,en;q\u003d0.7",
"cookie": '__jda=122270672.16284882664002016987922.1628488266.1628488266.1628488266.1;__jdv=122270672%7Cdirect%7C-%7Cnone%7C-%7C1628488266402;__jdc=122270672;mba_muid=16284882664002016987922;shshshfp=234de4b0aaf7878e76554af3039eb9bf;shshshfpa=272e547b-5c97-7432-1824-d57611a4d6c0-1628488270;shshshsID=05805da17d23190f51d015bfcf67bec0_1_1628488270685;shshshfpb=yRz6zg0dJIS8Po%2FeQ8YxeKA%3D%3D;3AB9D23F7A4B3C9B=EZRC2BS2B3U7XTFLUKTSJVGTXYSC22EIBN2GGZSBLIAIW2O5BYCUSHYIJHHP3A63YKIGF4FSAR5YQHKL4BJYM3CL3M;TrackerID=5i6KmNXbP7za8nPJKlCI45N31ediuZDET5-Soy1IpGGJzm6d9N4hWitYLfYVMb07FN9xwYBsDsKtqdd5ujji6pl0sDJPSLm29fN89vagDU51RlhC8rgKWhLKScODUxIq;' + my_cookie + ';pt_token=oss1b9v6;__jdb=122270672.3.16284882664002016987922|1.1628488266;mba_sid=16284882664066635066110123546.3;__jd_ref_cls=carnivalcity_1616135996494%7C41'
}
body = json.dumps({"apiMapping": "/khc/task/getSupport"})
data = {
'appid': 'guardian-starjd',
'functionId': 'carnivalcity_jd_prod',
'body': body,
't': '1628488283504',
'loginType': '2',
'loginWQBiz': 'rdcactivity'
}
res = requests.post(url=url, headers=headers, data=data).json()
# print(res)
if res['code'] == 200:
# print(res['data']['shareId'])
return (res['data']['shareId'])
elif res['code'] == 1002:
print(pin+'是黑号')
return '-1'
# 助力好友
def help(mycookie,pin,cookiesList,pinNameList):
shareId = share(mycookie,pin)
if shareId != '-1':
UA = userAgent()
url = 'https://api.m.jd.com/api'
body = json.dumps({"shareId": shareId, "apiMapping": "/khc/task/doSupport"})
data = {
'appid': 'guardian-starjd',
'functionId': 'carnivalcity_jd_prod',
'body': body,
't': '1628488283504',
'loginType': '2',
'loginWQBiz': 'rdcactivity'
}
for i in range(len(cookiesList)):
headers = {
"Host": "api.m.jd.com",
"content-length": "172",
"accept": "application/json, text/plain, */*",
"origin": "https://carnivalcity.m.jd.com",
"user-agent": UA,
"content-type": "application/x-www-form-urlencoded",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"referer": "https://carnivalcity.m.jd.com/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "zh-CN,zh;q\u003d0.9,en-US;q\u003d0.8,en;q\u003d0.7",
"cookie": '__jda=122270672.16284882664002016987922.1628488266.1628488266.1628488266.1;__jdv=122270672%7Cdirect%7C-%7Cnone%7C-%7C1628488266402;__jdc=122270672;mba_muid=16284882664002016987922;shshshfp=234de4b0aaf7878e76554af3039eb9bf;shshshfpa=272e547b-5c97-7432-1824-d57611a4d6c0-1628488270;shshshsID=05805da17d23190f51d015bfcf67bec0_1_1628488270685;shshshfpb=yRz6zg0dJIS8Po%2FeQ8YxeKA%3D%3D;3AB9D23F7A4B3C9B=EZRC2BS2B3U7XTFLUKTSJVGTXYSC22EIBN2GGZSBLIAIW2O5BYCUSHYIJHHP3A63YKIGF4FSAR5YQHKL4BJYM3CL3M;TrackerID=5i6KmNXbP7za8nPJKlCI45N31ediuZDET5-Soy1IpGGJzm6d9N4hWitYLfYVMb07FN9xwYBsDsKtqdd5ujji6pl0sDJPSLm29fN89vagDU51RlhC8rgKWhLKScODUxIq;' + cookiesList[i] + ';pt_token=oss1b9v6;__jdb=122270672.3.16284882664002016987922|1.1628488266;mba_sid=16284882664066635066110123546.3;__jd_ref_cls=carnivalcity_1616135996494%7C41'
}
res = requests.post(url=url, headers=headers, data=data).json()
# print(res)
try:
if res['code'] == 200 and res['data']['status'] == 6:
print(pinNameList[i]+'助力'+pin+':'+'助力成功')
elif res['code'] == 200 and res['data']['status'] == 4:
print(pinNameList[i]+'助力'+pin+':'+'助力完成啦----')
break
elif res['code'] == 200 and res['data']['status'] == 3:
print(pinNameList[i]+'助力'+pin+':'+'没助力机会了')
except:
pass
time.sleep(1)
pass
def use_thread(jd818_cookies,pins, cookiesList,pinNameList):
threads = []
for i in range(len(jd818_cookies)):
threads.append(
threading.Thread(target=help, args=(jd818_cookies[i], pins[i],cookiesList,pinNameList))
)
for t in threads:
t.start()
for t in threads:
t.join()
def start():
printT("############{}##########".format(script_name))
jd818_pins = getPinEnvs()
get_jd_cookie = getJDCookie()
cookiesList, pinNameList = get_jd_cookie.getcookies()
jd818_cookies = []
nicks = []
for ckname in jd818_pins:
try:
ckNum = pinNameList.index(ckname)
jd818_cookies.append(cookiesList[ckNum])
# nicks.append(nickNameList[ckNum])
except Exception as e:
try:
ckNum = pinNameList.index(unquote(ckname))
jd818_cookies.append(cookiesList[ckNum])
# nicks.append(nickNameList[ckNum])
except:
print(f"请检查被助力账号【{ckname}】名称是否正确?ck是否存在?提示:助力名字可填pt_pin的值、也可以填账号名。")
continue
if len(jd818_cookies) == 0:
exit(4)
use_thread(jd818_cookies,jd818_pins, cookiesList,pinNameList)
if __name__ == '__main__':
start()