dicr/yii2-anticaptcha

This package is not installable via Composer 1.x, please make sure you upgrade to Composer 2+. Read more about our Composer 1.x deprecation policy.

Клиент Anti-captcha API 2 для Yii2

Installs: 0

Dependents: 1

Suggesters: 0

Security: 0

Type:yii2-extension

1.0.5 2021-02-03 15:32 UTC

This package is auto-updated.

Last update: 2021-07-01 00:19:48 UTC


README

Настройка

$config = [
    'modules' => [
        'anticaptcha' => [
            'class' => dicr\anticaptcha\AntiCaptchaModule::class,
            'clientKey' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
        ]
    ]
];

Использование

Запрос на решение простой текстовой капчи:

use dicr\anticaptcha\AntiCaptchaModule;
use dicr\anticaptcha\method\CreateTaskRequest;
use dicr\anticaptcha\method\GetTaskRequest;
use dicr\anticaptcha\task\ImageToTextTask;

/** @var AntiCaptchaModule $module модуль */
$module = Yii::$app->getModule('anticaptcha');

/** @var CreateTaskRequest $req запрос создания задачи */
$req = $module->request([
    'class' => CreateTaskRequest::class,
    'task' => new ImageToTextTask([
        'body' => base64_encode(file_get_contents(__DIR__ . '/captcha.gif')),
    ])
]);

// отправляем запрос создания задачи решения капчи
$res = $req->send();
echo 'Задача: ' . $res->taskId . "\n";

// ждем 20 секунд
sleep(20);

/** @var CreateTaskRequest $req запрос решения капчи */
$req =$module->request([
    'class' => GetTaskRequest::class,
    'taskId' => $res->taskId
]);

// отправляем запрос
$res = $req->send();
echo 'Ответ: ' . $res->solution['text'] . "\n";