Skip to main content

chaser_gt/
lib.rs

1//! # chaser-gt
2//!
3//! A high-performance Rust implementation of a Geetest v4 captcha solver.
4//!
5//! ## Features
6//!
7//! - **Automatic Deobfuscation**: Constants are automatically updated when Geetest
8//!   releases new versions - no manual intervention required.
9//! - **Multiple Captcha Types**: Supports Slide, Gobang, Icon, and AI/Invisible captchas.
10//! - **TLS Fingerprinting**: Uses `rquest` for Chrome-like TLS fingerprinting.
11//! - **Proxy Support**: HTTP and SOCKS5 proxy support with authentication.
12//! - **Async/Await**: Built on Tokio for efficient concurrent captcha solving.
13//!
14//! ## Quick Start
15//!
16//! ```ignore
17//! use chaser_gt::{Geeked, RiskType};
18//!
19//! #[tokio::main]
20//! async fn main() -> anyhow::Result<()> {
21//!     // Create a solver for slide captcha
22//!     let solver = Geeked::builder("your_captcha_id", RiskType::Slide)
23//!         .build()
24//!         .await?;
25//!
26//!     // Solve the captcha
27//!     let result = solver.solve().await?;
28//!
29//!     println!("captcha_id: {}", result.captcha_id);
30//!     println!("lot_number: {}", result.lot_number);
31//!     println!("pass_token: {}", result.pass_token);
32//!     println!("gen_time: {}", result.gen_time);
33//!     println!("captcha_output: {}", result.captcha_output);
34//!
35//!     Ok(())
36//! }
37//! ```
38//!
39//! ## With Proxy
40//!
41//! ```ignore
42//! use chaser_gt::{Geeked, RiskType};
43//!
44//! let solver = Geeked::builder("captcha_id", RiskType::Slide)
45//!     .proxy("http://user:pass@proxy.example.com:8080")
46//!     .build()
47//!     .await?;
48//! ```
49//!
50//! ## Supported Captcha Types
51//!
52//! - `RiskType::Slide` - Slide puzzle captcha
53//! - `RiskType::Gobang` - Five-in-a-row puzzle
54//! - `RiskType::Icon` - Icon selection captcha (requires `icon` feature)
55//! - `RiskType::Ai` - AI/Invisible captcha
56//! - `RiskType::Svg` - SVG animated icon captcha (requires `svg` feature)
57//!
58//! ## Automatic Constant Updates
59//!
60//! Unlike other implementations that require manual updates when Geetest changes
61//! their obfuscation, this library automatically:
62//!
63//! 1. Checks for new Geetest script versions
64//! 2. Deobfuscates the script to extract constants
65//! 3. Caches the constants for future use
66//!
67//! This means the library stays functional even when Geetest updates their anti-bot measures.
68
69// Allow missing docs for internal types for now
70#![allow(missing_docs)]
71
72pub mod client;
73pub mod crypto;
74pub mod deobfuscate;
75pub mod error;
76pub mod models;
77pub mod sign;
78pub mod solvers;
79
80#[cfg(feature = "ffi")]
81pub mod ffi;
82
83// Re-exports for convenience
84pub use client::{Geeked, GeekedBuilder};
85pub use error::{GeekedError, Result};
86pub use models::{RiskType, SecCode};
87
88/// Initialize the library.
89///
90/// This is optional but can be called to pre-fetch constants before solving.
91pub async fn init() -> Result<()> {
92    let deobfuscator = deobfuscate::Deobfuscator::new();
93    let _ = deobfuscator.get_constants().await?;
94    Ok(())
95}
96
97#[cfg(test)]
98mod tests {
99    use super::*;
100
101    #[test]
102    fn test_risk_type_display() {
103        assert_eq!(RiskType::Slide.as_str(), "slide");
104        assert_eq!(RiskType::Gobang.as_str(), "gobang");
105        assert_eq!(RiskType::Icon.as_str(), "icon");
106        assert_eq!(RiskType::Ai.as_str(), "ai");
107        assert_eq!(RiskType::Svg.as_str(), "svg");
108    }
109}