PHP package for easy integration with 2captcha AP

CAPTCHAFORUM

Administrator
1655989700650.png

Installation
This package can be installed via composer or manually

Composer
composer require 2captcha/2captcha

Manual
Copy src directory to your project and then require autoloader (src/autoloader.php) where needed:

require 'path/to/autoloader.php';

Configuration
TwoCaptcha instance can be created like this:

Code:
$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');
Also there are few options that can be configured:
$solver = new \TwoCaptcha\TwoCaptcha([
    'apiKey'           => 'YOUR_API_KEY',
    'softId'           => 123,
    'callback'         => 'https://your.site/result-receiver',
    'defaultTimeout'   => 120,
    'recaptchaTimeout' => 600,
    'pollingInterval'  => 10,
]);

1655989784306.png

Solve captcha
When you submit any image-based captcha use can provide additional options to help 2captcha workers to solve it properly.

1655989773616.png

Below you can find basic examples for every captcha type. Check out examples directory to find more examples with all available options.

Normal Captcha
To bypass a normal captcha (distorted text on image) use the following method. This method also can be used to recognize any text on the image.

$result = $solver->normal('path/to/captcha.jpg');

Text Captcha
This method can be used to bypass a captcha that requires to answer a question provided in clear text.

$result = $solver->text('If tomorrow is Saturday, what day is today?');

ReCaptcha v2
Use this method to solve ReCaptcha V2 and obtain a token to bypass the protection.

Code:
$result = $solver->recaptcha([
    'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
    'url'     => 'https://mysite.com/page/with/recaptcha',
]);

ReCaptcha v3
This method provides ReCaptcha V3 solver and returns a token.

Code:
$result = $solver->recaptcha([
    'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
    'url'     => 'https://mysite.com/page/with/recaptcha',
    'version' => 'v3',
]);

FunCaptcha
FunCaptcha (Arkoselabs) solving method. Returns a token.

Code:
$result = $solver->funcaptcha([
    'sitekey' => '6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-',
    'url'     => 'https://mysite.com/page/with/funcaptcha',
]);

GeeTest
Method to solve GeeTest puzzle captcha. Returns a set of tokens as JSON.

Code:
$result = $solver->geetest([
    'gt'        => 'f1ab2cdefa3456789012345b6c78d90e',
    'challenge' => '12345678abc90123d45678ef90123a456b',
    'url'       => 'https://www.site.com/page/',
]);

hCaptcha
Use this method to solve hCaptcha challenge. Returns a token to bypass captcha.

Code:
$result = $solver->hcaptcha([
    'sitekey'   => '10000000-ffff-ffff-ffff-000000000001',
    'url'       => 'https://www.site.com/page/',
]);

KeyCaptcha
Token-based method to solve KeyCaptcha.

Code:
$result = $solver->keycaptcha([

    's_s_c_user_id'          => 10,

    's_s_c_session_id'       => '493e52c37c10c2bcdf4a00cbc9ccd1e8',

    's_s_c_web_server_sign'  => '9006dc725760858e4c0715b835472f22-pz-',

    's_s_c_web_server_sign2' => '2ca3abe86d90c6142d5571db98af6714',

    'url'                    => 'https://www.keycaptcha.ru/demo-magnetic/',

]);

Capy
Token-based method to bypass Capy puzzle captcha.

Code:
$result = $solver->capy([

    'sitekey' => 'PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v',

    'url'     => 'http://mysite.com/',

    'api_server' => 'https://jp.api.capy.me/',

]);

Grid
Grid method is originally called Old ReCaptcha V2 method. The method can be used to bypass any type of captcha where you can apply a grid on image and need to click specific grid boxes. Returns numbers of boxes.

$result = $solver->grid('path/to/captcha.jpg');

Canvas
Canvas method can be used when you need to draw a line around an object on image. Returns a set of points' coordinates to draw a polygon.

$result = $solver->canvas('path/to/captcha.jpg');

ClickCaptcha
ClickCaptcha method returns coordinates of points on captcha image. Can be used if you need to click on particular points on the image.

$result = $solver->coordinates('path/to/captcha.jpg');
Rotate
This method can be used to solve a captcha that asks to rotate an object. Mostly used to bypass FunCaptcha. Returns the rotation angle.

$result = $solver->rotate('path/to/captcha.jpg');

Error handling
If case of an error captch solver throws an exception. It's important to properly handle these cases. We recommend to use try catch to handle exceptions.

Code:
try {

    $result = $solver->text('If tomorrow is Saturday, what day is today?');

} catch (\TwoCaptcha\Exception\ValidationException $e) {

    // invalid parameters passed

} catch (\TwoCaptcha\Exception\NetworkException $e) {

    // network error occurred

} catch (\TwoCaptcha\Exception\ApiException $e) {

    // api respond with error

} catch (\TwoCaptcha\Exception\TimeoutException $e) {

    // captcha is not solved so far

}

Doumentation https://packagist.org/packages/2captcha/2captcha