Skip to content

Commit

Permalink
feat: rrocr 添加
Browse files Browse the repository at this point in the history
  • Loading branch information
mikumifa committed Jun 11, 2024
1 parent 625163f commit 64667db
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 71 deletions.
68 changes: 68 additions & 0 deletions geetest/CapSolverValidator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import time

import loguru
import requests
from retry import retry

from config import cookies_config_path, global_cookieManager
from geetest.Validator import Validator
from util.bili_request import BiliRequest


class CapSolverValidator(Validator):
def __init__(self):
self.cookieManager = global_cookieManager
pass

@retry()
def validate(self, appkey, gt, challenge, referer="http://127.0.0.1:7860/") -> str:
if appkey is None or appkey == "":
appkey = self.cookieManager.get_config_value("appkey", "")
else:
self.cookieManager.set_config_value("appkey", appkey)
payload = {
"clientKey": appkey,
"task": {
"type": 'GeeTestTaskProxyLess',
"websiteURL": referer,
"gt": gt,
"challenge": challenge,
}}
res = requests.post("https://api.capsolver.com/createTask", json=payload)
resp = res.json()
task_id = resp.get("taskId")
if not task_id:
raise ValueError("Failed to create task: " + res.text)
loguru.logger.info(f"Got taskId: {task_id} / Getting result...")
while True:
time.sleep(1)
payload = {"clientKey": appkey, "taskId": task_id}
res = requests.post("https://api.capsolver.com/getTaskResult", json=payload)
resp = res.json()
status = resp.get("status")
if status == "ready":
loguru.logger.info(resp.get("solution"))
return resp.get("solution")['validate']
if status == "failed" or resp.get("errorId"):
raise ValueError("Solve failed! response: " + res.text)
if status == "processing":
continue


if __name__ == "__main__":
# 使用示例
appkey = "xxxxxxxxxxxxxxxxxxx"
_request = BiliRequest(cookies_config_path=cookies_config_path)
test_res = _request.get(
"https://passport.bilibili.com/x/passport-login/captcha?source=main_web"
).json()
challenge = test_res["data"]["geetest"]["challenge"]
gt = test_res["data"]["geetest"]["gt"]
loguru.logger.info(challenge)
loguru.logger.info(gt)
validator = CapSolverValidator()
try:
validate_string = validator.validate(appkey, gt, challenge)
print(f"Validation String: {validate_string}")
except Exception as e:
print(f"Error: {e}")
67 changes: 67 additions & 0 deletions geetest/RROCRValidator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
from urllib import parse

import loguru
import requests
from retry import retry

from config import cookies_config_path, global_cookieManager
from geetest.Validator import Validator
from util.bili_request import BiliRequest
from util.config_util import CookieManager


class RROCRValidator(Validator):
def __init__(self):
self.url = "http://api.rrocr.com/api/recognize.html"
self.headers = {
"User-Agent": "Mozilla/5.0 Chrome/77.0.3865.120 Safari/537.36",
"Accept": "text/html",
"Content-Type": "application/x-www-form-urlencoded"
}
self.cookieManager = global_cookieManager

@retry()
def validate(self, appkey, gt, challenge, referer="http://www.baidu.com", ip='', host='') -> str:
if appkey is None or appkey == "":
appkey = self.cookieManager.get_config_value("appkey", "")
else:
self.cookieManager.set_config_value("appkey", appkey)
data = {
"appkey": appkey,
"gt": gt,
"challenge": challenge,
"referer": referer,
"ip": ip,
"host": host
}
data = parse.urlencode(data)
response = requests.post(self.url, headers=self.headers, data=data)

if response.status_code == 200:
result = response.json()
loguru.logger.info(result)
if result.get("status") == 0:
return result['data']['validate']
else:
raise ValueError(f"识别失败: {result.get('msg')}")
else:
raise ConnectionError(f"Request failed with status code: {response.status_code}")


if __name__ == "__main__":
# 使用示例
appkey = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
_request = BiliRequest(cookies_config_path=cookies_config_path)
test_res = _request.get(
"https://passport.bilibili.com/x/passport-login/captcha?source=main_web"
).json()
challenge = test_res["data"]["geetest"]["challenge"]
gt = test_res["data"]["geetest"]["gt"]
loguru.logger.info(challenge)
loguru.logger.info(gt)
validator = RROCRValidator()
try:
validate_string = validator.validate(appkey, gt, challenge)
print(f"Validation String: {validate_string}")
except Exception as e:
print(f"Error: {e}")
64 changes: 0 additions & 64 deletions geetest/Validator.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
from abc import ABC, abstractmethod
from urllib import parse

