forked from Mashiro2000/HeyTapTask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dailyCash.py
355 lines (334 loc) · 14.9 KB
/
dailyCash.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
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2021/9/12
# @Author : 2984922017@qq.com
# @File : dailyCash.py
# @Software: PyCharm
'''
cron: 30 5,12 * * * dailyCash.py
new Env('欢太每日现金');
'''
import os
import sys
import time
import json
import random
import logging
# 日志模块
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logFormat = logging.Formatter("%(message)s")
# 日志输出流
stream = logging.StreamHandler()
stream.setFormatter(logFormat)
logger.addHandler(stream)
# 日志录入时间
logger.info(f"任务:{'任务中心'}\n时间:{time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())}")
# 第三方库
try:
import requests
except ModuleNotFoundError:
print("缺少requests依赖!程序将尝试安装依赖!")
os.system("pip3 install requests -i https://pypi.tuna.tsinghua.edu.cn/simple")
os.execl(sys.executable, 'python3', __file__, *sys.argv)
class DailyCash:
def __init__(self,dic):
self.dic = dic
self.sess = requests.session()
# 登录验证
def login(self):
url = 'https://store.oppo.com/cn/oapi/users/web/member/check'
headers = {
'Host': 'store.oppo.com',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive',
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
}
response = self.sess.get(url=url,headers=headers).json()
if response['code'] == 200:
logger.info(f"{self.dic['user']}\t登录成功")
return True
else:
logger.info(f"{self.dic['user']}\t登录失败")
return False
# 浏览商品
def viewGoods(self, count,flag,dic=None):
headers = {
'clientPackage': 'com.oppo.store',
'Host': 'msec.opposhop.cn',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive',
'User-Agent': 'okhttp/3.12.12.200sp1',
'Accept-Encoding': 'gzip'
}
result = self.getGoodMess(count=count) # 秒杀列表存在商品url
if result['meta']['code'] == 200:
for each in result['detail']:
url = f"https://msec.opposhop.cn/goods/v1/info/sku?skuId={each['skuid']}"
self.sess.get(url=url,headers=headers)
logger.info(f"正在浏览商品id:{each['skuid']}...")
time.sleep(random.randint(7,10))
if flag == 1: # 来源天天领现金
self.getCash(dic=dic)
# 分享商品
def shareGoods(self, flag,count,dic=None):
url = 'https://msec.opposhop.cn/users/vi/creditsTask/pushTask'
headers = {
'clientPackage': 'com.oppo.store',
'Host': 'msec.opposhop.cn',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive',
'User-Agent': 'okhttp/3.12.12.200sp1',
'Accept-Encoding': 'gzip',
}
params = {
'marking': 'daily_sharegoods'
}
for i in range(count + random.randint(1,3)):
self.sess.get(url=url,headers=headers,params=params)
logger.info(f"正在执行第{i+1}次微信分享...")
time.sleep(random.randint(7,10))
if flag == 1: #来源天天赚钱
self.getCash(dic=dic)
# 秒杀详情页获取商品数据
def getGoodMess(self,count=10):
taskUrl = f'https://msec.opposhop.cn/goods/v1/SeckillRound/goods/{random.randint(100,250)}' # 随机商品
headers = {
'clientPackage': 'com.oppo.store',
'Host': 'msec.opposhop.cn',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive',
'User-Agent': 'okhttp/3.12.12.200sp1',
'Accept-Encoding': 'gzip',
}
params = {
'pageSize':count + random.randint(1,3)
}
response = self.sess.get(url=taskUrl,headers=headers,params=params).json()
if response['meta']['code'] == 200:
return response
else:
logger.info(response)
def getCash(self,dic):
url = 'https://store.oppo.com/cn/oapi/omp-web/web/dailyCash/drawReward'
headers = {
'Host': 'store.oppo.com',
'Connection': 'keep-alive',
'Origin': 'https://store.oppo.com',
'source_type': '501',
'clientPackage': 'com.oppo.store',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json, text/plain, */*',
'Referer': 'https://store.oppo.com/cn/app/cashRedEnvelope?activityId=1&us=shouye&um=xuanfu&uc=xianjinhongbao',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,en-US;q=0.9'
}
data = {
'activityId':1,
'channel':3,
'channelRewardId':dic['id']
}
response = self.sess.post(url=url,headers=headers,data=data).json()
if response['code'] == 200:
logger.info(f"[{dic['taskName']}]\t{response['data']['amount']}")
elif response['code'] == 1000001:
logger.info(f"[{dic['taskName']}]\t{response['errorMessage']}")
# 天天领取现金
def getDailyCashTask(self):
url = 'https://store.oppo.com/cn/oapi/omp-web/web/dailyCash/queryActivityReward'
headers = {
'Host': 'store.oppo.com',
'Connection': 'keep-alive',
'source_type': '501',
'clientPackage': 'com.oppo.store',
'Accept': 'application/json, text/plain, */*',
'Referer': 'https://store.oppo.com/cn/app/cashRedEnvelope?activityId=1&us=shouye&um=xuanfu&uc=xianjinhongbao',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,en-US;q=0.9'
}
params = {
'activityId':1
}
response = self.sess.get(url=url,headers=headers,params=params).json()
if response['code'] == 200:
self.taskRewardList = response['data']['taskRewardList']
self.timingRewardList = response['data']['timingRewardList']
return True
elif response['code'] == 1000001:
logger.info(response['errorMessage'])
return False
# 天天领现金浏览模板
def viewCashTask(self,dic):
url = 'https://store.oppo.com/cn/oapi/credits/web/dailyCash/reportDailyTask'
param = {
'taskType':dic['taskType'],
'taskId':f"dailyCash{dic['id']}"
}
headers = {
'Host': 'store.oppo.com',
'Connection': 'keep-alive',
'source_type': '501',
'clientPackage': 'com.oppo.store',
'Cache-Control': 'no-cache',
'Accept': 'application/json, text/plain, */*',
'Referer': 'https://store.oppo.com/cn/app/cashRedEnvelope?activityId=1&us=shouye&um=xuanfu&uc=xianjinhongbao',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'zh-CN,en-US;q=0.9'
}
response = self.sess.get(url=url,headers=headers,params=param).json()
if response['code'] == 200:
logger.info(f"正在执行{dic['taskName']}...")
time.sleep(random.randint(5,7))
self.getCash(dic=dic)
else:
logger.info(f"{dic['taskName']}执行失败")
def runTaskRewardList(self):
for each in self.taskRewardList:
if each['taskName'] == '浏览商品':
if each['taskStatus'] == 0:
self.viewGoods(count=6,flag=1,dic=each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '浏览秒杀专区':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '分享商品':
if each['taskStatus'] == 0:
self.shareGoods(count=2,flag=1,dic=each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '观看直播':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '浏览签到页':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
if each['taskName'] == '浏览领券中心':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '浏览realme商品':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '浏览指定商品':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '浏览一加商品':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
elif each['taskName'] == '浏览OPPO商品':
if each['taskStatus'] == 0:
self.viewCashTask(each)
elif each['taskStatus'] == 1:
self.getCash(dic=each)
elif each['taskStatus'] == 2:
logger.info(f"{each['taskName']}\t已领取")
# pushPlus配信
@staticmethod
def sendForPush():
if [each for each in admin['mask'] if each == os.path.basename(__file__)[:-3]] == []:
with open(file=LOG_FILE,mode='r',encoding='utf-8') as f:
content = f.read()
url = 'http://www.pushplus.plus/send'
data = {
"token": admin['pushGroup']['pushToken'],
"title":"欢太任务通知",
"content":content,
"template":"txt"
}
if admin['pushGroup']['pushToken'] != "":
if admin['pushGroup']['pushTopic'] != "":
data['topic'] = admin['pushGroup']['pushTopic']
response = requests.post(url=url,data=json.dumps(data)).json()
if response['code'] == 200:
logger.info(f"Push Plus发信成功!\n")
else:
logger.info(f"Push Plus发信失败!\t失败原因:{response['msg']}")
else:
logger.info("未配置pushPlus Token,取消配信!")
else:
logger.info(f"{os.path.basename(__file__)[:-3]}\t发信功能被屏蔽")
# 执行欢太商城实例对象
def start(self):
self.sess.headers.update({
"User-Agent":self.dic['UA']
})
self.sess.cookies.update({
"Cookie":self.dic['CK']
})
if self.login() == True:
if self.getDailyCashTask() == True: # 获取天天领现金数据,判断CK是否正确(登录可能成功,但无法跑任务)
self.runTaskRewardList() # 运行天天领现金
logger.info('*' * 40 + '\n')
# 格式化设备信息Json
def transform(string):
dic2 = {}
dic1 = eval(string)
for i in dic1['app_param'][1:-1].split(','):
dic2[i.split(':')[0]] = i.split(':')[-1]
dic1['CK'] = dic1['CK'] + f";app_param={json.dumps(dic2,ensure_ascii=False)}"
return dic1
# 读取青龙CK
# 由于青龙的特殊性,把CK中的 app_param 转换未非正常格式,故需要此函数
def getEnv(key):
lists = []
logger.info("尝试导入青龙面板CK...")
variable = os.environ.get(key)
if (variable == '') or (variable == None):
logger.info("青龙面板环境变量 TH_COOKIE 不存在!")
else:
for each in variable.split('&'):
lists.append(transform(each))
return lists
if __name__ == '__main__':
for each in getEnv('HT_COOKIE'):
if each['CK'] != "" and each['UA'] != "":
dailyCash = DailyCash(each)
for count in range(3):
try:
time.sleep(random.randint(2,5)) # 随机延时
dailyCash.start()
break
except requests.exceptions.ConnectionError:
logger.info(f"{dailyCash.dic['user']}\t请求失败,随机延迟后再次访问")
time.sleep(random.randint(2,5))
continue
else:
logger.info(f"账号: {dailyCash.dic['user']}\n状态: 取消登录\n原因: 多次登录失败")
break