From 96425586e865d638e16ff92de92d6e4ab18b9f21 Mon Sep 17 00:00:00 2001 From: Womsxd <45663319+Womsxd@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:59:54 +0800 Subject: [PATCH] =?UTF-8?q?bbs&=E5=8E=9F=E7=A5=9E=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- captcha.py | 9 +++++++++ genshin.py | 10 +++++++++- mihoyobbs.py | 32 ++++++++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 captcha.py diff --git a/captcha.py b/captcha.py new file mode 100644 index 0000000..3988c19 --- /dev/null +++ b/captcha.py @@ -0,0 +1,9 @@ +from request import http + + +def game_captcha(gt: str, challenge: str): + return None # 失败返回None 成功返回validate + + +def bbs_captcha(gt: str, challenge: str): + return None diff --git a/genshin.py b/genshin.py index 65c0588..60720f5 100644 --- a/genshin.py +++ b/genshin.py @@ -2,6 +2,7 @@ import time import tools import config import random +import captcha import setting from error import * from request import http @@ -46,10 +47,12 @@ class Genshin: return data["data"] def check_in(self, account): + header = {} + header.update(self.headers) for i in range(4): if i != 0: log.info(f'触发验证码,即将进行第{i}次重试,最多3次') - req = http.post(url=setting.genshin_Signurl, headers=self.headers, + req = http.post(url=setting.genshin_Signurl, headers=header, json={'act_id': setting.genshin_Act_id, 'region': account[2], 'uid': account[1]}) if req.status_code == 429: time.sleep(10) # 429同ip请求次数过多,尝试sleep10s进行解决 @@ -57,6 +60,11 @@ class Genshin: continue data = req.json() if data["retcode"] == 0 and data["data"]["success"] == 1: + validate = captcha.game_captcha() + if validate is not None: + header["x-rpc-challenge"] = data["data"]["challenge"] + header["x-rpc-validate"] = validate + header["x-rpc-seccode"] = f'{validate}|jordan' time.sleep(random.randint(6, 15)) else: break diff --git a/mihoyobbs.py b/mihoyobbs.py index ba7797e..ec321ea 100644 --- a/mihoyobbs.py +++ b/mihoyobbs.py @@ -3,6 +3,7 @@ import time import tools import config import random +import captcha import setting from request import http from loghelper import log @@ -47,6 +48,22 @@ class Mihoyobbs: def refresh_list(self) -> None: self.postsList = self.get_list() + def get_pass_challenge(self): + req = http.get(url=setting.bbs_get_captcha, headers=self.headers) + data = req.json() + if data["retcode"] != 0: + return None + validate = captcha.bbs_captcha(data["data"]["gt"], data["data"]["challenge"]) + if validate is not None: + check_req = http.post(url=setting.bbs_captcha_verify, headers=self.headers, + json={"geetest_challenge": data["data"]["challenge"], + "geetest_seccode": validate+"|jordan", + "geetest_validate": validate}) + check = check_req.json() + if check["retcode"] == 0: + return check["data"]["challenge"] + return None + # 获取任务列表,用来判断做了哪些任务 def get_tasks_list(self): global today_get_coins @@ -152,17 +169,28 @@ class Mihoyobbs: # 点赞 def like_posts(self): + header = {} + header.update(self.headers) + challenge = None if self.Task_do["bbs_Like_posts"]: log.info("点赞任务已经完成过了~") else: log.info("正在点赞......") for i in range(self.Task_do["bbs_Like_posts_num"]): - req = http.post(url=setting.bbs_Like_url, headers=self.headers, + req = http.post(url=setting.bbs_Like_url, headers=header, json={"post_id": self.postsList[i][0], "is_cancel": False}) data = req.json() if data["message"] == "OK": log.debug("点赞:{} 成功".format(self.postsList[i][1])) - # 判断取消点赞是否打开 + if challenge is not None: + challenge = None + header.pop("x-rpc-challenge") + elif data["retcode"] == 1034: + log.warning("点赞触发验证码") + challenge = self.get_pass_challenge() + if challenge is not None: + header["x-rpc-challenge"] = challenge + # 判断取消点赞是否打开 if config.config["mihoyobbs"]["cancel_like_posts"]: time.sleep(random.randint(2, 8)) req = http.post(url=setting.bbs_Like_url, headers=self.headers,