mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
Fixed 2captcha to work with CapMonster and XEvil (switched from json to plaintext response).
This commit is contained in:
@@ -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<GenericResponse>(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<GenericResponse>(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<GenericResponse>(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<GenericResponse>(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<GenericResponse>(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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user