From d957b81b9959ac3bd4ca449dc0c4d44ea13f2719 Mon Sep 17 00:00:00 2001 From: capmonster-sdk-bot Date: Wed, 18 Nov 2026 09:22:54 +0000 Subject: [PATCH] Add FengkongCloud, ARCaptcha, HeyTap and Proton Captcha request types --- CHANGELOG.md | 8 ++ Cargo.toml | 2 +- README.md | 2 + src/requests/arcaptcha.rs | 104 ++++++++++++++++++++++++ src/requests/fengkongcloud.rs | 118 +++++++++++++++++++++++++++ src/requests/heytap.rs | 119 +++++++++++++++++++++++++++ src/requests/mod.rs | 8 ++ src/requests/proton.rs | 147 ++++++++++++++++++++++++++++++++++ 8 files changed, 507 insertions(+), 1 deletion(-) create mode 100644 src/requests/arcaptcha.rs create mode 100644 src/requests/fengkongcloud.rs create mode 100644 src/requests/heytap.rs create mode 100644 src/requests/proton.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d3701e..e163bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this crate are documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), versions follow [SemVer](https://semver.org/) (while the major version is 0, a breaking change bumps the **minor** number). +## [0.2.0] + +### Added +- `FengkongCloudRequest` (`CustomTask`, class `fengkongcloud`). +- `ArCaptchaRequest` (`ArCaptchaTask`). +- `HeyTapRequest` (`CustomTask`, class `heytap`). +- `ProtonRequest` (`CustomTask`, class `proton`, proxy required). + ## [0.1.2] ### Added diff --git a/Cargo.toml b/Cargo.toml index 3082208..a67ec66 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "capmonstercloud-client" -version = "0.1.2" +version = "0.2.0" edition = "2021" rust-version = "1.88" description = "Async Rust client for the CapMonster Cloud captcha-solving API" diff --git a/README.md b/README.md index e1a9f59..f93f721 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,8 @@ All task types follow the official [CapMonster Cloud API documentation](https:// | **TSPD** | `TspdCustomTaskRequest` | 🌐 Required | | **HUNT** | `HuntCustomTaskRequest` | 🌐 Required | | **Basilisk / TenDI / Alibaba / Friendly Captcha / Altcha** | `BasiliskCustomTaskRequest`, `TenDiCustomTaskRequest`, `AlibabaCustomTaskRequest`, `FriendlyCustomTaskRequest`, `AltchaCustomTaskRequest` | Optional | +| **Proton Captcha** | `ProtonRequest` | 🌐 Required | +| **FengkongCloud / ARCaptcha / HeyTap** | `FengkongCloudRequest`, `ArCaptchaRequest`, `HeyTapRequest` | — | | **Binance CAPTCHA** | `BinanceTaskRequest` | Optional | | **MTCaptcha / Yidun / Prosopo** | `MtCaptchaRequest`, `YidunRequest`, `ProsopoTaskRequest` | Optional | | **Standard Text CAPTCHA** | `ImageToTextRequest` (+ `TextModule`) | — | diff --git a/src/requests/arcaptcha.rs b/src/requests/arcaptcha.rs new file mode 100644 index 0000000..137282e --- /dev/null +++ b/src/requests/arcaptcha.rs @@ -0,0 +1,104 @@ +use serde::Serialize; + +use super::{require_non_empty, CaptchaRequest}; +use crate::error::Result; +use crate::timeouts::GetResultTimeouts; + +/// ARCaptcha (`ArCaptchaTask`). The solution token is in `solution.token`. +#[derive(Debug, Clone, Serialize)] +pub struct ArCaptchaRequest { + /// The address of the main page where the captcha is located. + #[serde(rename = "websiteURL")] + pub website_url: String, + /// The siteKey value found on the page. + #[serde(rename = "websiteKey")] + pub website_key: String, + /// `true` if the captcha is invisible (has a hidden verification field). + #[serde(rename = "isInvisible", skip_serializing_if = "Option::is_none")] + pub is_invisible: Option, + /// Browser User-Agent (current Windows UA supported by CapMonster Cloud). + #[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")] + pub user_agent: Option, +} + +impl ArCaptchaRequest { + pub fn new(website_url: impl Into, website_key: impl Into) -> Self { + Self { + website_url: website_url.into(), + website_key: website_key.into(), + is_invisible: None, + user_agent: None, + } + } + + pub fn with_is_invisible(mut self, value: bool) -> Self { + self.is_invisible = Some(value); + self + } + + pub fn with_user_agent(mut self, value: impl Into) -> Self { + self.user_agent = Some(value.into()); + self + } +} + +impl CaptchaRequest for ArCaptchaRequest { + const TASK_TYPE: &'static str = "ArCaptchaTask"; + + fn timeouts(&self) -> GetResultTimeouts { + GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0) + } + + fn validate(&self) -> Result<()> { + require_non_empty("websiteURL", &self.website_url)?; + require_non_empty("websiteKey", &self.website_key)?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + #[test] + fn minimal_task() { + let task = ArCaptchaRequest::new("https://example.com", "KEY") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "ArCaptchaTask", + "websiteURL": "https://example.com", "websiteKey": "KEY" + }) + ); + } + + #[test] + fn full_task() { + let task = ArCaptchaRequest::new("https://example.com", "KEY") + .with_is_invisible(false) + .with_user_agent("UA") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "ArCaptchaTask", + "websiteURL": "https://example.com", "websiteKey": "KEY", + "isInvisible": false, "userAgent": "UA" + }) + ); + } + + #[test] + fn empty_required_strings_are_rejected() { + let err = ArCaptchaRequest::new("", "KEY").to_task().unwrap_err(); + assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteURL"))); + let err = ArCaptchaRequest::new("https://example.com", "") + .to_task() + .unwrap_err(); + assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteKey"))); + } +} diff --git a/src/requests/fengkongcloud.rs b/src/requests/fengkongcloud.rs new file mode 100644 index 0000000..849020a --- /dev/null +++ b/src/requests/fengkongcloud.rs @@ -0,0 +1,118 @@ +use serde::Serialize; + +use super::{require_non_empty, CaptchaRequest}; +use crate::error::Result; +use crate::timeouts::GetResultTimeouts; + +/// FengkongCloud-specific data (`metadata`). +#[derive(Debug, Clone, Serialize)] +pub struct FengkongCloudMetadata { + /// Link to `smcp.min.js`, e.g. `https://example.com/pr/vX.X.X/smcp.min.js`. + #[serde(rename = "apiJsUrl", skip_serializing_if = "Option::is_none")] + pub api_js_url: Option, +} + +/// FengkongCloud captcha (`CustomTask`, class `fengkongcloud`). The solution token is in +/// `solution.data.token`. +#[derive(Debug, Clone, Serialize)] +pub struct FengkongCloudRequest { + /// The address of the main page where the captcha is located. + #[serde(rename = "websiteURL")] + pub website_url: String, + /// The `appid` value found on the page. + #[serde(rename = "websiteKey")] + pub website_key: String, + /// Optional challenge data; sent only when `api_js_url` is set. + #[serde(skip_serializing_if = "Option::is_none")] + pub metadata: Option, + /// Browser User-Agent (current Windows UA supported by CapMonster Cloud). + #[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")] + pub user_agent: Option, +} + +impl FengkongCloudRequest { + pub fn new(website_url: impl Into, website_key: impl Into) -> Self { + Self { + website_url: website_url.into(), + website_key: website_key.into(), + metadata: None, + user_agent: None, + } + } + + /// Sets `metadata.apiJsUrl`, the link to `smcp.min.js`. + pub fn with_api_js_url(mut self, value: impl Into) -> Self { + self.metadata = Some(FengkongCloudMetadata { + api_js_url: Some(value.into()), + }); + self + } + + pub fn with_user_agent(mut self, value: impl Into) -> Self { + self.user_agent = Some(value.into()); + self + } +} + +impl CaptchaRequest for FengkongCloudRequest { + const TASK_TYPE: &'static str = "CustomTask"; + const CLASS: Option<&'static str> = Some("fengkongcloud"); + + fn timeouts(&self) -> GetResultTimeouts { + GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0) + } + + fn validate(&self) -> Result<()> { + require_non_empty("websiteURL", &self.website_url)?; + require_non_empty("websiteKey", &self.website_key)?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + #[test] + fn minimal_task() { + let task = FengkongCloudRequest::new("https://example.com", "KEY") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "CustomTask", "class": "fengkongcloud", + "websiteURL": "https://example.com", "websiteKey": "KEY" + }) + ); + } + + #[test] + fn full_task() { + let task = FengkongCloudRequest::new("https://example.com", "KEY") + .with_api_js_url("https://example.com/smcp.min.js") + .with_user_agent("UA") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "CustomTask", "class": "fengkongcloud", + "websiteURL": "https://example.com", "websiteKey": "KEY", + "metadata": {"apiJsUrl": "https://example.com/smcp.min.js"}, + "userAgent": "UA" + }) + ); + } + + #[test] + fn empty_required_strings_are_rejected() { + let err = FengkongCloudRequest::new("", "KEY").to_task().unwrap_err(); + assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteURL"))); + let err = FengkongCloudRequest::new("https://example.com", "") + .to_task() + .unwrap_err(); + assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteKey"))); + } +} diff --git a/src/requests/heytap.rs b/src/requests/heytap.rs new file mode 100644 index 0000000..f3c111d --- /dev/null +++ b/src/requests/heytap.rs @@ -0,0 +1,119 @@ +use serde::Serialize; + +use super::{require_non_empty, CaptchaRequest}; +use crate::error::Result; +use crate::timeouts::GetResultTimeouts; + +/// HeyTap-specific data (`metadata`). +#[derive(Debug, Clone, Serialize)] +pub struct HeyTapMetadata { + /// Subdomain of the HeyTap API server, without the `https://` prefix. Must be specified + /// when it differs from the default server. + #[serde(rename = "apiServer", skip_serializing_if = "Option::is_none")] + pub api_server: Option, +} + +/// HeyTap captcha (`CustomTask`, class `heytap`). The solution token is in +/// `solution.data.token`. +#[derive(Debug, Clone, Serialize)] +pub struct HeyTapRequest { + /// The address of the main page where the captcha is located. + #[serde(rename = "websiteURL")] + pub website_url: String, + /// The siteKey value found on the page (the `ak` parameter of the HeyTap API URL). + #[serde(rename = "websiteKey")] + pub website_key: String, + /// Optional challenge data; sent only when `api_server` is set. + #[serde(skip_serializing_if = "Option::is_none")] + pub metadata: Option, + /// Browser User-Agent (current Windows UA supported by CapMonster Cloud). + #[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")] + pub user_agent: Option, +} + +impl HeyTapRequest { + pub fn new(website_url: impl Into, website_key: impl Into) -> Self { + Self { + website_url: website_url.into(), + website_key: website_key.into(), + metadata: None, + user_agent: None, + } + } + + /// Sets `metadata.apiServer` (domain only, without `https://`). + pub fn with_api_server(mut self, value: impl Into) -> Self { + self.metadata = Some(HeyTapMetadata { + api_server: Some(value.into()), + }); + self + } + + pub fn with_user_agent(mut self, value: impl Into) -> Self { + self.user_agent = Some(value.into()); + self + } +} + +impl CaptchaRequest for HeyTapRequest { + const TASK_TYPE: &'static str = "CustomTask"; + const CLASS: Option<&'static str> = Some("heytap"); + + fn timeouts(&self) -> GetResultTimeouts { + GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0) + } + + fn validate(&self) -> Result<()> { + require_non_empty("websiteURL", &self.website_url)?; + require_non_empty("websiteKey", &self.website_key)?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use serde_json::json; + + #[test] + fn minimal_task() { + let task = HeyTapRequest::new("https://example.com", "KEY") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "CustomTask", "class": "heytap", + "websiteURL": "https://example.com", "websiteKey": "KEY" + }) + ); + } + + #[test] + fn full_task() { + let task = HeyTapRequest::new("https://example.com", "KEY") + .with_api_server("api.example.com") + .with_user_agent("UA") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "CustomTask", "class": "heytap", + "websiteURL": "https://example.com", "websiteKey": "KEY", + "metadata": {"apiServer": "api.example.com"}, + "userAgent": "UA" + }) + ); + } + + #[test] + fn empty_required_strings_are_rejected() { + let err = HeyTapRequest::new("", "KEY").to_task().unwrap_err(); + assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteURL"))); + let err = HeyTapRequest::new("https://example.com", "") + .to_task() + .unwrap_err(); + assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteKey"))); + } +} diff --git a/src/requests/mod.rs b/src/requests/mod.rs index c2b6edf..d8edc6b 100644 --- a/src/requests/mod.rs +++ b/src/requests/mod.rs @@ -17,18 +17,22 @@ use crate::timeouts::GetResultTimeouts; mod alibaba; mod altcha; mod amazon_waf; +mod arcaptcha; mod basilisk; mod binance; mod complex_image; mod datadome; +mod fengkongcloud; mod friendly; mod funcaptcha; mod geetest; +mod heytap; mod hunt; mod image_to_text; mod imperva; mod mt_captcha; mod prosopo; +mod proton; mod recaptcha_complex_image; mod recaptcha_v2; mod recaptcha_v2_enterprise; @@ -46,17 +50,21 @@ pub use amazon_waf::{ AmazonChallengeAndCaptcha, AmazonChallengeOnly, AmazonVisibleCaptcha, AmazonWafRequest, AmazonWafVariant, }; +pub use arcaptcha::ArCaptchaRequest; pub use basilisk::BasiliskCustomTaskRequest; pub use binance::BinanceTaskRequest; pub use datadome::{DataDomeCustomTaskRequest, DataDomeMetadata, DataDomeVersion}; +pub use fengkongcloud::{FengkongCloudMetadata, FengkongCloudRequest}; pub use friendly::{FriendlyCustomTaskRequest, FriendlyMetadata}; pub use funcaptcha::FuncaptchaRequest; pub use geetest::{GeetestRequest, GeetestVersion}; +pub use heytap::{HeyTapMetadata, HeyTapRequest}; pub use hunt::{HuntCustomTaskRequest, HuntMetadata, HuntMode}; pub use image_to_text::{ImageToTextRequest, TextModule}; pub use imperva::{ImpervaCustomTaskRequest, ImpervaMetadata}; pub use mt_captcha::MtCaptchaRequest; pub use prosopo::ProsopoTaskRequest; +pub use proton::{ProtonMetadata, ProtonRequest}; pub use recaptcha_complex_image::{ RecaptchaComplexImageTaskRequest, RecaptchaGrid, RecaptchaMetadata, }; diff --git a/src/requests/proton.rs b/src/requests/proton.rs new file mode 100644 index 0000000..70c6394 --- /dev/null +++ b/src/requests/proton.rs @@ -0,0 +1,147 @@ +use serde::Serialize; + +use super::{require_non_empty, CaptchaRequest}; +use crate::error::{Error, Result}; +use crate::proxy::ProxyInfo; +use crate::timeouts::GetResultTimeouts; + +/// Proton Captcha challenge data (`metadata`). +#[derive(Debug, Clone, Serialize)] +pub struct ProtonMetadata { + /// Token from the site's response. + #[serde(rename = "HumanVerificationToken")] + pub human_verification_token: String, + /// Action on the site: `login` or `signup`. + #[serde(rename = "pageAction")] + pub page_action: String, +} + +/// Proton Captcha (`CustomTask`, class `proton`). Your own proxy with login and password is +/// required. The solution token is in `solution.data.tokens`. +#[derive(Debug, Clone, Serialize)] +pub struct ProtonRequest { + /// The address of the main page where the captcha is located. + #[serde(rename = "websiteURL")] + pub website_url: String, + pub metadata: ProtonMetadata, + /// Required proxy (non-transparent, not local). + #[serde(flatten)] + pub proxy: ProxyInfo, + /// Browser User-Agent (current Windows UA supported by CapMonster Cloud). + #[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")] + pub user_agent: Option, +} + +impl ProtonRequest { + /// `page_action` is `login` or `signup`. + pub fn new( + website_url: impl Into, + human_verification_token: impl Into, + page_action: impl Into, + proxy: ProxyInfo, + ) -> Self { + Self { + website_url: website_url.into(), + metadata: ProtonMetadata { + human_verification_token: human_verification_token.into(), + page_action: page_action.into(), + }, + proxy, + user_agent: None, + } + } + + pub fn with_user_agent(mut self, value: impl Into) -> Self { + self.user_agent = Some(value.into()); + self + } +} + +impl CaptchaRequest for ProtonRequest { + const TASK_TYPE: &'static str = "CustomTask"; + const CLASS: Option<&'static str> = Some("proton"); + + fn timeouts(&self) -> GetResultTimeouts { + GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0) + } + + fn validate(&self) -> Result<()> { + require_non_empty("websiteURL", &self.website_url)?; + require_non_empty( + "metadata.HumanVerificationToken", + &self.metadata.human_verification_token, + )?; + if self.metadata.page_action != "login" && self.metadata.page_action != "signup" { + return Err(Error::Validation( + "metadata.pageAction must be \"login\" or \"signup\"".into(), + )); + } + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::proxy::ProxyType; + use serde_json::json; + + fn proxy() -> ProxyInfo { + ProxyInfo::new(ProxyType::Http, "1.2.3.4", 8080).with_auth("u", "p") + } + + #[test] + fn minimal_task() { + let task = ProtonRequest::new("https://example.com", "TOKEN", "login", proxy()) + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "CustomTask", "class": "proton", "websiteURL": "https://example.com", + "metadata": {"HumanVerificationToken": "TOKEN", "pageAction": "login"}, + "proxyType": "http", "proxyAddress": "1.2.3.4", "proxyPort": 8080, + "proxyLogin": "u", "proxyPassword": "p" + }) + ); + } + + #[test] + fn full_task() { + let task = ProtonRequest::new("https://example.com", "TOKEN", "signup", proxy()) + .with_user_agent("UA") + .to_task() + .unwrap(); + assert_eq!( + task, + json!({ + "type": "CustomTask", "class": "proton", "websiteURL": "https://example.com", + "metadata": {"HumanVerificationToken": "TOKEN", "pageAction": "signup"}, + "proxyType": "http", "proxyAddress": "1.2.3.4", "proxyPort": 8080, + "proxyLogin": "u", "proxyPassword": "p", "userAgent": "UA" + }) + ); + } + + #[test] + fn invalid_page_action_is_rejected() { + let err = ProtonRequest::new("https://example.com", "TOKEN", "logout", proxy()) + .to_task() + .unwrap_err(); + assert!(matches!(err, Error::Validation(ref m) if m.contains("metadata.pageAction"))); + } + + #[test] + fn empty_required_strings_are_rejected() { + let err = ProtonRequest::new("", "TOKEN", "login", proxy()) + .to_task() + .unwrap_err(); + assert!(matches!(err, Error::Validation(ref m) if m.contains("websiteURL"))); + let err = ProtonRequest::new("https://example.com", "", "login", proxy()) + .to_task() + .unwrap_err(); + assert!( + matches!(err, Error::Validation(ref m) if m.contains("metadata.HumanVerificationToken")) + ); + } +}