PHP code example of vvb / yandex-smart-captcha

1. Go to this page and download the library: Download vvb/yandex-smart-captcha library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vvb / yandex-smart-captcha example snippets


use vvb\YandexSmartCaptcha\Rules\YandexSmartCaptchaRule;

public function store(Request $request)
{
    $request->validate([
        'smart-token' => [new YandexSmartCaptchaRule],
    ]);
    
    // Ваша логика
}

new YandexSmartCaptchaRule(
    message: 'Неверная капча!',
    emptyMessage: 'Пожалуйста, пройдите проверку'
)

return [
    'yandex_smart_captcha_rule' => 'Капча не пройдена',
    'yandex_smart_captcha_empty' => 'Требуется подтверждение капчи',
];

use vvb\YandexSmartCaptcha\Facades\YandexSmartCaptcha;

// Проверка токена
YandexSmartCaptcha::verify($token, $ip = null);

// Получить client_key
YandexSmartCaptcha::getClientKey();

// Получить публичный конфиг (без server_key)
YandexSmartCaptcha::getConfig();

$service = app('yandex-smart-captcha');
$service->verify($token);
$service->getClientKey();
$service->getConfig();

return [
    'client_key' => env('YANDEX_SMART_CAPTCHA_CLIENT_KEY'),
    'server_key' => env('YANDEX_SMART_CAPTCHA_SERVER_KEY'),
    'script_url' => env('YANDEX_SMART_CAPTCHA_SCRIPT_URL', 'https://smartcaptcha.cloud.yandex.ru/captcha.js'),
    'validate_url' => env('YANDEX_SMART_CAPTCHA_VALIDATE_URL', 'https://smartcaptcha.cloud.yandex.ru/validate'),
    'language' => env('YANDEX_SMART_CAPTCHA_LANGUAGE', 'ru'),
    'theme' => env('YANDEX_SMART_CAPTCHA_THEME', 'auto'),
    'test' => env('YANDEX_SMART_CAPTCHA_TEST', false),
    'http_timeout' => env('YANDEX_SMART_CAPTCHA_HTTP_TIMEOUT', 30),
    'enabled' => env('YANDEX_SMART_CAPTCHA_ENABLED', true),
    'validate_host' => env('YANDEX_SMART_CAPTCHA_VALIDATE_HOST', false),
];
bash
  php artisan vendor:publish --tag=config --force
  
bash
php artisan vendor:publish --tag=config --provider="vvb\YandexSmartCaptcha\YandexSmartCaptchaServiceProvider"