Skip to content

Commit

Permalink
feat: rrocr 添加
Browse files Browse the repository at this point in the history
  • Loading branch information
mikumifa committed Jun 10, 2024
1 parent 12ddbeb commit 539321b
Show file tree
Hide file tree
Showing 14 changed files with 369 additions and 9,619 deletions.
3 changes: 3 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import os
import sys

from util.config_util import CookieManager


# 获取图标文件的路径
def get_application_path():
Expand All @@ -13,5 +15,6 @@ def get_application_path():


cookies_config_path = os.path.join(get_application_path(), "cookies.json")
global_cookieManager = CookieManager(config_file_path=cookies_config_path)
issue_please_text = " (如果还无法解决, 请提交issue到仓库, 十分感谢)"
sleep_seconds = 1
73 changes: 73 additions & 0 deletions geetest/Validator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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):
@abstractmethod
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}")
139 changes: 0 additions & 139 deletions geetest/api.py

This file was deleted.

4,416 changes: 0 additions & 4,416 deletions geetest/click.js

This file was deleted.

68 changes: 0 additions & 68 deletions geetest/click3.py

This file was deleted.

87 changes: 0 additions & 87 deletions geetest/main.py

This file was deleted.

Loading

0 comments on commit 539321b

Please sign in to comment.