#sdk #recaptcha #task

yescaptcha

YesCaptcha SDK for Rust

1 个不稳定版本

0.1.0 2024 年 8 月 16 日

1642网页编程

Download history 94/week @ 2024-08-10

94 每月下载量

MIT 许可证

15KB
238 代码行

YesCaptcha Rust SDK

🚧 目前只实现了某些类型的任务,欢迎任何 PR

开始使用

cargo add yescaptcha

示例

所有示例

ReCaptcha V2

use std::time::Duration;
use tokio::time::sleep;
use yescaptcha::{
    task::recaptcha_v2::{ReCaptchaV2Config, TaskType},
    Client, TaskResult,
};

#[tokio::main]
async fn main() {
    let client_key = "CLIENT_KEY";

    // Create a new YesCaptcha client
    let client = Client::new(client_key);

    // Create a new ReCaptchaV2 task
    let task_config = ReCaptchaV2Config {
        website_url: "https://www.google.com/recaptcha/api2/demo".to_string(),
        website_key: "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-".to_string(),
        task_type: TaskType::NoCaptchaTaskProxyless,
        is_invisible: false,
    };

    // Send the task to the YesCaptcha API
    let task = client.create_task(task_config).await.unwrap();

    // Wait for the task to be completed
    loop {
        // Get the task result
        let result = client.get_task_result(&task).await.unwrap();

        match result {
            TaskResult::Processing => {
                println!("Task is not completed yet");
            }
            TaskResult::Ready(solution) => {
                println!("Solution: {:#?}", solution);
                // Exit the loop once the task is completed
                break;
            }
        }

        // Wait for 5 seconds before checking again
        sleep(Duration::from_secs(5)).await;
    }
}

依赖项

~6–17MB
~239K SLoC