Cookie使用通知

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

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

利用C#绕过验证码

将API与C#库集成,实现自动打码,适用于任何脚本。

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

快速开始

安装

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

NuGet

您需要使用NuGet来自动安装库包,这是CSharp程序包的标准解决方案。前往链接下载并按指示安装。安装完成后,再安装所需的库包

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

配置

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

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

TwoCaptcha solver = new TwoCaptcha('YOUR_API_KEY');

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

solver.SoftId = 123;
solver.Callback = "https://your.site/result-receiver";
solver.DefaultTimeout = 120;
solver.RecaptchaTimeout = 600;
solver.PollingInterval = 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
{
    await solver.Solve(captcha);
    Console.WriteLine("Captcha solved: " + captcha.Code);
}
catch (Exception e)
{
    Console.WriteLine("Error occurred: " + e.Message);
}
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 FileInfo("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.SetDomain("google.com");
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 FileInfo("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 FileInfo("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 FileInfo("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 FileInfo("path/to/hint.jpg"));
captcha.SetHintText("Put the images in the correct way up");

其他方法

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

send / getResult

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

string captchaId = await solver.Send(captcha);

Task.sleep(20 * 1000);

string code = await solver.GetResult(captchaId);

balance

以此方法获取账户余额。

double balance = await solver.Balance();

report

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

await solver.Report(captcha.Id, true); // captcha solved correctly
await solver.Report(captcha.Id, false); // captcha solved incorrectly

错误处理

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

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

try
{
    await 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集成的其他语言