diff --git a/error.py b/error.py index b5e6ff0..9cd4d75 100644 --- a/error.py +++ b/error.py @@ -4,3 +4,11 @@ class CookieError(Exception): def __str__(self): return repr(self.info) + + +class CaptchaError(Exception): + def __init__(self, info): + self.info = info + + def __str__(self): + return repr(self.info) diff --git a/genshin.py b/genshin.py index 649fa0d..211e7f6 100644 --- a/genshin.py +++ b/genshin.py @@ -3,17 +3,18 @@ import tools import config import random import setting +from error import * from request import http from loghelper import log -from error import CookieError from account import get_account_list class Genshin: def __init__(self) -> None: - self.headers = setting.headers + self.headers = {} + self.headers.update(setting.headers) self.headers['DS'] = tools.get_ds(web=True) - self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true'\ + self.headers['Referer'] = 'https://webstatic.mihoyo.com/bbs/event/signin-ys/index.html?bbs_auth_required=true' \ f'&act_id={setting.genshin_Act_id}&utm_source=bbs&utm_medium=mys&utm_campaign=icon' self.headers['Cookie'] = config.config["account"]["cookie"] self.headers['x-rpc-device_id'] = tools.get_device_id() @@ -43,6 +44,17 @@ class Genshin: raise CookieError("BBS Cookie Errror") return data["data"] + def check_in(self, account): + for i in range(3): + req = http.post(url=setting.genshin_Signurl, headers=self.headers, + json={'act_id': setting.genshin_Act_id, 'region': account[2], 'uid': account[1]}) + data = req.json() + if data["retcode"] == 0 and data["data"]["success"] == 1: + time.sleep(random.randint(4, 10)) + else: + break + return req + # 签到 def sign_account(self) -> str: return_data = "原神: " @@ -57,14 +69,13 @@ class Genshin: log.warning(f"旅行者{i[0]}是第一次绑定米游社,请先手动签到一次") else: sign_days = is_data["total_sign_day"] - 1 - ok = True - if is_data["is_sign"]: + ok = True + if not is_data["is_sign"]: log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}") sign_days += 1 else: time.sleep(random.randint(2, 8)) - req = http.post(url=setting.genshin_Signurl, headers=self.headers, - json={'act_id': setting.genshin_Act_id, 'region': i[2], 'uid': i[1]}) + req = self.check_in(i) data = req.json() if data["retcode"] == 0 and data["data"]["success"] == 0: log.info(f"旅行者{i[0]}签到成功~\r\n今天获得的奖励是" @@ -74,12 +85,13 @@ class Genshin: log.info(f"旅行者{i[0]}今天已经签到过了~\r\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days])}") else: s = "账号签到失败!" - if data["data"] != "" and data.get("data").get("success",-1): + if data["data"] != "" and data.get("data").get("success", -1): s += "原因: 验证码\njson信息:" + req.text log.warning(s) ok = False if ok: - return_data += f"\n{i[0]}已连续签到{sign_days}天\n今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days - 1])}" + return_data += f"\n{i[0]}已连续签到{sign_days}天\n" \ + f"今天获得的奖励是{tools.get_item(self.checkin_rewards[sign_days - 1])}" else: return_data += f"\n{i[0]},本次签到失败" if data["data"] != "" and data["data"]["success"] == 1: diff --git a/main.py b/main.py index b394c24..9f0afdc 100644 --- a/main.py +++ b/main.py @@ -9,8 +9,8 @@ import setting import mihoyobbs import honkai3rd import tearsofthemis +from error import * from loghelper import log -from error import CookieError def main(): @@ -38,6 +38,7 @@ def main(): if int(i["id"]) == 5: setting.mihoyobbs_List_Use.append(i) # 米游社签到 + ret_code = 0 if config.config["mihoyobbs"]["enable"]: bbs = mihoyobbs.Mihoyobbs() if bbs.Task_do["bbs_Sign"] and bbs.Task_do["bbs_Read_posts"] and bbs.Task_do["bbs_Like_posts"] and \ @@ -88,9 +89,12 @@ def main(): if config.config["games"]["cn"]["genshin"]["auto_checkin"]: log.info("正在进行原神签到") genshin_help = genshin.Genshin() - return_data += "\n\n" + genshin_help.sign_account() + genshin_message = genshin_help.sign_account() + if "触发验证码" in genshin_message: + ret_code = 3 + return_data += "\n\n" + genshin_message time.sleep(random.randint(2, 8)) - return 0, return_data + return ret_code, return_data elif config.config["account"]["cookie"] == "CookieError": raise CookieError('Cookie expires') else: diff --git a/main_multi.py b/main_multi.py index 5a09d0f..11444d8 100644 --- a/main_multi.py +++ b/main_multi.py @@ -34,7 +34,7 @@ def main_multi(autorun: bool): input("请输入回车继续,需要重新搜索配置文件请Ctrl+C退出脚本") except KeyboardInterrupt: exit(0) - results = {"ok": [], "close": [], "error": []} + results = {"ok": [], "close": [], "error": [], "captcha": []} for i in iter(config_list): log.info(f"正在执行{i}") setting.mihoyobbs_List_Use = [] @@ -46,6 +46,8 @@ def main_multi(autorun: bool): else: if run_code == 0: results["ok"].append(i) + elif run_code == 3: + results["captcha"].append(i) else: results["close"].append(i) log.info(f"{i}执行完毕") @@ -53,13 +55,16 @@ def main_multi(autorun: bool): print("") push_message = f'脚本执行完毕,共执行{len(config_list)}个配置文件,成功{len(results["ok"])}个,' \ f'没执行{len(results["close"])}个,失败{len(results["error"])}个' \ - f'\r\n没执行的配置文件: {results["close"]}\r\n执行失败的配置文件: {results["error"]}' + f'\r\n没执行的配置文件: {results["close"]}\r\n执行失败的配置文件: {results["error"]}\r\n' \ + f'触发原神验证码的配置文件: {results["captcha"]} ' log.info(push_message) status = 0 if len(results["error"]) == len(config_list): status = 1 elif len(results["error"]) != 0: status = 2 + elif len(results["captcha"]) != 0: + status = 3 push.push(status, push_message) diff --git a/push.py b/push.py index 0483f26..fcc2aa0 100644 --- a/push.py +++ b/push.py @@ -27,6 +27,8 @@ def title(status): return "「米游社脚本」执行失败!" elif status == 2: return "「米游社脚本」部分账号执行失败!" + elif status == 3: + return "「米游社脚本」原神签到触发验证码!" # telegram的推送 @@ -83,7 +85,7 @@ def wecom(status, push_message): except: # 没有配置时赋默认值 touser = '@all' - + push_token = http.post( url=f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={secret}', data="" @@ -112,11 +114,11 @@ def pushdeer(status, push_message): } ) + # 钉钉群机器人 def dingrobot(status, push_message): api_url = cfg.get('dingrobot', 'webhook') # https://oapi.dingtalk.com/robot/send?access_token=XXX - secret = cfg.get('dingrobot', 'secret') # 安全设置 -> 加签 -> 密钥 -> SEC* - + secret = cfg.get('dingrobot', 'secret') # 安全设置 -> 加签 -> 密钥 -> SEC* if secret: timestamp = str(round(time.time() * 1000)) sign_string = f"{timestamp}\n{secret}" @@ -127,16 +129,17 @@ def dingrobot(status, push_message): ).digest() sign = urllib.parse.quote_plus(base64.b64encode(hmac_code)) api_url = f"{api_url}×tamp={timestamp}&sign={sign}" - + rep = http.post( url=api_url, headers={"Content-Type": "application/json; charset=utf-8"}, json={ - "msgtype": "text", "text": { "content": title(status) + "\r\n" + push_message } + "msgtype": "text", "text": {"content": title(status) + "\r\n" + push_message} } ).json() log.info(f"推送结果:{rep.get('errmsg')}") + # Bark def bark(status, push_message): rep = http.get( @@ -144,6 +147,7 @@ def bark(status, push_message): ).json() log.info(f"推送结果:{rep.get('message')}") + # gotify def gotify(status, push_message): rep = http.post( @@ -156,6 +160,7 @@ def gotify(status, push_message): ).json() log.info(f"推送结果:{rep.get('errmsg')}") + def push(status, push_message): if not load_config(): return 0 @@ -179,5 +184,6 @@ def push(status, push_message): log.info("推送完毕......") return 1 + if __name__ == "__main__": push(0, f'推送验证{int(time.time())}')