Skip to content

Instantly share code, notes, and snippets.

@ruter
Last active November 19, 2021 02:24
Show Gist options
  • Save ruter/41286c3bc0082c2bf8a41f3e4d98cc9e to your computer and use it in GitHub Desktop.
Save ruter/41286c3bc0082c2bf8a41f3e4d98cc9e to your computer and use it in GitHub Desktop.
屈臣氏小程序签到+造美值任务
#!/usr/bin/env python3
# -*- coding: utf-8 -*
# 屈臣氏 - 造美值中心
import os, re, sys
import json
import time
try:
import requests
except Exception as e:
print(e, "\n缺少requests 模块,请执行命令安装:python3 -m pip install requests")
exit(3)
requests.packages.urllib3.disable_warnings()
API_URL = 'https://mystore-fb.watsonsvip.com.cn:10500'
# 多个账号请按以下格式添加在列表中 [{}, {}, ...]
USER_CONFIG = [{
'name': '', # 账号名称,发送消息使用,任意值
'union_id': '', # headers 中的 unionId
'open_id': '', # headers 中的 openId
'auth': '', # headers 中的 Authorization 值中 Bearer 后的内容
'ua': '', # headers 中的 User-Agent 或自己指定
}]
def get_headers(config):
return {
"Host": "mystore-fb.watsonsvip.com.cn:10500",
"Authorization": f"Bearer {config.get('auth')}",
"unionId": config.get('union_id'),
"openId": config.get('open_id'),
"authorizer-appid": "wx1ffbd6927043dff7",
"Accept-Language": "zh-cn",
"Accept-Encoding": "gzip, deflate, br",
"User-Agent": config.get('ua'),
"Referer": "https://servicewechat.com/wx1ffbd6927043dff7/329/page-frame.html",
"Connection": "keep-alive",
"Content-Type": "application/json"
}
def get_mission_ids(headers):
task_api_url = f'{API_URL}/thirdparty/api/index'
resp = requests.get(task_api_url, headers=headers)
res = resp.json().get('data', {})
mission_ids = []
for mission in res.get('missions', []):
if mission.get('finished', 0) == 0:
if mission.get('linkType', 2) == 2:
mission_ids.append(str(mission.get('id')))
else:
mission_ids.append(mission.get('id'))
return mission_ids
def do_mission(mission_id, headers):
mission_api_url = f'{API_URL}/thirdparty/api/missions'
resp = requests.post(mission_api_url, headers=headers, json={"id": mission_id})
res = resp.json().get('data', {})
if res:
msg = f'任务名称:{res.get("title", "?")}\n造美值:{res.get("value", 0)}'
else:
msg = f'任务未完成(ID: {mission_id})'
print(msg)
return msg
def do_sign(headers):
sign_api_url = f'{API_URL}/wx/signIn/iter/sign'
resp = requests.post(sign_api_url, headers=headers, json={"unionId": headers.get('unionId')})
res = resp.json()
if res.get("code", "0") == 11000:
msg = res.get("errorMsg", "未知错误")
print(msg)
return msg
res = res.get('result', {})
if res:
msg = f'签到成功\n红包奖励:{res.get("rewardAmount", 0) / 100.0}\n造美值:{res.get("beautyAmount", 0)}'
else:
msg = f'签到失败'
print(msg)
return msg
def start():
scriptName='### 屈臣氏 - 造美值中心 ###'
print(scriptName)
msg_lst = []
for conf in USER_CONFIG:
msg = f'>>> 账号 {conf.get("name", "?")} <<<'
msg_lst.append(msg)
print(msg)
headers = get_headers(conf)
mission_ids = get_mission_ids(headers)
msg = f'任务 ID: {mission_ids}'
print(msg)
msg_lst.append(msg)
for mission_id in mission_ids:
mission_msg = do_mission(mission_id, headers)
msg_lst.append(mission_msg)
time.sleep(1)
msg = '##### 每日签到 #####'
print(msg)
msg_lst.append(msg)
msg = do_sign(headers)
msg_lst.append(msg)
msg = '\n\n'.join(msg_lst)
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
send(scriptName, msg)
except:
pass
if __name__ == '__main__':
start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment