Skip to content

dicrtarasov/yii2-anticaptcha-simple

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Клиент Simple API решения каптч для Yii2.

Простой протокол Rest-запросов поддерживается такими сервисами как:

  • rucaptcha.com
  • 2captcha.com
  • pixodrom.com
  • captcha24.com
  • socialink.ru

Настройка

'modules' => [
    'anticaptcha' => [
        'class' => dicr\anticaptcha\simple\AntiCaptchaSimpleModule::class,
        'key' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
    ]
]

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

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

// находим модуль
$module = Yii::$app->getModule('anticaptcha');

// создаем запрос
$req = $module->captchaRequest([
    'textCaptcha' => 'Привет'
]);

// отправляем
$res = $req->send();

// проверяем статус заявки
if (! $res->status) {
    throw new Exception('Ошибка: ' . $res->request);
}

// получаем id заявки
$id = (int)$res->request;

Получение решения:

// запрос решения
$req = $module->resultRequest([
    'action' => ResultRequest::ACTION_GET,
    'id' => $id 
]);

// отправляем
$res = $res->send();

// проверяем статус заявки
if ($res->status) {
    echo 'Результат: ' . $res->request;
}