GithubHelp home page GithubHelp logo

2captcha / 2captcha-php Goto Github PK

View Code? Open in Web Editor NEW
61.0 6.0 44.0 376 KB

PHP package for easy integration with the API of 2captcha captcha solving service to bypass recaptcha, hcaptcha, funcaptcha, geetest and solve any other captchas.

Home Page: https://2captcha.com

PHP 100.00%
2captcha recaptcha-v2-captcha-solver captcha-solving captcha-recognition captcha-breaking anticaptcha anti-captcha bypass-invisible-recaptcha bypass-on-captcha-recaptcha bypass-recaptcha-v2

2captcha-php's Introduction

PHP Module for 2Captcha API

The easiest way to quickly integrate 2Captcha captcha solving service into your code to automate solving of any types of captcha.

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:

$solver = new \TwoCaptcha\TwoCaptcha('YOUR_API_KEY');

Also there are few options that can be configured:

$solver = new \TwoCaptcha\TwoCaptcha([
    'server'           => 'http://rucaptcha.com',
    'apiKey'           => 'YOUR_API_KEY',
    'softId'           => 123,
    'callback'         => 'https://your.site/result-receiver',
    'defaultTimeout'   => 120,
    'recaptchaTimeout' => 600,
    'pollingInterval'  => 10,
]);

TwoCaptcha instance options

Option Default value Description
softId - your software ID obtained after publishing in 2captcha sofware catalog
callback - URL of your web-sever that receives the captcha recognition result. The URl should be first registered in pingback settings of your account
defaultTimeout 120 Polling timeout in seconds for all captcha types except ReCaptcha. Defines how long the module tries to get the answer from res.php API endpoint
recaptchaTimeout 600 Polling timeout for ReCaptcha in seconds. Defines how long the module tries to get the answer from res.php API endpoint
pollingInterval 10 Interval in seconds between requests to res.php API endpoint, setting values less than 5 seconds is not recommended

IMPORTANT: once callback is defined for TwoCaptcha instance, all methods return only the captcha ID and DO NOT poll the API to get the result. The result will be sent to the callback URL. To get the answer manually use getResult method

Solve captcha

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

Captcha options

Option Default Value Description
numeric 0 Defines if captcha contains numeric or other symbols see more info in the API docs
minLength 0 minimal answer lenght
maxLength 0 maximum answer length
phrase 0 defines if the answer contains multiple words or not
caseSensitive 0 defines if the answer is case sensitive
calc 0 defines captcha requires calculation
lang - defines the captcha language, see the list of supported languages
hintImg - an image with hint shown to workers with the captcha
hintText - hint or task text shown to workers with the captcha

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.

$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.

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

FunCaptcha

FunCaptcha (Arkoselabs) solving method. Returns a token.

$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.

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

GeeTestV4

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

$result = $solver->geetest_v4([
    'captchaId' => '72bf15796d0b69c43867452fea615052',
    'url'       => 'https://mysite.com/captcha.html',
]);

hCaptcha

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

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

KeyCaptcha

Token-based method to solve KeyCaptcha.

$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.

$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');

Audio

This method can be used to solve a audio captcha

$result = $solver->audio('path/to/audio.mp3');

Yandex

Use this method to solve Yandex and obtain a token to bypass the protection.

$result = $solver->yandex([
    'sitekey' => 'Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV',
    'url'     => 'https://rutube.ru',
]);

Lemin

Use this method to solve Lemin and obtain a token to bypass the protection.

$result = $solver->lemin([
    'captchaId' => 'CROPPED_d3d4d56_73ca4008925b4f83a8bed59c2dd0df6d',
    'apiServer' => 'api.leminnow.com',
    'url'       => 'http://sat2.aksigorta.com.tr',
]);

Turnstile

Use this method to solve Turnstile and obtain a token to bypass the protection.

$result = $solver->turnstile([
    'sitekey' => '0x4AAAAAAAChNiVJM_WtShFf',
    'url'     => 'https://ace.fusionist.io',
]);

AmazonWaf

Use this method to solve AmazonWaf and obtain a token to bypass the protection.

$result = $solver->amazon_waf([
    'sitekey' => 'AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AF5H1K/siwSLK7RfstKtN5bAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglg',
    'url'     => 'https://non-existent-example.execute-api.us-east-1.amazonaws.com',
    'iv'      => 'test_iv',
    'context' => 'test_context'
]);

Other methods

send / getResult

These methods can be used for manual captcha submission and answer polling.

$id = $solver->send(['file' => 'path/to/captcha.jpg', ...]);

sleep(20);

$code = $solver->getResult($id);

balance

Use this method to get your account's balance

$balance = $solver->balance();

report

Use this method to report good or bad captcha answer.

$solver->report($id, true); // captcha solved correctly
$solver->report($id, false); // captcha solved incorrectly

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.

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
}

2captcha-php's People

Contributors

kratzky avatar lucasferreira avatar zatvorius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

2captcha-php's Issues

Every time geting error ERROR_KEY_DOES_NOT_EXIST

Code example

$solver = new \TwoCaptcha\TwoCaptcha('key_value');

try {
    $result = $solver->recaptcha([
        'sitekey' => '6LfD3PIbAAAAAJs_eEHvoOl75_83eXSqpPSRFJ_u',
        'url'     => 'https://2captcha.com/demo/recaptcha-v2',
    ]);
} catch (\Exception $e) {
    die($e->getMessage());
}
$solver = new \TwoCaptcha\TwoCaptcha('key_value');

try {
    $result = $solver->turnstile([
        'sitekey' => '0x4AAAAAAAVrOwQWPlm3Bnr5',
        'url'     => 'https://2captcha.com/demo/cloudflare-turnstile',
    ]);
} catch (\Exception $e) {
    die($e->getMessage());
}

help

I need to send a cookies to the site where the captcha will be passed

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.