randock/anti-captcha-client

此包的最新版本(0.4.0)没有可用的许可信息。

一个用于连接 https://anti-captcha.com 的 PHP 库

0.4.0 2023-03-14 08:54 UTC

README

Build Status

Anti-captcha API

此库集成了 https://anti-captcha.com API。

安装

使用 composer 安装此库是最简单的方式

composer require randock/anti-captcha-client

用法

可以通过创建客户端实例并调用相应的方法来使用此库。

例如,要创建一个新的任务

<?php

use Randock\AntiCaptcha\Client;
use Randock\AntiCaptcha\Task\ImageToTextTask;
use Randock\AntiCaptcha\Solution\ImageToTextSolution;
use Randock\AntiCaptcha\Exception\InvalidRequestException;

// create a new client
$client = new Client('<<API KEY>>');

// create the task to be send
$task = new ImageToTextTask();

// set the body
$task->setBody('<<BASE 64 of captcha>>');
//$task->setBodyFromFile($file);

try {
    // send the task to anti-captcha.com
    $task = $client->createTask($task);

    do {
        // wait a bit before (re)trying
        sleep(2);

        $taskResult = $client->getTaskResult($task);
    } while ($taskResult->isProcessing());

    /* @var ImageToTextSolution $solution */
    $solution = $taskResult->getSolution();

    // grab captcha text
    $captcha = $solution->getText();
} catch (InvalidRequestException $exception) {
}