dicr/yii2-anticaptcha-simple

为 Yii2 的 Simple API Captcha 解决方案客户端

安装: 0

依赖: 0

建议者: 0

安全性: 0

星标: 0

分支: 0

类型:yii2-extension

1.0.0 2020-10-28 21:14 UTC

This package is auto-updated.

Last update: 2024-08-29 03:05:38 UTC


README

API: https://rucaptcha.com/api-rucaptcha

以下服务支持简单的 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;
}