-
Notifications
You must be signed in to change notification settings - Fork 479
/
Copy pathjd_getFollowGift.py
365 lines (319 loc) · 11.4 KB
/
jd_getFollowGift.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
363
364
365
#!/bin/env python3
# -*- coding: utf-8 -*
'''
项目名称: JD-Script / jd_getFollowGift
Author: Curtin
功能:
Date: 2021/6/6 上午7:57
建议cron: 0 9 * * *
new Env('关注有礼');
2022-1-9:
1、修复bug
2021-11-08:
1、修复cookie检测接口
'''
##################################
#######################################
version = 'v1.1.0'
readmes = """
# JD 关注有礼
## 目录结构
JD-Script/ #主仓库
|-- getFollowGifts # 主目录
| |-- jd_getFollowGift.py # 主代码 (必要)
| |-- JDCookies.txt # 存放JD cookie,一行一个ck
| |-- Readme.md # 说明书
| `-- start.sh # shell脚本(非必要)
`-- README.md
### `【兼容环境】`
1.Python3.6+ 环境
2.兼容ios设备软件:Pythonista 3、Pyto(已测试正常跑,其他软件自行测试)
3.Windows exe
安装依赖模块 :
pip3 install requests
执行:
python3 jd_getFollowGift.py
## `【更新记录】`
2021.6.6:(v1.0.0 Beta)
* Test
###### [GitHub仓库 https://github.com/curtinlv/JD-Script](https://github.com/curtinlv/JD-Script)
###### [TG频道 https://t.me/TopStyle2021](https://t.me/TopStyle2021)
###### [TG群 https://t.me/topStyle996](https://t.me/topStyle996)
###### 关注公众号【TopStyle】

#
@Last Version: %s
@Last Time: 2021-06-06 07:57
@Author: Curtin
#### **仅以学习交流为主,请勿商业用途、禁止违反国家法律 ,转载请留个名字,谢谢!**
# End.
[回到顶部](#readme)
""" % version
################################ 【Main】################################
import time, os, sys, datetime
import requests
import re, json, base64
from urllib.parse import unquote, quote_plus
try:
from jd_cookie import getJDCookie
getCk = getJDCookie()
except:
print("请先下载依赖脚本,\n下载链接:https://ghproxy.com/https://raw.githubusercontent.com/curtinlv/JD-Script/main/jd_tool_dl.py")
sys.exit(3)
# 获取当前工作目录
pwd = os.path.dirname(os.path.abspath(__file__)) + os.sep
# 定义一些要用到参数
requests.packages.urllib3.disable_warnings()
scriptHeader = """
════════════════════════════════════════
║ ║
║ JD 关 注 有 礼 ║
║ ║
════════════════════════════════════════
@Version: {}""".format(version)
remarks = '\n\n\tTG交流 : https://t.me/topstyle996\n\n\tTG频道 : https://t.me/TopStyle2021\n\n\t公众号 : TopStyle\n\n\t\t\t--By Curtin\n'
######JD Cookie (多账号&分隔)
#######
notify_mode = []
message_info = ''''''
usergetGiftinfo = {}
## 获取通知服务
class msg(object):
def __init__(self, m):
self.str_msg = m
self.msg()
def msg(self):
global msg_info
print(self.str_msg)
try:
msg_info = "{}\n{}".format(msg_info, self.str_msg)
except:
msg_info = "{}".format(self.str_msg)
sys.stdout.flush()
def getsendNotify(self, a=0):
if a == 0:
a += 1
try:
url = 'https://gitee.com/curtinlv/Public/raw/master/sendNotify.py'
response = requests.get(url)
if 'curtinlv' in response.text:
with open('sendNotify.py', "w+", encoding="utf-8") as f:
f.write(response.text)
else:
if a < 5:
a += 1
return self.getsendNotify(a)
else:
pass
except:
if a < 5:
a += 1
return self.getsendNotify(a)
else:
pass
def main(self):
global send
cur_path = os.path.abspath(os.path.dirname(__file__))
sys.path.append(cur_path)
if os.path.exists(cur_path + "/sendNotify.py"):
try:
from sendNotify import send
except:
self.getsendNotify()
try:
from sendNotify import send
except:
print("加载通知服务失败~")
else:
self.getsendNotify()
try:
from sendNotify import send
except:
print("加载通知服务失败~")
###################
msg("").main()
def exitCodeFun(code):
try:
# exitCode = input()
if sys.platform == 'win32' or sys.platform == 'cygwin':
print("进程睡眠10分钟后自动退出。")
time.sleep(600)
exit(code)
except:
time.sleep(3)
exit(code)
def nowtime():
return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
# 检查是否有更新版本
def gettext(url):
try:
resp = requests.get(url, timeout=60).text
if '该内容无法显示' in resp or '违规' in resp:
return gettext(url)
return resp
except Exception as e:
print(e)
def isUpdate():
global footer,readme,uPversion,scriptName
url = base64.decodebytes(
b"aHR0cHM6Ly9naXRlZS5jb20vY3VydGlubHYvUHVibGljL3Jhdy9tYXN0ZXIvRm9sbG93R2lmdHMvdXBkYXRlLmpzb24=")
try:
result = gettext(url)
result = json.loads(result)
scriptName = result['name']
isEnable = result['isEnable']
uPversion = result['version']
info = result['info']
readme = result['readme']
pError = result['m']
footer = result['footer']
getWait = result['s']
if isEnable > 50 and isEnable < 150:
if version != uPversion:
print(f"\n当前最新版本:【{uPversion}】\n\n{info}\n")
msg(f"{readme}")
exitCodeFun(888)
else:
msg(f"{readme}")
time.sleep(getWait)
else:
print(pError)
exitCodeFun(888)
except:
msg("请检查您的环境/版本是否正常!")
exitCodeFun(888)
def outfile(filename, context):
with open(filename, "w+", encoding="utf-8") as f1:
f1.write(context)
f1.close()
def getRemoteShopid():
url = base64.decodebytes(
b"aHR0cHM6Ly9naXRlZS5jb20vY3VydGlubHYvUHVibGljL3Jhdy9tYXN0ZXIvRm9sbG93R2lmdHMvc2hvcGlkLnR4dA==")
try:
rShopid = gettext(url)
rShopid = rShopid.split("\n")
return rShopid
except:
print("无法从远程获取shopid")
exitCodeFun(999)
def createShopidList():
global shopidNum ,shopidList
shopidList = []
shopids = getRemoteShopid()
shopidNum = len(shopids) - 1
for i in range(shopidNum):
shopid = shopids[i]
shopid = eval(shopid)
shopidList.append(shopid)
def memoryFun(pinName,bean):
global usergetGiftinfo
try:
try:
usergetGiftinfo['{}'.format(pinName)]
usergetGiftinfo['{}'.format(pinName)] += bean
except:
usergetGiftinfo['{}'.format(pinName)] = bean
except Exception as e:
print(e)
def buildBody(data):
shopid = data['shopid']
venderId = data['venderId']
activityId = data['activityId']
signbody = data['signbody']
openudid = data['openudid']
body = 'body={"follow":0,"shopId":"' + shopid + '","activityId":"' + activityId + '","sourceRpc":"shop_app_home_window","venderId":"'+ venderId + '"}&build=&client=apple&clientVersion=10.2.4&d_brand=apple&d_model=iPhone10,3&ef=1&eid=&ep={"ciphertype":5,"cipher":{"openudid":"' + openudid + '"}}&ext={"prstate":"0"}&joycious=66&lang=zh_CN&partner=TF&' + signbody
return body
def drawShopGift(cookie, data):
try:
url = 'https://api.m.jd.com/client.action?functionId=drawShopGift'
body = data
headers = {
'Connection': 'keep-alive',
'Accept-Encoding': 'gzip, deflate, br',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'User-Agent': 'JD4iPhone/167870%20(iPhone;%20iOS;%20Scale/3.00)',
'Cookie': cookie,
'Host': 'api.m.jd.com',
'Referer': '',
'Accept-Language': 'zh-Hans-CN;q=1',
'Accept': '*/*'
}
n = 1
while True:
response = requests.post(url, headers=headers, data=body, timeout=60)
if response.status_code != 403:
break
else:
if n == 6:
break
n += 1
print("狗东限制ip,休眠60秒...")
sys.stdout.flush()
time.sleep(60)
if 'isSuccess' in response.text:
return response.json()
else:
return 9
except Exception as e:
return 9
def getGiftresult(result, nickname, pinName, uNum):
try:
if result['isSuccess']:
if result['result']:
followDesc = result['result']['followDesc']
giftDesc = result['result']['giftDesc']
print(f"\t└账号{uNum}【{nickname}】{followDesc}>{giftDesc}")
if result['result']['giftCode'] == '200':
try:
alreadyReceivedGifts = result['result']['alreadyReceivedGifts']
for g in alreadyReceivedGifts:
if g['prizeType'] == 4:
bean = g['redWord']
memoryFun(pinName, int(bean))
print(f"\t\t└获得{g['rearWord']}:{g['redWord']}")
except:
pass
except Exception as e:
print(f"getGiftresult Error {e}")
def start():
print(scriptHeader)
isUpdate()
outfile("Readme.md", readmes)
cookiesList, userNameList = getCk.iscookie()
userNum = len(cookiesList)
msg(f"开始:{scriptName}")
createShopidList()
msg(f"获取到店铺:{shopidNum}")
starttime = time.perf_counter() # 记录时间开始
for i in shopidList:
body = buildBody(i)
print(f"关注店铺【{i['shopid']}】")
uNum = 1
for ck, nickname in zip(cookiesList, userNameList):
result = drawShopGift(ck, body)
time.sleep(1.5)
if result != 9:
getGiftresult(result, nickname, nickname, uNum)
else:
uNum += 1
break
uNum += 1
endtime = time.perf_counter() # 记录时间结束
msg("\n###【本次统计 {}】###\n".format(nowtime()))
all_get_bean = 0
n = 1
for name, pinname in zip(userNameList, userNameList):
try:
userCountBean = usergetGiftinfo['{}'.format(pinname)]
msg(f"账号{n}:【{name}】\n\t└收获 {userCountBean} 京豆")
all_get_bean += userCountBean
except Exception as e:
msg(f"账号{n}:【{name}】\n\t└收获 0 京豆")
n += 1
msg(f"\n本次总累计获得:{all_get_bean} 京豆")
msg("\n------- 总耗时 : %.03f 秒 seconds -------" % (endtime - starttime))
print("{0}\n{1}\n{2}".format("*" * 30, scriptHeader, remarks))
send(f"【{scriptName}】", message_info)
exitCodeFun(0)
if __name__ == '__main__':
start()