-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathjd_fanli.py
114 lines (93 loc) · 4.05 KB
/
jd_fanli.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
"""
const $ = new Env("京东饭粒");
京东饭粒任务
活动入口:https://u.jd.com/ywEoeYu
cron:
47 7,17 * * * jd_fanli.py
"""
import sys
import os
import time
import re
import requests
import random
proxies = {"http": None, "https": None}
def printf(text):
print(text)
sys.stdout.flush()
def randomstr(num):
randomstr = ""
for i in range(num):
randomstr = randomstr + random.choice("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
return randomstr
def randomstr1():
randomstr = ""
for i in range(16):
randomstr = randomstr + random.choice("0123456789")
randomstr += "-"
for i in range(16):
randomstr = randomstr + random.choice("0123456789")
return randomstr
def getheader(ck):
return {
"Host": "ifanli.m.jd.com",
"Connection": "keep-alive",
"Accept": "application/json, text/plain, */*",
"Cache-Control": "no-cache",
"User-Agent": "jdapp;android;10.2.2;11;%s;model/Mi 10;osVer/30;appBuild/91077;partner/xiaomi001;eufv/1;jdSupportDarkMode/0;Mozilla/5.0 (Linux; Android 11; Mi 10 Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045715 Mobile Safari/537.36" % randomstr1(),
"Sec-Fetch-Mode": "cors",
"X-Requested-With": "com.jingdong.app.mall",
"Sec-Fetch-Site": "same-origin",
"Referer": "https://ifanli.m.jd.com/rebate/earnBean.html?paltform=null",
"Accept-Encoding": "gzip, deflate, br",
"Accept-Language": "zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7",
"Cookie": ck,
"Content-Type": "application/json;charset=UTF-8"
}
def getTaskList(ck):
url = "https://ifanli.m.jd.com/rebateapi/task/getTaskList"
headers = getheader(ck)
r = requests.get(url, headers=headers, proxies=proxies)
# printf(r.text)
return r.json()["content"]
def getTaskFinishCount(ck):
url = "https://ifanli.m.jd.com/rebateapi/task/getTaskFinishCount"
headers = getheader(ck)
r = requests.get(url, headers=headers, proxies=proxies)
printf(
'已完成任务次数:' + str(r.json()["content"]["finishCount"]) + ' 总任务次数:' + str(r.json()["content"]["maxTaskCount"]))
return r.json()["content"]
def saveTaskRecord(ck, taskId, businessId, taskType):
url = "https://ifanli.m.jd.com/rebateapi/task/saveTaskRecord"
headers = getheader(ck)
data = '{"taskId":%s,"businessId":%s,"taskType":%s}' % (taskId, businessId, taskType)
r = requests.post(url, headers=headers, data=data, proxies=proxies)
# printf(r.text)
return r.json()["content"]["uid"], r.json()["content"]["tt"]
def saveTaskRecord1(ck, taskId, businessId, taskType, uid, tt):
# tt=int(time.time()*1000)
url = "https://ifanli.m.jd.com/rebateapi/task/saveTaskRecord"
headers = getheader(ck)
data = '{"taskId":%s,"businessId":%s,"taskType":%s,"uid":"%s","tt":%s}' % (taskId, businessId, taskType, uid, tt)
# printf(data)
r = requests.post(url, headers=headers, data=data, proxies=proxies)
printf(r.json()["content"]["msg"])
if __name__ == '__main__':
printf("🔔京东饭粒, 开始!\n\n活动入口:https://u.jd.com/ywEoeYu\n\n")
cks = os.environ["JD_COOKIE"].split("&")
for ck in cks:
ptpin = re.findall(r"pt_pin=(.*?);", ck)[0]
printf("--------开始京东账号" + ptpin + "--------")
try:
count = getTaskFinishCount(ck)
if count["finishCount"] < count["maxTaskCount"]:
for times in range(count["maxTaskCount"] - count["finishCount"]):
tasks = getTaskList(ck)
for i in tasks:
if i["statusName"] != "活动结束":
printf("开始做任务: " + i["taskName"])
uid, tt = saveTaskRecord(ck, i["taskId"], i["businessId"], i["taskType"])
time.sleep(10)
saveTaskRecord1(ck, i["taskId"], i["businessId"], i["taskType"], uid, tt)
except:
printf("发生异常错误")