bbs&原神验证码支持

This commit is contained in:
Womsxd 2022-10-08 15:59:54 +08:00
parent 1e6b05b16c
commit 96425586e8
No known key found for this signature in database
GPG Key ID: 0FE76418EE689B68
3 changed files with 48 additions and 3 deletions

9
captcha.py Normal file
View File

@ -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

View File

@ -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

View File

@ -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,16 +169,27 @@ 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))