MCPcopy Create free account
hub / github.com/TheSmallHanCat/flow2api / _solve_recaptcha_with_api_service

Function _solve_recaptcha_with_api_service

src/api/admin.py:411–507  ·  view source on GitHub ↗

使用当前配置的第三方打码服务获取 token。

(
    method: str,
    website_url: str,
    website_key: str,
    action: str,
    enterprise: bool = False
)

Source from the content-addressed store, hash-verified

409
410
411async def _solve_recaptcha_with_api_service(
412 method: str,
413 website_url: str,
414 website_key: str,
415 action: str,
416 enterprise: bool = False
417) -> Optional[str]:
418 """使用当前配置的第三方打码服务获取 token。"""
419 if method == "yescaptcha":
420 client_key = config.yescaptcha_api_key
421 base_url = config.yescaptcha_base_url
422 task_type = config.yescaptcha_task_type
423 min_score = get_yescaptcha_min_score(task_type)
424 elif method == "capmonster":
425 client_key = config.capmonster_api_key
426 base_url = config.capmonster_base_url
427 task_type = "RecaptchaV3TaskProxyless"
428 min_score = None
429 elif method == "ezcaptcha":
430 client_key = config.ezcaptcha_api_key
431 base_url = config.ezcaptcha_base_url
432 task_type = "ReCaptchaV3TaskProxylessS9"
433 min_score = None
434 elif method == "capsolver":
435 client_key = config.capsolver_api_key
436 base_url = config.capsolver_base_url
437 task_type = "ReCaptchaV3EnterpriseTaskProxyLess" if enterprise else "ReCaptchaV3TaskProxyLess"
438 min_score = None
439 else:
440 raise RuntimeError(f"不支持的打码方式: {method}")
441
442 if not client_key:
443 raise RuntimeError(f"{method} API Key 未配置")
444
445 task: Dict[str, Any] = {
446 "websiteURL": website_url,
447 "websiteKey": website_key,
448 "type": task_type,
449 "pageAction": action,
450 }
451 if min_score is not None:
452 task["minScore"] = min_score
453
454 if enterprise and method == "capsolver":
455 task["isEnterprise"] = True
456
457 create_url = f"{base_url.rstrip('/')}/createTask"
458 get_url = f"{base_url.rstrip('/')}/getTaskResult"
459
460 # 获取代理配置
461 proxies = None
462 try:
463 if proxy_manager:
464 proxy_cfg = await proxy_manager.get_proxy_config()
465 if proxy_cfg and proxy_cfg.enabled and proxy_cfg.proxy_url:
466 proxies = {"http": proxy_cfg.proxy_url, "https": proxy_cfg.proxy_url}
467 except Exception:
468 pass

Callers 1

test_captcha_scoreFunction · 0.85

Calls 4

get_yescaptcha_min_scoreFunction · 0.90
postMethod · 0.80
sleepMethod · 0.80
get_proxy_configMethod · 0.45

Tested by 1

test_captcha_scoreFunction · 0.68