-
Notifications
You must be signed in to change notification settings - Fork 113
/
main.py
333 lines (312 loc) · 14.1 KB
/
main.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
# -*- coding: utf-8 -*-
# @Time : 2021/8/17
# @Author : hwkxk(丶大K丶)
# @Email : [email protected]
import requests,json,time,logging,traceback,os,random,notify,datetime,configparser
#用户登录全局变量
client = None
session = None
#日志基础配置
# 创建一个logger
logger = logging.getLogger()
logger.setLevel(logging.INFO)
# 创建一个handler,用于写入日志文件
# w 模式会记住上次日志记录的位置
fh = logging.FileHandler('./log.txt', mode='a', encoding='utf-8')
fh.setFormatter(logging.Formatter("%(message)s"))
logger.addHandler(fh)
# 创建一个handler,输出到控制台
ch = logging.StreamHandler()
ch.setFormatter(logging.Formatter("[%(asctime)s]:%(levelname)s:%(message)s"))
logger.addHandler(ch)
#读取用户配置信息
def readConfig():
try:
#用户配置信息
global userconfig
userconfig = configparser.RawConfigParser()
path ="./config.ini"
userconfig.read(path,encoding="utf-8")
return userconfig
except Exception as e:
print(traceback.format_exc())
logging.error('1.请检查是否在目录下建立了config.ini')
#获取个人信息,判断登录状态
def get_infouser(HT_cookies,HT_UA):
flag = False
global session
session = requests.Session()
headers = {
'Host': 'www.heytap.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',
'User-Agent': HT_UA,
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
'cookie': HT_cookies
}
response = session.get('https://www.heytap.com/cn/oapi/users/web/member/info', headers=headers)
response.encoding='utf-8'
try:
result = response.json()
if result['code'] == 200:
logger.info('==== 欢太商城任务 ====')
logger.info('【登录成功】: ' + result['data']['realName'])
flag = True
else:
logger.info('【登录失败】: ' + result['errorMessage'])
except Exception as e:
print(traceback.format_exc())
logger.error('【登录】: 发生错误,原因为: ' + str(e))
if flag:
return session
else:
return False
#任务中心列表,获取任务及任务状态
def taskCenter():
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',
'User-Agent': HT_UserAgent,
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
'cookie': HT_cookies,
'referer':'https://store.oppo.com/cn/app/taskCenter/index'
}
res1 = client.get('https://store.oppo.com/cn/oapi/credits/web/credits/show', headers=headers)
res1 = res1.json()
return res1
#每日签到
#位置: APP → 我的 → 签到
def daySign_task():
try:
dated = time.strftime("%Y-%m-%d")
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',
'User-Agent': HT_UserAgent,
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
'cookie': HT_cookies,
'referer':'https://store.oppo.com/cn/app/taskCenter/index'
}
res = taskCenter()
status = res['data']['userReportInfoForm']['status']
if status == 0:
res = res['data']['userReportInfoForm']['gifts']
for data in res:
if data['date'] == dated:
qd = data
if qd['today'] == False:
data = "amount=" + str(qd['credits'])
res1 = client.post('https://store.oppo.com/cn/oapi/credits/web/report/immediately', headers=headers,data=data)
res1 = res1.json()
if res1['code'] == 200:
logger.info('【每日签到成功】: ' + res1['data']['message'])
else:
logger.info('【每日签到失败】: ' + str(res1))
else:
print(str(qd['credits']),str(qd['type']),str(qd['gift']))
if len(str(qd['type'])) < 1 :
data = "amount=" + str(qd['credits'])
else:
data = "amount=" + str(qd['credits']) + "&type=" + str(qd['type']) + "&gift=" + str(qd['gift'])
res1 = client.post('https://store.oppo.com/cn/oapi/credits/web/report/immediately', headers=headers,data=data)
res1 = res1.json()
if res1['code'] == 200:
logger.info('【每日签到成功】: ' + res1['data']['message'])
else:
logger.info('【每日签到失败】: ' + str(res1))
else:
logger.info('【每日签到】: 已经签到过了!' )
time.sleep(1)
except Exception as e:
print(traceback.format_exc())
logging.error('【每日签到】: 错误,原因为: ' + str(e))
#浏览商品 10个sku +20 分
#位置: APP → 我的 → 签到 → 每日任务 → 浏览商品
def daily_viewgoods():
try:
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',
'cookie': HT_cookies,
}
res = taskCenter()
res = res['data']['everydayList']
for data in res:
if data['name'] == '浏览商品':
qd = data
if qd['completeStatus'] == 0:
shopList = client.get('https://msec.opposhop.cn/goods/v1/SeckillRound/goods/115?pageSize=12¤tPage=1')
res = shopList.json()
if res['meta']['code'] == 200:
for skuinfo in res['detail']:
skuid = skuinfo['skuid']
print('正在浏览商品ID:', skuid)
client.get('https://msec.opposhop.cn/goods/v1/info/sku?skuId='+ str(skuid), headers=headers)
time.sleep(5)
res2 = cashingCredits(qd['marking'],qd['type'],qd['credits'])
if res2 == True:
logger.info('【每日浏览商品】: ' + '任务完成!积分领取+' + str(qd['credits']))
else:
logger.info('【每日浏览商品】: ' + "领取积分奖励出错!")
else:
logger.info('【每日浏览商品】: ' + '错误,获取商品列表失败')
elif qd['completeStatus'] == 1:
res2 = cashingCredits(qd['marking'],qd['type'],qd['credits'])
if res2 == True:
logger.info('【每日浏览商品】: ' + '任务完成!积分领取+' + str(qd['credits']))
else:
logger.info('【每日浏览商品】: ' + '领取积分奖励出错!')
else:
logger.info('【每日浏览商品】: ' + '任务已完成!')
except Exception as e:
print(traceback.format_exc())
logging.error('【每日浏览任务】: 错误,原因为: ' + str(e))
def daily_sharegoods():
try:
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',
'cookie': HT_cookies,
}
daySignList = taskCenter()
res = daySignList
res = res['data']['everydayList']
for data in res:
if data['name'] == '分享商品到微信':
qd = data
if qd['completeStatus'] == 0:
count = qd['readCount']
endcount = qd['times']
while (count <= endcount):
client.get('https://msec.opposhop.cn/users/vi/creditsTask/pushTask?marking=daily_sharegoods', headers=headers)
count += 1
res2 = cashingCredits(qd['marking'],qd['type'],qd['credits'])
if res2 == True:
logger.info('【每日分享商品】: ' + '任务完成!积分领取+' + str(qd['credits']))
else:
logger.info('【每日分享商品】: ' + '领取积分奖励出错!')
elif qd['completeStatus'] == 1:
res2 = cashingCredits(qd['marking'],qd['type'],qd['credits'])
if res2 == True:
logger.info('【每日分享商品】: ' + '任务完成!积分领取+' + str(qd['credits']))
else:
logger.info('【每日分享商品】: ' + '领取积分奖励出错!')
else:
logger.info('【每日分享商品】: ' + '任务已完成!')
except Exception as e:
print(traceback.format_exc())
logging.error('【每日分享商品】: 错误,原因为: ' + str(e))
def daily_viewpush():
try:
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',
'cookie': HT_cookies,
}
daySignList = taskCenter()
res = daySignList
res = res['data']['everydayList']
for data in res:
if data['name'] == '点推送消息':
qd = data
if qd['completeStatus'] == 0:
count = qd['readCount']
endcount = qd['times']
while (count <= endcount):
client.get('https://msec.opposhop.cn/users/vi/creditsTask/pushTask?marking=daily_viewpush', headers=headers)
count += 1
res2 = cashingCredits(qd['marking'],qd['type'],qd['credits'])
if res2 == True:
logger.info('【每日点推送】: ' + '任务完成!积分领取+' + str(qd['credits']))
else:
logger.info('【每日点推送】: ' + '领取积分奖励出错!')
elif qd['completeStatus'] == 1:
res2 = cashingCredits(qd['marking'],qd['type'],qd['credits'])
if res2 == True:
logger.info('【每日点推送】: ' + '任务完成!积分领取+' + str(qd['credits']))
else:
logger.info('【每日点推送】: ' + '领取积分奖励出错!')
else:
logger.info('【每日点推送】: ' + '任务已完成!')
except Exception as e:
print(traceback.format_exc())
logging.error('【每日推送消息】: 错误,原因为: ' + str(e))
#执行完成任务领取奖励
def cashingCredits(info_marking,info_type,info_credits):
headers = {
'Host': 'store.oppo.com',
'clientPackage': 'com.oppo.store',
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/x-www-form-urlencoded',
'Connection': 'keep-alive',
'User-Agent': HT_UserAgent,
'Accept-Language': 'zh-cn',
'Accept-Encoding': 'gzip, deflate, br',
'cookie': HT_cookies,
'Origin': 'https://store.oppo.com',
'X-Requested-With': 'com.oppo.store',
'referer':'https://store.oppo.com/cn/app/taskCenter/index?us=gerenzhongxin&um=hudongleyuan&uc=renwuzhongxin'
}
data = "marking=" + str(info_marking) + "&type=" + str(info_type) + "&amount=" + str(info_credits)
res = client.post('https://store.oppo.com/cn/oapi/credits/web/credits/cashingCredits', data=data, headers=headers)
res = res.json()
if res['code'] == 200:
return True
else:
return False
#函数入口
def main(event, context):
users = readConfig()
#清空上一个用户的日志记录
open('./log.txt',mode='w',encoding='utf-8')
global client
global HT_cookies
global HT_UserAgent
HT_cookies = users.get("config","cookies")
HT_UserAgent = users.get("config","User-Agent")
#print(HT_cookies,HT_UserAgent)
client = get_infouser(HT_cookies,HT_UserAgent)
#如果不想做特定任务可以手动注释
if client != False:
daySign_task() #执行每日签到
daily_viewgoods() #执行每日商品浏览任务
daily_sharegoods() #执行每日商品分享任务
#daily_viewpush() #执行每日点推送任务 该任务在2021-9-16下线 注释
if users.has_option("dingding", 'dingtalkWebhook'):
notify.sendDing(users.get("dingding","dingtalkWebhook"),users.get("dingding","dingtalksecret")) #钉钉推送日记
if users.has_option("telegramBot", 'tgToken'):
notify.sendTg(users.get("telegramBot","tgToken"),users.get("telegramBot","tgUserId"),users.get("telegramBot","tghost")) #TG机器人推送日记
if users.has_option("pushplus", 'pushplusToken'):
notify.sendPushplus(users.get("pushplus","pushplusToken")) #push+ 推送日记
if users.has_option("enterpriseWechat", 'id'):
notify.sendWechat(users.get("enterpriseWechat","id"),users.get("enterpriseWechat","secret"),users.get("enterpriseWechat","agentld")) #企业微信通知
if users.has_option("IFTTT", 'apiKey'):
notify.sendIFTTT(users.get("IFTTT","apiKey"),users.get("IFTTT","eventName")) #IFTTT 推送日记
if users.has_option("Bark", 'Barkkey'):
notify.sendBark(users.get("Bark","Barkkey"),users.get("Bark","Barksave")) #Bark推送助手
#主函数入口
if __name__ == '__main__':
main("","")