import loguru
import requests
from retry import retry

from config import cookies_config_path
from util.bili_request import BiliRequest
from util.config_util import CookieManager


class Validator(ABC):
Expand All @@ -16,58 +7,3 @@ def validate(self, field: str) -> str:
pass


class RROCRValidator(Validator):
def __init__(self):
self.url = "http://api.rrocr.com/api/recognize.html"
self.headers = {
"User-Agent": "Mozilla/5.0 Chrome/77.0.3865.120 Safari/537.36",
"Accept": "text/html",
"Content-Type": "application/x-www-form-urlencoded"
}
self.cookieManager = CookieManager(config_file_path=cookies_config_path)

@retry()
def validate(self, appkey, gt, challenge, referer="http://www.baidu.com", ip='', host='') -> str:
if appkey == None or appkey == "":
appkey = self.cookieManager.get_config_value("appkey", "")
else:
self.cookieManager.set_config_value("appkey", appkey)
data = {
"appkey": appkey,
"gt": gt,
"challenge": challenge,
"referer": referer,
"ip": ip,
"host": host
}
data = parse.urlencode(data)
response = requests.post(self.url, headers=self.headers, data=data)

if response.status_code == 200:
result = response.json()
loguru.logger.info(result)
if result.get("status") == 0:
return result['data']['validate']
else:
raise ValueError(f"识别失败: {result.get('msg')}")
else:
raise ConnectionError(f"Request failed with status code: {response.status_code}")


if __name__ == "__main__":
# 使用示例
appkey = "e1db1bc497a8471c9479f600527ef56f"
_request = BiliRequest(cookies_config_path=cookies_config_path)
test_res = _request.get(
"https://passport.bilibili.com/x/passport-login/captcha?source=main_web"
).json()
challenge = test_res["data"]["geetest"]["challenge"]
gt = test_res["data"]["geetest"]["gt"]
loguru.logger.info(challenge)
loguru.logger.info(gt)
validator = RROCRValidator()
try:
validate_string = validator.validate(appkey, gt, challenge)
print(f"Validation String: {validate_string}")
except Exception as e:
print(f"Error: {e}")
7 changes: 4 additions & 3 deletions tab/go.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@

from common import format_dictionary_to_string
from config import cookies_config_path, global_cookieManager
from geetest.Validator import RROCRValidator
from geetest.CapSolverValidator import CapSolverValidator
from geetest.RROCRValidator import RROCRValidator
from util.bili_request import BiliRequest
from util.error import ERRNO_DICT, withTimeString
from util.order_qrcode import get_qrcode_url

isRunning = False

ways = ["手动", "使用接码网站 rrocr"]
ways_detail = [None, RROCRValidator()]
ways = ["手动", "使用接码网站 rrocr", "使用 CapSolver"]
ways_detail = [None, RROCRValidator(), CapSolverValidator()]


def go_tab():
Expand Down
9 changes: 5 additions & 4 deletions tab/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def train_tab():
| ------------------ | ------------------------------------------------------------ |
| 手动 | 自己过,速度取决于自己,过程看项目的readme.md的GIF |
| 使用接码网站 rrocr | rrocr 提供的 http://www.rrocr.com<br /> 能过验证码,但是抢票没有测试,慎用 <br /> 需要购买对应的key,速度比手动快,价格 一次大概一分钱<br /> |
| ..... | 欢迎补充 |
| 使用接码网站 CapSolve | CapSolver的过码方式<br />https://www.capsolver.com/zh <br />https://docs.capsolver.com/guide/captcha/Geetest.html|
| ..... | 欢迎Discussion补充 |
""")

Expand All @@ -40,11 +41,11 @@ def choose_option(way):
global select_way
select_way = way
# loguru.logger.info(way)
if way == 1:
if way == 0:
# rrocr
return gr.update(visible=True)
else:
return gr.update(visible=False)
else:
return gr.update(visible=True)

way_select_ui.change(choose_option, inputs=way_select_ui, outputs=api_key_input_ui)

Expand Down

0 comments on commit 64667db

Please sign in to comment.