omasn/decaptcha-bundle

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.

Symfony Decaptcha bundle, распознавание капч для всех популярных сервисов rucaptcha.com, 2captcha.com, pixodrom.com, captcha24.com, socialink.ru, anti-captcha.com

1.1.2 2017-09-23 13:25 UTC

This package is auto-updated.

Last update: 2021-06-15 18:56:04 UTC


README

Symfony Decaptcha bundle.

The package is created for standardization of all services on guessing Captcha. Each service has its own characteristics and now you do not need to operate a few packages. It is enough only to familiarize with the available documentation in order to customize each. The package covers all the functionality of the services. If you do not have enough functionality, I'll be happy to hear all the suggestions. Bundle is implemented on the basis of https://github.com/jumper423/decaptcha

Choose Language

Menu

Services

Captcha Recognition for all popular services

Installation

Get the bundle

Let Composer download and install the bundle by running

Or you can run

composer require omasn/decaptcha-bundle "*"

or add

"omasn/decaptcha-bundle": "1.1.*"

in file composer.json.

Enable the bundle

// in app/AppKernel.php
public function registerBundles() {
	$bundles = [
		...
		new Omasn\DecaptchaBundle\DecaptchaBundle(),
	];
	...
}

Configuration bundle

Configure api_key for those Captcha Recognition services that you want to use.

# app/config/config.yml
omasn_decaptcha:
    ru_captcha:
        api_key: '%api_key%'
    anticaptcha:
        api_key: '%api_key%'
    captcha_24:
        api_key: '%api_key%'
    pixodrom:
        api_key: '%api_key%'
    ripcaptcha:
        api_key: '%api_key%'
    socialink:
        api_key: '%api_key%'
    two_captcha:
        api_key: '%api_key%'

Usage

A small example of how on the basis of the RuCaptcha service to get your current balance in the system and by the available url to recognize the captcha. For more information on usage, see Documentation

Example in the controller action

// src/AppBundle/Controller/DefaultController.php
...
public function indexAction()
{
    $oReCapcha = $this->get('decaptcha.ru_captcha');
    $iBalance = $oReCapcha->getBalance();
    ...
    if ($oReCapcha->recognize('http://site.ru/captcha.jpg')) {
        $code = $oReCapcha->getCode();
        if (!$myApp->validCode($code)) {
            $oReCapcha->notTrue(); // not valid code request in api
        }
    } else {
        $error = $oReCapcha->getError();
    }
}
...

Using an additional configuration

Add additional parameters to the RuCaptcha configuration "Description of fields"

// src/AppBundle/Controller/DefaultController.php

use Omasn\DecaptchaBundle\Services\RuCaptcha;

...
public function indexAction()
{
    $oReCapcha = $this->get('decaptcha.ru_captcha');
    $oReCapcha->setParams([
        RuCaptcha::ACTION_FIELD_FILE => '/file/to/path',
    ]);
}
...