Coder Social home page Coder Social logo

2captcha / 2captcha-java Goto Github PK

View Code? Open in Web Editor NEW
37.0 2.0 14.0 349 KB

Java library 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

Java 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-java's Introduction

JAVA Module for 2Captcha API

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

Installation

2captcha-java artifact is available in Maven Central

Configuration

TwoCaptcha instance can be created like this:

TwoCaptcha solver = new TwoCaptcha('YOUR_API_KEY');

Also there are few options that can be configured:

solver.setHost("2captcha.com");
solver.setSoftId(123);
solver.setCallback("https://your.site/result-receiver");
solver.setDefaultTimeout(120);
solver.setRecaptchaTimeout(600);
solver.setPollingInterval(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 URL is defined for TwoCaptcha instance with setCallback, 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.

Basic example

Example below shows a basic solver call example with error handling.

Normal captcha = new Normal();
captcha.setFile("path/to/captcha.jpg");
captcha.setMinLen(4);
captcha.setMaxLen(20);
captcha.setCaseSensitive(true);
captcha.setLang("en");

try {
    solver.solve(captcha);
    System.out.println("Captcha solved: " + captcha.getCode());
} catch (Exception e) {
    System.out.println("Error occurred: " + e.getMessage());
}

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.

Normal captcha = new Normal();
captcha.setFile("path/to/captcha.jpg");
captcha.setNumeric(4);
captcha.setMinLen(4);
captcha.setMaxLen(20);
captcha.setPhrase(true);
captcha.setCaseSensitive(true);
captcha.setCalc(false);
captcha.setLang("en");
captcha.setHintImg(new File("path/to/hint.jpg"));
captcha.setHintText("Type red symbols only");

Text Captcha

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

Text captcha = new Text();
captcha.setText("If tomorrow is Saturday, what day is today?");
captcha.setLang("en");

ReCaptcha v2

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

ReCaptcha captcha = new ReCaptcha();
captcha.setSiteKey("6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-");
captcha.setUrl("https://mysite.com/page/with/recaptcha");
captcha.setInvisible(true);
captcha.setEnterprise(true);
captcha.setAction("verify");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

ReCaptcha v3

This method provides ReCaptcha V3 solver and returns a token.

ReCaptcha captcha = new ReCaptcha();
captcha.setSiteKey("6Le-wvkSVVABCPBMRTvw0Q4Muexq1bi0DJwx_mJ-");
captcha.setUrl("https://mysite.com/page/with/recaptcha");
captcha.setVersion("v3");
captcha.setEnterprise(false);
captcha.setAction("verify");
captcha.setScore(0.3);
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

FunCaptcha

FunCaptcha (Arkoselabs) solving method. Returns a token.

FunCaptcha captcha = new FunCaptcha();
captcha.setSiteKey("69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC");
captcha.setUrl("https://mysite.com/page/with/funcaptcha");
captcha.setSUrl("https://client-api.arkoselabs.com");
captcha.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36");
captcha.setData("anyKey", "anyValue");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

GeeTest

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

GeeTest captcha = new GeeTest();
captcha.setGt("f2ae6cadcf7886856696502e1d55e00c");
captcha.setApiServer("api-na.geetest.com");
captcha.setChallenge("12345678abc90123d45678ef90123a456b");
captcha.setUrl("https://mysite.com/captcha.html");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

GeeTestV4

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

GeeTestV4 captcha = new GeeTestV4();
captcha.setCaptchaId("72bf15796d0b69c43867452fea615052");
captcha.setApiServer("api-na.geetest.com");
captcha.setChallenge("12345678abc90123d45678ef90123a456b");
captcha.setUrl("https://mysite.com/captcha.html");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

hCaptcha

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

HCaptcha captcha = new HCaptcha();
captcha.setSiteKey("10000000-ffff-ffff-ffff-000000000001");
captcha.setUrl("https://www.site.com/page/");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

KeyCaptcha

Token-based method to solve KeyCaptcha.

KeyCaptcha captcha = new KeyCaptcha();
captcha.setUserId(10);
captcha.setSessionId("493e52c37c10c2bcdf4a00cbc9ccd1e8");
captcha.setWebServerSign("9006dc725760858e4c0715b835472f22");
captcha.setWebServerSign2("2ca3abe86d90c6142d5571db98af6714");
captcha.setUrl("https://www.keycaptcha.ru/demo-magnetic/");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

Capy

Token-based method to bypass Capy puzzle captcha.

Capy captcha = new Capy();
captcha.setSiteKey("PUZZLE_Abc1dEFghIJKLM2no34P56q7rStu8v");
captcha.setUrl("https://www.mysite.com/captcha/");
captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

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.

Grid captcha = new Grid();
captcha.setFile("path/to/captcha.jpg");
captcha.setRows(3);
captcha.setCols(3);
captcha.setPreviousId(0);
captcha.setCanSkip(false);
captcha.setLang("en");
captcha.setHintImg(new File("path/to/hint.jpg"));
captcha.setHintText("Select all images with an Orange");

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.

Canvas captcha = new Canvas();
captcha.setFile("path/to/captcha.jpg");
captcha.setPreviousId(0);
captcha.setCanSkip(false);
captcha.setLang("en");
captcha.setHintImg(new File("path/to/hint.jpg"));
captcha.setHintText("Draw around apple");

ClickCaptcha

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

Coordinates captcha = new Coordinates();
captcha.setFile("path/to/captcha.jpg");
captcha.setLang("en");
captcha.setHintImg(new File("path/to/hint.jpg"));
captcha.setHintText("Select all images with an Orange");

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.

Rotate captcha = new Rotate();
captcha.setFile("path/to/captcha.jpg");
captcha.setAngle(40);
captcha.setLang("en");
captcha.setHintImg(new File("path/to/hint.jpg"));
captcha.setHintText("Put the images in the correct way up");

Audio

This method can be used to solve a audio captcha

TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
byte[] bytes = Files.readAllBytes(Paths.get("src/main/resources/audio-en.mp3"));
String base64EncodedImage = Base64.getEncoder().encodeToString(bytes);
Audio captcha = new Audio();
captcha.setBase64(base64EncodedImage);

Yandex

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

TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
Yandex captcha = new Yandex();
captcha.setSiteKey("Y5Lh0tiycconMJGsFd3EbbuNKSp1yaZESUOIHfeV");
captcha.setUrl("https://rutube.ru");

Lemin

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

TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
Lemin captcha = new Lemin();      
captcha.setСaptchaId("CROPPED_d3d4d56_73ca4008925b4f83a8bed59c2dd0df6d");
captcha.setUrl("http://sat2.aksigorta.com.tr");
captcha.setApiServer("api.leminnow.com");

Turnstile

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

TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
Turnstile captcha = new Turnstile();
captcha.setSiteKey("0x4AAAAAAAChNiVJM_WtShFf");
captcha.setUrl("https://ace.fusionist.io");

AmazonWaf

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

TwoCaptcha solver = new TwoCaptcha("YOUR_API_KEY");
AmazonWaf captcha = new AmazonWaf();
captcha.setSiteKey("AQIDAHjcYu/GjX+QlghicBgQ/7bFaQZ+m5FKCMDnO+vTbNg96AF5H1K/siwSLK7RfstKtN5bAAAAfjB8BgkqhkiG9w0BBwagbzBtAgEAMGgGCSqGSIb3DQEHATAeBglg");
captcha.setUrl("https://non-existent-example.execute-api.us-east-1.amazonaws.com");
captcha.setIV("test_iv");
captcha.setContext("test_context");

Other methods

send / getResult

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

String captchaId = solver.send(captcha);

Thread.sleep(20 * 1000);

String code = solver.getResult(captchaId);

balance

Use this method to get your account's balance

double balance = solver.balance();

report

Use this method to report good or bad captcha answer.

solver.report(captcha.getId(), true); // captcha solved correctly
solver.report(captcha.getId(), false); // captcha solved incorrectly

Proxies

You can pass your proxy as an additional argument for methods: recaptcha, funcaptcha, geetest, geetest v4, hcaptcha, keycaptcha, capy puzzle, lemin, turnstile, amazon waf and etc. The proxy will be forwarded to the API to solve the captcha.

We have our own proxies that we can offer you. Buy residential proxies for avoid restrictions and blocks. Quick start.

captcha.setProxy("HTTPS", "login:password@IP_address:PORT");

Error handling

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

try {
    solver.solve(captcha);
} catch (ValidationException e) {
    // invalid parameters passed
} catch (NetworkException e) {
    // network error occurred
} catch (ApiException e) {
    // api respond with error
} catch (TimeoutException e) {
    // captcha is not solved so far
}

2captcha-java's People

Contributors

dependabot[bot] avatar dzmitry-duboyski avatar italogustavoborba avatar kratzky 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

Watchers

 avatar  avatar

2captcha-java's Issues

No option to add mark ReCaptcha as enterprise or add custom data-s Field

Under the official documentation:

Add an additional parameter enterprise=1 to your request to in.php endpoint and interact with our API the same way it is done when solving V2 or solving V3 to get the token, then use the token in the same way it is used on your target website.

For V2 implementations there can be optional additional data used: in most cases that is a custom string value defined in s or data-s parameter. You can pass this data inside data-s request parameter.

Workaround is extending the ReCaptcha Class.

How to install

Hey Whats going on ..

How do I pair the library with my project on Inteliij Idea witch I put it on libraries area but I can only use:
TwoCaptcha solver = new TwoCaptcha('YOUR_API_KEY');
I can't do
solver.setSoftId(); || setCAllBack etc...

java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(byte[])

java.lang.NoSuchMethodError: 'okhttp3.RequestBody okhttp3.RequestBody.create(byte[])'
Continually receiving this error when making a call to the api client code utilizing okhttp3. I have imported the maven dependency: <dependency> <groupId>com.github.2captcha</groupId> <artifactId>2captcha-java</artifactId> <version>1.0.1</version> </dependency>

I cannot figure out if it is because this api is deprecated or if it is the way I'm using it.
Here is my code for actually implementing this client:
Normal captcha = new Normal(pathName); try { TwoCaptcha solver = new TwoCaptcha(utils.getAPIKey()); solver.solve(captcha); String code =captcha.getCode(); System.out.println("Captcha solved: " + code); return code; } catch (Exception e){ System.out.println("Error occurred: " + e.getMessage()); return null; }

Turnstile requires 3 parameters

Turnstile requires 3 parameters, if you do not use proxy.

type String Yes Task type:TurnstileTaskProxylessTurnstileTask
websiteURL String Yes The full URL of target web page where the captcha is loaded. We do not open the page, not a problem if it is available only for authenticated users
websiteKey String Yes Turnstile sitekey. Can be found inside data-sitekey property of the Turnstile div element

But tasktype is missing, therefore API always return error BAD_PARAMETERS when using without proxy.

Captcha.getParams method return a copy of original HasMap

Captcha.getParams method returns a copy of the original map, making it impossible to add additional parameters to break the captcha.

Ex: AmazonWaf.

amazonWaf.getParams().put("challengeScript", "value").

The value will never be added to the map

Don't work

Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/RequestBody
at com.twocaptcha.TwoCaptcha.(TwoCaptcha.java:66)
at com.twocaptcha.TwoCaptcha.(TwoCaptcha.java:75)
at Main.main(Main.java:96)
Caused by: java.lang.ClassNotFoundException: okhttp3.RequestBody
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 3 more

Just Stop Working

I've been working without problems until today.

Same application, without any code change since 10/30/2020.

Now every single request I receive this exceptions .

2CAPTCHA CHAMADO

com.twocaptcha.exceptions.ApiException: ERROR_ZERO_CAPTCHA_FILESIZE
at com.twocaptcha.ApiClient.execute(ApiClient.java:100)
at com.twocaptcha.ApiClient.in(ApiClient.java:59)
at com.twocaptcha.TwoCaptcha.send(TwoCaptcha.java:212)
at com.twocaptcha.TwoCaptcha.solve(TwoCaptcha.java:154)
at com.twocaptcha.TwoCaptcha.solve(TwoCaptcha.java:142)
at com.mueller.pregaobot.parser.ConsultaAtaPage.captchaScreen(ConsultaAtaPage.java:276)
at com.mueller.pregaobot.parser.ConsultaAtaPage.listaScreen(ConsultaAtaPage.java:121)
at com.mueller.pregaobot.parser.ConsultaAtaPage.search(ConsultaAtaPage.java:84)
at com.mueller.pregaobot.Main$2.lambda$actionPerformed$0(Main.java:153)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
ERRO AO INVALIDAR CAPTCHA
CAPTCHA INVÁLIDO. INFORME NOVAMENTE.

2CAPTCHA CHAMADO

com.twocaptcha.exceptions.ApiException: Cannot recognise api response (TOO_MANY_BAD_IMAGES)
at com.twocaptcha.TwoCaptcha.send(TwoCaptcha.java:215)
at com.twocaptcha.TwoCaptcha.solve(TwoCaptcha.java:154)
at com.twocaptcha.TwoCaptcha.solve(TwoCaptcha.java:142)
at com.mueller.pregaobot.parser.ConsultaAtaPage.captchaScreen(ConsultaAtaPage.java:276)
at com.mueller.pregaobot.parser.ConsultaAtaPage.listaScreen(ConsultaAtaPage.java:121)
at com.mueller.pregaobot.parser.ConsultaAtaPage.search(ConsultaAtaPage.java:84)
at com.mueller.pregaobot.Main$2.lambda$actionPerformed$0(Main.java:153)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)

Captcha

94db4b8b05d25b616c56a135c3248960

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.