Cookie使用通知

本网站会使用cookies,以便记住您的选择,并提供个性化服务。了解更多

如果网站速度慢,请使用网站链接 2captcha.cn
绕过JAVA验证码

绕过JAVA验证码

执行Java库,用于快速绕过验证码。可破解验证码的简单API。

Java程序包可轻松集成2Captcha的验证码破解服务API,以绕过reCAPTCHAhCaptchaArkose captchaGeetest,并破解其他验证码。

快速开始

安装

脚本包可通过安装程序安装或人工安装

Maven中央仓库

2captcha-java工件可用于Maven中心仓库

欢迎您了解GitHub库,找到可轻松集成API的库和模块。

配置

配置已安装软件包的所有必要参数说明

TwoCaptcha类实例可按照如下方法创建:

TwoCaptcha solver = new TwoCaptcha('YOUR_API_KEY');

您还能为已创建的实例设置选项:

solver.setSoftId(123);
solver.setCallback("https://your.site/result-receiver");
solver.setDefaultTimeout(120);
solver.setRecaptchaTimeout(600);
solver.setPollingInterval(10);
TwoCaptcha实例选项
选项默认值说明
softId-您将在2Captcha软件目录发布后获得软件ID
回调函数-验证码识别结果会发送至网络服务器URL,但应先在账户的pingback设置中注册URL
defaultTimeout120除reCAPTCHA外的验证码的轮询超时时间(秒),用于判定模块尝试从res.phpAPI端点获得答案的时间
recaptchaTimeout600reCAPTCHA的轮询超时时间(秒),用于判定模块尝试从res.phpAPI端点获得答案的时间
pollingInterval10res.phpAPI端点发送请求的间隔时间(秒),不建议设置在5秒以内
重要提示:一旦回调函数确定用于TwoCaptcha实例,那么所有方法都只返回验证码ID,无法通过轮询API获得结果。结果将发送至回调URL。请通过getResult方法进行人工破解。

破解验证码

您在提交图片验证码时可提出额外选项,以便2Captcha的员工能够正确破解。

验证码选项
选项默认值说明
numeric0判定验证码是否由数字或其他符号组成,详情请见API文档
minLength0最小答案长度
maxLength0最大答案长度
phrase0判定答案是否由多个词语组成
caseSensitive0判定答案是否区分大小写
calc0确定验证码需要计算
lang-确定验证码语言,见可用语言列表
hintImg-所有验证码员工可见的提示图片
hintText-员工可见的验证码提示或任务文字

基本示例

以下为错误处理的基本破解程序的调用示例。

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());
}
simpleCaptcha

您可以利用以下方法绕过normal captcha(带有扭曲文字的图片)。这个方法也可用于识别图片上的任何文字。

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");
textCaptcha

这种方法可用于绕过需要回答清晰文字问题的验证码。

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

此方法可破解reCAPTCHA V2,并获得令牌实现绕过保护。

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

此方法利可破解reCAPTCHA V3,并返回令牌。

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

FunCaptcha(Arkoselabs)破解方法,并返回令牌。

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

此方法可破解GeeTest拼图验证码,并返回一组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");
hCaptcha

此方法可破解hCaptcha,并返回可以绕过验证码的令牌。

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

通过令牌形式破解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

以令牌形式绕过Capy拼图验证码。

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法最初名为Old reCAPTCHA V2法,先在图中画好网格,点击特定网格框,以绕过任何类型的验证码。这种方法会返回方框数。

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法需要围着图中物体画一条线。这种方法会返回一组点坐标,用于绘制多边形。

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会返回验证码图片的点坐标,若您需要点击图片的特定点,就可以使用这种方法。

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");
rotateCaptcha

这种方法可破解需要旋转物体的验证码,主要用于绕过FunCaptcha。它会返回旋转角度。

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");

其他方法

主要脚本执行时可用的其他方法

send / getResult

上述方法可用于人工提交验证码和答案轮询。

String captchaId = solver.send(captcha);

Thread.sleep(20 * 1000);

String code = solver.getResult(captchaId);

balance

以此方法获取账户余额。

double balance = solver.balance();

report

以此方法报告验证码答案之优劣。

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

错误处理

网站在处理请求时返回的标准错误的可能变体

如发生错误,验证码破解程序会提示异常。妥善处理这类情况很重要。我们推荐使用try/catch来处理异常。

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
}

用于网站API集成的其他语言

Chrome和Firefox浏览器均可使用验证码绕过扩展程序验证码绕过 扩展程序建议扩展
备用扩展
CaptchaTheCat