From 476333c1d3a786a8b2e01927333a905e650dd0a4 Mon Sep 17 00:00:00 2001 From: ruri Date: Wed, 17 Apr 2019 16:27:59 +0200 Subject: [PATCH] Fixed 2captcha to work with CapMonster and XEvil (switched from json to plaintext response). --- RuriLib/CaptchaServices/TwoCaptcha.cs | 38 +++++++++++---------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/RuriLib/CaptchaServices/TwoCaptcha.cs b/RuriLib/CaptchaServices/TwoCaptcha.cs index 10c10ba..47788a1 100644 --- a/RuriLib/CaptchaServices/TwoCaptcha.cs +++ b/RuriLib/CaptchaServices/TwoCaptcha.cs @@ -26,10 +26,8 @@ namespace RuriLib.CaptchaServices using (CWebClient client = new CWebClient()) { if (Timeout > 0) client.Timeout = Timeout; - var response = client.DownloadString($"http://2captcha.com/res.php?key={ApiKey}&action=getbalance&json=1"); - GenericResponse gbr = JsonConvert.DeserializeObject(response); - if (gbr.status == 0) throw new Exception(gbr.request); - return double.Parse(gbr.request, CultureInfo.InvariantCulture); + var response = client.DownloadString($"http://2captcha.com/res.php?key={ApiKey}&action=getbalance"); + return double.Parse(response, CultureInfo.InvariantCulture); } } @@ -40,10 +38,9 @@ namespace RuriLib.CaptchaServices using (CWebClient client = new CWebClient()) { if (Timeout > 0) client.Timeout = Timeout; - var response = client.DownloadString($"http://2captcha.com/in.php?key={ApiKey}&method=userrecaptcha&googlekey={siteKey}&pageurl={siteUrl}&json=1"); - GenericResponse ctr = JsonConvert.DeserializeObject(response); - if (ctr.status == 0) throw new Exception(ctr.request); - TaskId = ctr.request; + var response = client.DownloadString($"http://2captcha.com/in.php?key={ApiKey}&method=userrecaptcha&googlekey={siteKey}&pageurl={siteUrl}"); + if (!response.StartsWith("OK")) throw new Exception(response); + TaskId = response.Split('|')[1]; Status = CaptchaStatus.Processing; // Check if task has been completed @@ -51,12 +48,11 @@ namespace RuriLib.CaptchaServices while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout) { Thread.Sleep(5000); - response = client.DownloadString($"http://2captcha.com/res.php?key={ApiKey}&action=get&id={TaskId}&json=1"); - GenericResponse gtrr = JsonConvert.DeserializeObject(response); - if (gtrr.request.Contains("NOT_READY")) continue; - if (gtrr.status == 0) throw new Exception(gtrr.request); + response = client.DownloadString($"http://2captcha.com/res.php?key={ApiKey}&action=get&id={TaskId}"); + if (response.Contains("NOT_READY")) continue; + if (response.Contains("ERROR")) throw new Exception(response); Status = CaptchaStatus.Completed; - return gtrr.request; + return response.Split('|')[1]; } throw new TimeoutException(); } @@ -71,10 +67,9 @@ namespace RuriLib.CaptchaServices if (Timeout > 0) client.Timeout = Timeout; client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded"); var response = client.UploadString("http://2captcha.com/in.php", - $"key={ApiKey}&method=base64®sense=1&body={GetBase64(bitmap, ImageFormat.Bmp)}&json=1"); - GenericResponse ctr = JsonConvert.DeserializeObject(response); - if (ctr.status == 0) throw new Exception(ctr.request); - TaskId = ctr.request; + $"key={ApiKey}&method=base64®sense=1&body={GetBase64(bitmap, ImageFormat.Bmp)}"); + if (!response.StartsWith("OK")) throw new Exception(response); + TaskId = response.Split('|')[1]; Status = CaptchaStatus.Processing; // Check if task has been completed @@ -82,12 +77,11 @@ namespace RuriLib.CaptchaServices while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout) { Thread.Sleep(5000); - response = client.DownloadString($"http://2captcha.com/res.php?key={ApiKey}&action=get&id={TaskId}&json=1"); - GenericResponse gtrr = JsonConvert.DeserializeObject(response); - if (gtrr.request.Contains("NOT_READY")) continue; - if (gtrr.status == 0) throw new Exception(gtrr.request); + response = client.DownloadString($"http://2captcha.com/res.php?key={ApiKey}&action=get&id={TaskId}"); + if (response.Contains("NOT_READY")) continue; + if (response.Contains("ERROR")) throw new Exception(response); Status = CaptchaStatus.Completed; - return gtrr.request; + return response.Split('|')[1]; } throw new TimeoutException(); }