forked from Mashiro2000/HeyTapTask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TimingCash.py
187 lines (170 loc) · 6.42 KB
/
TimingCash.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
# !/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Time : 2021/9/17
# @Author : MashiroF
# @File : TimingCash.py
# @Software: PyCharm
'''
cron: */30 * * * * TimingCash.py
new Env('欢太定时现金');
'''
import os
import re
import sys
import time
import random
# 配置文件
try:
from HT_config import downFlag,notifyBlackList,logger
import requests
except Exception as error:
logger.info(f'失败原因:{error}')
sys.exit(0)
# 判断是否发生下载行为
if downFlag == True:
logger.info('发生下载行为,应退出程序,编辑配置文件')
sys.exit(0)
# 配信文件
try:
from sendNotify import send
except Exception as error:
logger.info('推送文件有误')
logger.info(f'失败原因:{error}')
sys.exit(0)
# 导入账户
try:
from HT_account import accounts
lists = accounts
except Exception as error:
logger.info(f'失败原因:{error}')
lists = []
# 配信内容格式
allMess = ''
def notify(content=None):
global allMess
allMess = allMess + content + '\n'
logger.info(content)
# 日志录入时间
notify(f"任务:欢太定时现金\n时间:{time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())}")
class TimingCash:
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:
notify(f"{self.dic['user']}\t登录成功")
return True
else:
notify(f"{self.dic['user']}\t登录失败")
return False
# 天天领取现金
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.timingRewardList = response['data']['timingRewardList']
return True
elif response['code'] == 1000001:
notify(f"[定时红包]\t{response['errorMessage']}")
return False
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':1,
'channelRewardId':dic['id']
}
response = self.sess.post(url=url,headers=headers,data=data).json()
if response['code'] == 200:
notify(f"[定时红包]\t第{dic['id']}个红包:{response['data']['amount']}")
elif response['code'] == 1000001:
notify(f"[定时红包]\t第{dic['id']}个红包:{response['errorMessage']}")
def runtimeReward(self):
for each in self.timingRewardList:
if each['hasDraw'] == False:
self.getCash(dic=each)
break
# 执行欢太商城实例对象
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:
self.runtimeReward()
notify('*' * 40 + '\n')
# 检测CK是否存在必备参数
def checkHT(dic):
CK = dic['CK']
if len(re.findall(r'source_type=.*?;',CK)) == 0:
notify(f"{dic['user']}\tCK格式有误:可能缺少`source_type`字段")
return False
if len(re.findall(r'TOKENSID=.*?;',CK)) == 0:
notify(f"{dic['user']}\tCK格式有误:可能缺少`TOKENSID`字段")
return False
if len(re.findall(r'app_param=.*?[;]?',CK)) == 0:
notify(f"{dic['user']}\tCK格式有误:可能缺少`app_param`字段")
return False
return True
# 兼容云函数
def main_handler(event, context):
global lists
for each in lists:
if all(each.values()):
if checkHT(each):
timingCash = TimingCash(each)
for count in range(3):
try:
time.sleep(random.randint(2,5)) # 随机延时
timingCash.start()
break
except requests.exceptions.ConnectionError:
notify(f"{timingCash.dic['user']}\t请求失败,随机延迟后再次访问")
time.sleep(random.randint(2,5))
continue
else:
notify(f"账号: {timingCash.dic['user']}\n状态: 取消登录\n原因: 多次登录失败")
break
if not os.path.basename(__file__).split('_')[-1][:-3] in notifyBlackList:
send('欢太定时现金',allMess)
if __name__ == '__main__':
main_handler(None,None)