通用API打码服务 Args: method: 打码服务类型 project_id: 项目ID action: reCAPTCHA action类型 (IMAGE_GENERATION 或 VIDEO_GENERATION) proxy_url: 预解析后的代理地址,确保打码与后续提交走同一出口 user_agent: 显式传给打码服务的 UA,避免 solve / submit 环境不一致 Returns: (gR
(
self,
method: str,
project_id: str,
action: str = "IMAGE_GENERATION",
proxy_url: Optional[str] = None,
user_agent: Optional[str] = None,
)
| 4736 | return None, None |
| 4737 | |
| 4738 | async def _get_api_captcha_token( |
| 4739 | self, |
| 4740 | method: str, |
| 4741 | project_id: str, |
| 4742 | action: str = "IMAGE_GENERATION", |
| 4743 | proxy_url: Optional[str] = None, |
| 4744 | user_agent: Optional[str] = None, |
| 4745 | ) -> Optional[tuple[str, str]]: |
| 4746 | """通用API打码服务 |
| 4747 | |
| 4748 | Args: |
| 4749 | method: 打码服务类型 |
| 4750 | project_id: 项目ID |
| 4751 | action: reCAPTCHA action类型 (IMAGE_GENERATION 或 VIDEO_GENERATION) |
| 4752 | proxy_url: 预解析后的代理地址,确保打码与后续提交走同一出口 |
| 4753 | user_agent: 显式传给打码服务的 UA,避免 solve / submit 环境不一致 |
| 4754 | |
| 4755 | Returns: |
| 4756 | (gRecaptchaResponse, userAgent) 元组, 或 None (失败时)。 |
| 4757 | 返回 userAgent 是为了让后续 Flow API 请求沿用打码时的 UA, |
| 4758 | 避免 reCAPTCHA V3 评估因 UA 不一致判定 UNUSUAL_ACTIVITY。 |
| 4759 | """ |
| 4760 | # 获取配置 |
| 4761 | if method == "yescaptcha": |
| 4762 | client_key = config.yescaptcha_api_key |
| 4763 | base_url = config.yescaptcha_base_url |
| 4764 | elif method == "capmonster": |
| 4765 | client_key = config.capmonster_api_key |
| 4766 | base_url = config.capmonster_base_url |
| 4767 | elif method == "ezcaptcha": |
| 4768 | client_key = config.ezcaptcha_api_key |
| 4769 | base_url = config.ezcaptcha_base_url |
| 4770 | elif method == "capsolver": |
| 4771 | client_key = config.capsolver_api_key |
| 4772 | base_url = config.capsolver_base_url |
| 4773 | else: |
| 4774 | debug_logger.log_error(f"[reCAPTCHA] Unknown API method: {method}") |
| 4775 | return None |
| 4776 | |
| 4777 | if not client_key: |
| 4778 | debug_logger.log_info(f"[reCAPTCHA] {method} API key not configured, skipping") |
| 4779 | return None |
| 4780 | |
| 4781 | runtime_settings = self._resolve_recaptcha_runtime_settings(method, action) |
| 4782 | task_type = runtime_settings["task_type"] |
| 4783 | min_score = runtime_settings["min_score"] |
| 4784 | website_key = runtime_settings["website_key"] |
| 4785 | website_url = self._build_flow_project_page_url(project_id) |
| 4786 | page_action = runtime_settings["page_action"] |
| 4787 | |
| 4788 | try: |
| 4789 | # 获取代理配置,让打码API请求也走代理 |
| 4790 | # 注意:curl_cffi 对 SOCKS5 使用 proxy 参数,HTTP 代理使用 proxies 参数 |
| 4791 | proxy = None |
| 4792 | proxies = None |
| 4793 | resolved_proxy_url = str(proxy_url or "").strip() |
| 4794 | if not resolved_proxy_url and self.proxy_manager: |
| 4795 | try: |