2023-11-18 10:37:51 +00:00
|
|
|
"""签到实例"""
|
|
|
|
|
2023-11-13 13:18:59 +00:00
|
|
|
import time
|
|
|
|
|
2023-11-19 12:19:54 +00:00
|
|
|
from typing import Dict, List, Optional, Type, Union, Any
|
2023-11-13 13:18:59 +00:00
|
|
|
|
|
|
|
from ..data_model import ApiResultHandler, DailyTasksResult, SignResultHandler
|
|
|
|
from ..request import get, post
|
|
|
|
from ..logger import log
|
|
|
|
|
|
|
|
|
|
|
|
class BaseSign:
|
|
|
|
"""
|
|
|
|
签到基类
|
|
|
|
"""
|
|
|
|
NAME = ""
|
|
|
|
"""任务名字"""
|
|
|
|
|
|
|
|
PARAMS = {}
|
|
|
|
"""签到参数"""
|
|
|
|
|
|
|
|
DATA = {}
|
|
|
|
"""签到数据"""
|
|
|
|
|
|
|
|
URL_SIGN = ""
|
|
|
|
"""签到地址"""
|
|
|
|
|
|
|
|
AVAILABLE_SIGNS: Dict[str, Type["BaseSign"]] = {}
|
|
|
|
"""可用的子类"""
|
|
|
|
|
|
|
|
def __init__(self, cookie: Dict, token: Optional[str] = None):
|
|
|
|
self.cookie = cookie
|
|
|
|
self.token = token
|
|
|
|
self.headers = {
|
|
|
|
}
|
|
|
|
|
2023-11-22 04:02:10 +00:00
|
|
|
async def check_daily_tasks(self, nolog: bool = False) -> Union[List[DailyTasksResult], List[None]]:
|
2023-11-18 10:37:51 +00:00
|
|
|
"""获取每日任务状态"""
|
2023-11-13 13:18:59 +00:00
|
|
|
try:
|
|
|
|
response = await get('https://api.vip.miui.com/mtop/planet/vip/member/getCheckinPageCakeList',
|
|
|
|
cookies=self.cookie)
|
|
|
|
log.debug(response.text)
|
|
|
|
result = response.json()
|
|
|
|
api_data = ApiResultHandler(result)
|
|
|
|
if api_data.success:
|
|
|
|
task_status = []
|
2023-11-22 04:02:10 +00:00
|
|
|
tasks: List[Dict[str, List[Dict[str, Any]]]] = list(filter(
|
|
|
|
lambda x: x['head']['title'] in ["每日任务", "其他任务"], api_data.data))
|
2023-11-19 12:19:54 +00:00
|
|
|
for task in tasks:
|
|
|
|
for daily_task in task['data']:
|
|
|
|
task_name = daily_task['title']
|
|
|
|
task_desc = daily_task.get('desc', '')
|
2023-11-22 04:02:10 +00:00
|
|
|
show_type = True if daily_task['showType'] == 0 else False # pylint: disable=simplifiable-if-expression
|
2023-11-19 12:19:54 +00:00
|
|
|
task_status.append(DailyTasksResult(name=task_name, showType=show_type, desc=task_desc))
|
2023-11-13 13:18:59 +00:00
|
|
|
return task_status
|
|
|
|
else:
|
2023-11-18 10:37:51 +00:00
|
|
|
if not nolog:
|
|
|
|
log.error(f"获取每日任务状态失败:{api_data.message}")
|
|
|
|
return []
|
2023-11-22 04:02:10 +00:00
|
|
|
except Exception: # pylint: disable=broad-exception-caught
|
2023-11-18 10:37:51 +00:00
|
|
|
if not nolog:
|
|
|
|
log.exception("获取每日任务异常")
|
2023-11-13 13:18:59 +00:00
|
|
|
return []
|
|
|
|
|
|
|
|
async def sign(self) -> bool:
|
|
|
|
"""
|
|
|
|
每日任务处理器
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
params = self.PARAMS.copy()
|
|
|
|
params['miui_vip_ph'] = self.cookie['miui_vip_ph'] if 'miui_vip_ph' in self.cookie else params
|
|
|
|
params['token'] = self.token if 'token' in params else params
|
|
|
|
data = self.DATA.copy()
|
|
|
|
data['miui_vip_ph'] = self.cookie['miui_vip_ph'] if 'miui_vip_ph' in self.cookie else data
|
2023-11-15 13:07:29 +00:00
|
|
|
if 'token' in data:
|
|
|
|
if self.token:
|
|
|
|
data['token'] = self.token
|
|
|
|
else:
|
|
|
|
log.info(f"未获取到token, 跳过{self.NAME}")
|
|
|
|
return False
|
2023-11-13 13:18:59 +00:00
|
|
|
response = await post(self.URL_SIGN,
|
|
|
|
params=params, data=data,
|
|
|
|
cookies=self.cookie, headers=self.headers)
|
|
|
|
log.debug(response.text)
|
|
|
|
result = response.json()
|
|
|
|
api_data = SignResultHandler(result)
|
|
|
|
if api_data:
|
2023-11-19 12:19:54 +00:00
|
|
|
if api_data.growth:
|
|
|
|
log.success(f"{self.NAME}结果: 成长值+{api_data.growth}")
|
|
|
|
else:
|
|
|
|
log.success(f"{self.NAME}结果: {api_data.message}")
|
2023-11-13 13:18:59 +00:00
|
|
|
return True
|
|
|
|
elif api_data.ck_invalid:
|
|
|
|
log.error(f"{self.NAME}失败: Cookie无效")
|
|
|
|
return False
|
|
|
|
else:
|
2023-11-19 12:19:54 +00:00
|
|
|
log.error(f"{self.NAME}失败:{api_data.message}")
|
2023-11-13 13:18:59 +00:00
|
|
|
return False
|
2023-11-22 04:02:10 +00:00
|
|
|
except Exception: # pylint: disable=broad-exception-caught
|
2023-11-13 13:18:59 +00:00
|
|
|
log.exception(f"{self.NAME}出错")
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class CheckIn(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
每日签到
|
|
|
|
"""
|
|
|
|
NAME = "每日签到"
|
|
|
|
|
|
|
|
PARAMS = {
|
|
|
|
'ref': 'vipAccountShortcut',
|
|
|
|
'pathname': '/mio/checkIn',
|
|
|
|
'version': 'dev.231026',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
|
|
|
|
DATA = {
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}",
|
2023-11-15 13:07:29 +00:00
|
|
|
'token': "{token}"
|
2023-11-13 13:18:59 +00:00
|
|
|
}
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/user/checkinV2'
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class BrowsePost(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
浏览帖子超过10秒
|
|
|
|
"""
|
|
|
|
NAME = "浏览帖子超过10秒"
|
|
|
|
|
|
|
|
PARAMS = {
|
|
|
|
'ref': 'vipAccountShortcut',
|
|
|
|
'pathname': '/mio/detail',
|
|
|
|
'version': 'dev.231026',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
DATA = {
|
|
|
|
'action': 'BROWSE_POST_10S',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByActionV2'
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class BrowseUserPage(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
浏览个人主页10s
|
|
|
|
"""
|
|
|
|
NAME = "浏览个人主页10s"
|
|
|
|
|
|
|
|
PARAMS = {
|
|
|
|
'ref': 'vipAccountShortcut',
|
|
|
|
'pathname': '/mio/detail',
|
|
|
|
'version': 'dev.231026',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
DATA = {
|
|
|
|
'action': 'BROWSE_SPECIAL_PAGES_USER_HOME',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByActionV2'
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class BrowseSpecialPage(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
浏览指定专题页
|
|
|
|
"""
|
|
|
|
NAME = "浏览指定专题页"
|
|
|
|
|
|
|
|
PARAMS = {
|
|
|
|
'ref': 'vipAccountShortcut',
|
|
|
|
'pathname': '/mio/detail',
|
|
|
|
'version': 'dev.231026',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
DATA = {
|
|
|
|
'action': 'BROWSE_SPECIAL_PAGES_SPECIAL_PAGE',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/member/addCommunityGrowUpPointByActionV2'
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class BoardFollow(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
加入小米圈子
|
|
|
|
"""
|
|
|
|
NAME = "加入小米圈子"
|
|
|
|
|
|
|
|
PARAMS = {
|
|
|
|
'pathname': '/mio/allboard',
|
|
|
|
'version': 'dev.20051',
|
|
|
|
'boardId': '558495',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/api/community/board/follow'
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class BoardUnFollow(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
退出小米圈子
|
|
|
|
"""
|
|
|
|
NAME = "退出小米圈子"
|
|
|
|
|
|
|
|
PARAMS = {
|
|
|
|
'pathname': '/mio/allboard',
|
|
|
|
'version': 'dev.20051',
|
|
|
|
'boardId': '558495',
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/api/community/board/unfollow'
|
|
|
|
|
|
|
|
|
2023-11-18 10:37:51 +00:00
|
|
|
class ThumbUp(BaseSign):
|
2023-11-13 13:18:59 +00:00
|
|
|
"""
|
|
|
|
点赞他人帖子
|
|
|
|
"""
|
|
|
|
NAME = "点赞他人帖子"
|
|
|
|
|
|
|
|
DATA = {
|
|
|
|
'postId': '36625780',
|
|
|
|
'sign': '36625780',
|
|
|
|
'timestamp': int(round(time.time() * 1000))
|
|
|
|
}
|
|
|
|
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/mtop/planet/vip/content/announceThumbUp'
|
|
|
|
|
2023-11-22 04:02:10 +00:00
|
|
|
|
2023-11-19 12:19:54 +00:00
|
|
|
class CarrotPull(BaseSign):
|
|
|
|
"""
|
|
|
|
参与拔萝卜获得奖励
|
|
|
|
"""
|
|
|
|
NAME = "参与拔萝卜获得奖励"
|
|
|
|
DATA = {
|
|
|
|
'miui_vip_ph': "{miui_vip_ph}"
|
|
|
|
}
|
|
|
|
URL_SIGN = 'https://api.vip.miui.com/api/carrot/pull'
|
2023-11-13 13:18:59 +00:00
|
|
|
|
2023-11-22 04:02:10 +00:00
|
|
|
|
2023-11-13 13:18:59 +00:00
|
|
|
# 注册签到任务
|
2023-11-18 10:37:51 +00:00
|
|
|
BaseSign.AVAILABLE_SIGNS[CheckIn.NAME] = CheckIn
|
|
|
|
BaseSign.AVAILABLE_SIGNS[BrowsePost.NAME] = BrowsePost
|
|
|
|
BaseSign.AVAILABLE_SIGNS[BrowseUserPage.NAME] = BrowseUserPage
|
|
|
|
BaseSign.AVAILABLE_SIGNS[BrowseSpecialPage.NAME] = BrowseSpecialPage
|
|
|
|
BaseSign.AVAILABLE_SIGNS[BoardFollow.NAME] = BoardFollow
|
|
|
|
BaseSign.AVAILABLE_SIGNS[BoardUnFollow.NAME] = BoardUnFollow
|
|
|
|
BaseSign.AVAILABLE_SIGNS[ThumbUp.NAME] = ThumbUp
|
2023-11-19 12:19:54 +00:00
|
|
|
BaseSign.AVAILABLE_SIGNS[CarrotPull.NAME] = CarrotPull
|