PHP code example of redpic / antigate

1. Go to this page and download the library: Download redpic/antigate 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/ */

    

redpic / antigate example snippets


'providers' => [
    // ...
    Redpic\Antigate\AntigateServiceProvider::class,
];



namespace App\Listeners;

use Redpic\Antigate\Events\CaptchaWasRecognized;
use Redpic\Antigate\Jobs\RecognizeCaptcha;

class CaptchaWasRecognizedListener
{
    public function handle(CaptchaWasRecognized $event)
    {
        $event->captcha->getKey(); // Тут текст разгаданной капчи
    }
}



namespace App\Listeners;

use Redpic\Antigate\Events\CaptchaWasNotRecognized;
use Redpic\Antigate\Jobs\RecognizeCaptcha;

class CaptchaWasNotRecognizedListener
{
    public function handle(CaptchaWasNotRecognized $event)
    {
        $event->captcha; // Не разгаданная капча
        $event->exception; // Исключение вызванное во время работы

        /*
        Если в этом месте вызвать какое то исключение, 
        то задание по разгадываю этой капчи снова добавится в очередь
        */
    }
}

protected $listen = [
    //...
    'Redpic\Antigate\Events\CaptchaWasRecognized' => [
        'App\Listeners\CaptchaWasRecognizedListener',
    ],
    'Redpic\Antigate\Events\CaptchaWasNotRecognized' => [
        'App\Listeners\CaptchaWasNotRecognizedListener',
    ],
];

$captcha = (new Captcha)->setImageByUrl('http://ПУТЬ_К_КАПЧЕ');
$this->dispatch(new RecognizeCaptcha($captcha));