mirror of
https://github.com/openbullet/openbullet.git
synced 2023-10-21 07:33:42 -05:00
First commit - OpenBullet 1.0.0
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of https://azcaptcha.com/
|
||||
/// </summary>
|
||||
public class AZCaptcha : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an AZCaptcha client.
|
||||
/// </summary>
|
||||
/// <param name="apiKey">The AZCaptcha API key</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public AZCaptcha(string apiKey, int timeout) : base(apiKey, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
var response = client.DownloadString($"http://azcaptcha.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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
var response = client.DownloadString($"http://azcaptcha.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;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
response = client.DownloadString($"http://azcaptcha.com/res.php?key={ApiKey}&action=get&id={TaskId}&json=1");
|
||||
GenericResponse gtrr = JsonConvert.DeserializeObject<GenericResponse>(response);
|
||||
if (gtrr.request.Contains("NOTREADY")) continue;
|
||||
if (gtrr.status == 0) throw new Exception(gtrr.request);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.request;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
var response = client.UploadString("http://azcaptcha.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;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
response = client.DownloadString($"http://azcaptcha.com/res.php?key={ApiKey}&action=get&id={TaskId}&json=1");
|
||||
GenericResponse gtrr = JsonConvert.DeserializeObject<GenericResponse>(response);
|
||||
if (gtrr.request.Contains("NOTREADY")) continue;
|
||||
if (gtrr.status == 0) throw new Exception(gtrr.request);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.request;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable 0414
|
||||
#pragma warning disable 0649
|
||||
class GenericResponse
|
||||
{
|
||||
public int status;
|
||||
public string request;
|
||||
}
|
||||
#pragma warning restore 0414
|
||||
#pragma warning restore 0649
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of https://anti-captcha.com/
|
||||
/// </summary>
|
||||
public class AntiCaptcha : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an AntiCaptcha client.
|
||||
/// </summary>
|
||||
/// <param name="apiKey">The AntiCaptcha API key</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public AntiCaptcha(string apiKey, int timeout) : base(apiKey, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
||||
var response = client.UploadString("https://api.anti-captcha.com/getBalance",
|
||||
JsonConvert.SerializeObject(new GetBalanceRequest(ApiKey)));
|
||||
GetBalanceResponse gbr = JsonConvert.DeserializeObject<GetBalanceResponse>(response);
|
||||
if (gbr.errorId > 0) throw new Exception(gbr.errorCode);
|
||||
return gbr.balance;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
||||
var response = client.UploadString("https://api.anti-captcha.com/createTask",
|
||||
JsonConvert.SerializeObject(new CreateRecaptchaTaskRequest(ApiKey, siteUrl, siteKey)));
|
||||
CreateTaskResponse ctr = JsonConvert.DeserializeObject<CreateTaskResponse>(response);
|
||||
if (ctr.errorId > 0) throw new Exception(ctr.errorCode);
|
||||
TaskId = ctr.taskId;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
||||
response = client.UploadString("https://api.anti-captcha.com/getTaskResult",
|
||||
JsonConvert.SerializeObject(new GetTaskResultRequest(ApiKey, TaskId)));
|
||||
GetTaskResultRecaptchaResponse gtrr = JsonConvert.DeserializeObject<GetTaskResultRecaptchaResponse>(response);
|
||||
if (gtrr.errorId > 0) throw new Exception(gtrr.errorCode);
|
||||
if (gtrr.status == "ready")
|
||||
{
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.solution.gRecaptchaResponse;
|
||||
}
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
||||
var response = client.UploadString("https://api.anti-captcha.com/createTask",
|
||||
JsonConvert.SerializeObject(new CreateCaptchaTaskRequest(ApiKey, GetBase64(bitmap, ImageFormat.Png))));
|
||||
CreateTaskResponse ctr = JsonConvert.DeserializeObject<CreateTaskResponse>(response);
|
||||
if (ctr.errorId > 0) throw new Exception(ctr.errorCode);
|
||||
TaskId = ctr.taskId;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");
|
||||
response = client.UploadString("https://api.anti-captcha.com/getTaskResult",
|
||||
JsonConvert.SerializeObject(new GetTaskResultRequest(ApiKey, TaskId)));
|
||||
GetTaskResultCaptchaResponse gtrr = JsonConvert.DeserializeObject<GetTaskResultCaptchaResponse>(response);
|
||||
if (gtrr.errorId > 0) throw new Exception(gtrr.errorCode);
|
||||
if (gtrr.status == "ready")
|
||||
{
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.solution.text;
|
||||
}
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable 0414
|
||||
#pragma warning disable 0649
|
||||
class GetBalanceRequest
|
||||
{
|
||||
public string clientKey;
|
||||
public GetBalanceRequest(string apiKey) { clientKey = apiKey; }
|
||||
}
|
||||
|
||||
class GetBalanceResponse
|
||||
{
|
||||
public int errorId;
|
||||
public string errorCode;
|
||||
public double balance;
|
||||
}
|
||||
|
||||
class CreateRecaptchaTaskRequest
|
||||
{
|
||||
public string clientKey;
|
||||
public RecaptchaTask task;
|
||||
public CreateRecaptchaTaskRequest(string apiKey, string url, string key) { clientKey = apiKey; task = new RecaptchaTask(url, key); }
|
||||
}
|
||||
|
||||
class RecaptchaTask
|
||||
{
|
||||
public string type = "NoCaptchaTaskProxyless";
|
||||
public string websiteURL;
|
||||
public string websiteKey;
|
||||
public RecaptchaTask(string url, string key) { websiteURL = url; websiteKey = key; }
|
||||
}
|
||||
|
||||
class CreateCaptchaTaskRequest
|
||||
{
|
||||
public string clientKey;
|
||||
public CaptchaTask task;
|
||||
public CreateCaptchaTaskRequest(string apiKey, string base64) { clientKey = apiKey; task = new CaptchaTask(base64); }
|
||||
}
|
||||
|
||||
class CaptchaTask
|
||||
{
|
||||
public string type = "ImageToTextTask";
|
||||
public string body;
|
||||
public CaptchaTask(string base64) { body = base64; }
|
||||
}
|
||||
|
||||
class CreateTaskResponse
|
||||
{
|
||||
public int errorId;
|
||||
public int taskId;
|
||||
public string errorCode;
|
||||
}
|
||||
|
||||
class GetTaskResultRequest
|
||||
{
|
||||
public string clientKey;
|
||||
public int taskId;
|
||||
public GetTaskResultRequest(string apiKey, int id) { clientKey = apiKey; taskId = id; }
|
||||
}
|
||||
|
||||
class GetTaskResultCaptchaResponse
|
||||
{
|
||||
public int errorId;
|
||||
public string errorCode;
|
||||
public string status;
|
||||
public CaptchaSolution solution;
|
||||
}
|
||||
|
||||
class GetTaskResultRecaptchaResponse
|
||||
{
|
||||
public int errorId;
|
||||
public string errorCode;
|
||||
public string status;
|
||||
public RecaptchaSolution solution;
|
||||
}
|
||||
|
||||
class RecaptchaSolution
|
||||
{
|
||||
public string gRecaptchaResponse;
|
||||
}
|
||||
|
||||
class CaptchaSolution
|
||||
{
|
||||
public string text;
|
||||
}
|
||||
#pragma warning restore 0414
|
||||
#pragma warning restore 0649
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// A WebClient with customizable timeout.
|
||||
/// </summary>
|
||||
public class CWebClient : WebClient
|
||||
{
|
||||
/// <summary>The maximum time to wait for a response.</summary>
|
||||
public int Timeout { get; set; } = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the WebRequest.
|
||||
/// </summary>
|
||||
/// <param name="uri">The uri</param>
|
||||
/// <returns>The WebRequest</returns>
|
||||
protected override WebRequest GetWebRequest(Uri uri)
|
||||
{
|
||||
WebRequest w = base.GetWebRequest(uri);
|
||||
w.Timeout = Timeout * 1000;
|
||||
return w;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent a captcha-solving service.
|
||||
/// </summary>
|
||||
public abstract class CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// The busy status of the service.
|
||||
/// </summary>
|
||||
public enum CaptchaStatus
|
||||
{
|
||||
/// <summary>No captcha is being solved.</summary>
|
||||
Idle,
|
||||
|
||||
/// <summary>A captcha is being solved.</summary>
|
||||
Processing,
|
||||
|
||||
/// <summary>A captcha was solved.</summary>
|
||||
Completed
|
||||
}
|
||||
|
||||
/// <summary>The API key to access the captcha service.</summary>
|
||||
public string ApiKey { get; set; }
|
||||
|
||||
/// <summary>The username to access the captcha service.</summary>
|
||||
public string User { get; set; }
|
||||
|
||||
/// <summary>The password to access the captcha service.</summary>
|
||||
public string Pass { get; set; }
|
||||
|
||||
/// <summary>The maximum time to wait for captcha completion.</summary>
|
||||
public int Timeout { get; set; }
|
||||
|
||||
/// <summary>The id of the captcha-solving task being performed on the remote server, used to periodically query the status of the task.</summary>
|
||||
public dynamic TaskId { get; set; }
|
||||
|
||||
/// <summary>The status of the captcha service.</summary>
|
||||
public CaptchaStatus Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Creates a captcha service that authenticates via API key.
|
||||
/// </summary>
|
||||
/// <param name="apiKey">The API key of the account</param>
|
||||
/// <param name="timeout">The maximum time to wait for captcha completion</param>
|
||||
public CaptchaService(string apiKey, int timeout)
|
||||
{
|
||||
ApiKey = apiKey;
|
||||
Timeout = timeout;
|
||||
Status = CaptchaStatus.Idle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a captcha service that authenticates via username and password.
|
||||
/// </summary>
|
||||
/// <param name="user">The username of the account</param>
|
||||
/// <param name="pass">The password of the account</param>
|
||||
/// <param name="timeout">The maximum time to wait for captcha completion</param>
|
||||
public CaptchaService(string user, string pass, int timeout)
|
||||
{
|
||||
User = user;
|
||||
Pass = pass;
|
||||
Timeout = timeout;
|
||||
Status = CaptchaStatus.Idle;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the remaining balance in the account.
|
||||
/// </summary>
|
||||
/// <returns>The balance of the account</returns>
|
||||
public virtual double GetBalance()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Solves a reCaptcha challenge for a given site.
|
||||
/// </summary>
|
||||
/// <param name="siteKey">The SiteKey found in the page's source code</param>
|
||||
/// <param name="siteUrl">The URL of the site to solve a reCaptcha for</param>
|
||||
/// <returns>The g-recaptcha-response of the challenge</returns>
|
||||
public virtual string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Solves an image captcha challenge.
|
||||
/// </summary>
|
||||
/// <param name="image">The bitmap image of the challenge</param>
|
||||
/// <returns>The text written in the image</returns>
|
||||
public virtual string SolveCaptcha(Bitmap image)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base64-encoded string from an image.
|
||||
/// </summary>
|
||||
/// <param name="image">The bitmap image</param>
|
||||
/// <param name="format">The format of the bitmap image</param>
|
||||
/// <returns>The base64-encoded string</returns>
|
||||
protected string GetBase64(Bitmap image, ImageFormat format)
|
||||
{
|
||||
MemoryStream stream = new MemoryStream();
|
||||
image.Save(stream, format);
|
||||
byte[] imageBytes = stream.ToArray();
|
||||
return Convert.ToBase64String(imageBytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a memory stream from an image.
|
||||
/// </summary>
|
||||
/// <param name="image">The bitmap image</param>
|
||||
/// <param name="format">The format of the bitmap image</param>
|
||||
/// <returns>The memory stream</returns>
|
||||
protected Stream GetStream(Bitmap image, ImageFormat format)
|
||||
{
|
||||
Stream stream = new MemoryStream();
|
||||
image.Save(stream, format);
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the bytes from an image.
|
||||
/// </summary>
|
||||
/// <param name="image">The bitmap image</param>
|
||||
/// <returns>The bytes of the image</returns>
|
||||
protected byte[] GetBytes(Bitmap image)
|
||||
{
|
||||
ImageConverter converter = new ImageConverter();
|
||||
return (byte[])converter.ConvertTo(image, typeof(byte[]));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a synchronous POST request that returns a string.
|
||||
/// </summary>
|
||||
/// <param name="client">The HttpClient that performs the async request</param>
|
||||
/// <param name="url">The URL to call</param>
|
||||
/// <param name="content">The content that needs to be posted</param>
|
||||
/// <returns>The response as a string</returns>
|
||||
protected string PostSync(HttpClient client, string url, HttpContent content)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
Task.Run(() =>
|
||||
client.PostAsync(url, content))
|
||||
.Result.Content.ReadAsStringAsync())
|
||||
.Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a synchronous POST request that returns a byte array.
|
||||
/// </summary>
|
||||
/// <param name="client">The HttpClient that performs the async request</param>
|
||||
/// <param name="url">The URL to call</param>
|
||||
/// <param name="content">The content that needs to be posted</param>
|
||||
/// <returns>The response as a byte array</returns>
|
||||
protected byte[] PostSync2(HttpClient client, string url, HttpContent content)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
Task.Run(() =>
|
||||
client.PostAsync(url, content))
|
||||
.Result.Content.ReadAsByteArrayAsync())
|
||||
.Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs a synchronous POST request that returns a stream.
|
||||
/// </summary>
|
||||
/// <param name="client">The HttpClient that performs the async request</param>
|
||||
/// <param name="url">The URL to call</param>
|
||||
/// <param name="content">The content that needs to be posted</param>
|
||||
/// <returns>The response as a stream</returns>
|
||||
protected Stream PostSync3(HttpClient client, string url, HttpContent content)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
Task.Run(() =>
|
||||
client.PostAsync(url, content))
|
||||
.Result.Content.ReadAsStreamAsync())
|
||||
.Result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of https://captchas.io/
|
||||
/// </summary>
|
||||
public class CaptchasIO : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a CaptchasIO client.
|
||||
/// </summary>
|
||||
/// <param name="apiKey">The CaptchasIO API key</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public CaptchasIO(string apiKey, int timeout) : base(apiKey, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
var response = client.DownloadString($"http://api.captchas.io/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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
var response = client.DownloadString($"http://api.captchas.io/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;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
response = client.DownloadString($"http://api.captchas.io/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);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.request;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
var response = client.UploadString("http://api.captchas.io.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;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
response = client.DownloadString($"http://api.captchas.io/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);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.request;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable 0414
|
||||
#pragma warning disable 0649
|
||||
struct GenericResponse
|
||||
{
|
||||
public int? status;
|
||||
public string request;
|
||||
}
|
||||
#pragma warning restore 0414
|
||||
#pragma warning restore 0649
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of http://de-captcher.com/
|
||||
/// </summary>
|
||||
public class DeCaptcher : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a DeCaptcher client.
|
||||
/// </summary>
|
||||
/// <param name="user">The DeCaptcher username</param>
|
||||
/// <param name="pass">The DeCaptcher password</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public DeCaptcher(string user, string pass, int timeout) : base(user, pass, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using (MultipartFormDataContent data = new MultipartFormDataContent())
|
||||
{
|
||||
client.Timeout = new TimeSpan(0, 0, Timeout);
|
||||
data.Add(new StringContent(User), "username");
|
||||
data.Add(new StringContent(Pass), "password");
|
||||
data.Add(new StringContent("balance"), "function");
|
||||
var response = PostSync(client, "http://poster.de-captcher.com/", data);
|
||||
return double.Parse(response, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
using (HttpClient client = new HttpClient())
|
||||
using (MultipartFormDataContent data = new MultipartFormDataContent())
|
||||
{
|
||||
client.Timeout = new TimeSpan(0, 0, Timeout);
|
||||
data.Add(new StringContent(User), "username");
|
||||
data.Add(new StringContent(Pass), "password");
|
||||
data.Add(new StringContent("proxyurl"), "function");
|
||||
data.Add(new StringContent(siteKey), "key");
|
||||
data.Add(new StringContent(siteUrl), "url");
|
||||
var response = PostSync(client, "http://poster.de-captcher.com/", data);
|
||||
try { return response.Split('|')[5]; }
|
||||
catch { throw new Exception(response); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
using(HttpClient client = new HttpClient())
|
||||
using (MultipartFormDataContent data = new MultipartFormDataContent())
|
||||
{
|
||||
client.Timeout = new TimeSpan(0, 0, Timeout);
|
||||
data.Add(new StringContent(User), "username");
|
||||
data.Add(new StringContent(Pass), "password");
|
||||
data.Add(new StringContent("picture2"), "function");
|
||||
data.Add(new ByteArrayContent(GetBytes(bitmap)), "pict");
|
||||
data.Add(new StringContent("0"), "picttype");
|
||||
var response = PostSync(client, "http://poster.de-captcher.com/", data);
|
||||
try { return response.Split('|')[5]; }
|
||||
catch { throw new Exception(response); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,195 @@
|
||||
using Extreme.Net;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of https://www.deathbycaptcha.com/
|
||||
/// </summary>
|
||||
public class DeathByCaptcha : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a DeathByCaptcha client.
|
||||
/// </summary>
|
||||
/// <param name="user">The DeathByCaptcha username</param>
|
||||
/// <param name="pass">The DeathByCaptcha password</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public DeathByCaptcha(string user, string pass, int timeout) : base(user, pass, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.Accept, "application/json");
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
var response = client.UploadString("http://api.dbcapi.me/api/user", $"username={User}&password={Pass}");
|
||||
GetBalanceResponse gbr = JsonConvert.DeserializeObject<GetBalanceResponse>(response);
|
||||
if (gbr.status != 0) throw new Exception("Invalid Credentials");
|
||||
return gbr.balance / 100;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
HttpRequest request = new HttpRequest();
|
||||
request.AddHeader(HttpHeader.Accept, "application/json");
|
||||
var content = new Extreme.Net.MultipartContent(BlockRequest.GenerateMultipartBoundary());
|
||||
content.Add(new Extreme.Net.StringContent(User), "username");
|
||||
content.Add(new Extreme.Net.StringContent(Pass), "password");
|
||||
content.Add(new Extreme.Net.StringContent("4"), "type");
|
||||
content.Add(new Extreme.Net.StringContent(JsonConvert.SerializeObject(new CreateRecaptchaTaskRequest(siteUrl, siteKey))), "token_params");
|
||||
var response = request.Post("http://api.dbcapi.me/api/captcha", content).ToString();
|
||||
var split = response.Split('&');
|
||||
var status = int.Parse(split[0].Split('=')[1]);
|
||||
var id = split[1].Split('=')[1];
|
||||
if (status == 255) throw new Exception(response);
|
||||
TaskId = id;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
HttpRequest gRequest = new HttpRequest();
|
||||
gRequest.AddHeader(HttpHeader.Accept, "application/json");
|
||||
HttpResponse gResponse = gRequest.Get($"http://api.dbcapi.me/api/captcha/{TaskId}");
|
||||
var resp = gResponse.ToString();
|
||||
CreateTaskResponse gtrr = JsonConvert.DeserializeObject<CreateTaskResponse>(resp);
|
||||
if (gtrr == null) continue;
|
||||
if (!gtrr.is_correct) throw new Exception("No answer could be found");
|
||||
if (gtrr.text != "")
|
||||
{
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.text;
|
||||
}
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
// Create task
|
||||
HttpRequest request = new HttpRequest();
|
||||
request.AddHeader(HttpHeader.Accept, "application/json");
|
||||
Extreme.Net.MultipartContent content = new Extreme.Net.MultipartContent(BlockRequest.GenerateMultipartBoundary());
|
||||
content.Add(new Extreme.Net.StringContent(User), "username");
|
||||
content.Add(new Extreme.Net.StringContent(Pass), "password");
|
||||
content.Add(new Extreme.Net.StringContent($"base64:{GetBase64(bitmap, ImageFormat.Jpeg)}"), "captchafile");
|
||||
var response = request.Post("http://api.dbcapi.me/api/captcha", content).ToString();
|
||||
var split = response.Split('&');
|
||||
var status = int.Parse(split[0].Split('=')[1]);
|
||||
var id = split[1].Split('=')[1];
|
||||
if (status == 255) throw new Exception(response);
|
||||
TaskId = id;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
HttpRequest gRequest = new HttpRequest();
|
||||
gRequest.AddHeader(HttpHeader.Accept, "application/json");
|
||||
HttpResponse gResponse = gRequest.Get($"http://api.dbcapi.me/api/captcha/{TaskId}");
|
||||
var resp = gResponse.ToString();
|
||||
CreateTaskResponse gtrr = JsonConvert.DeserializeObject<CreateTaskResponse>(resp);
|
||||
if (gtrr == null) continue;
|
||||
if (!gtrr.is_correct) throw new Exception("No answer could be found");
|
||||
if (gtrr.text != "")
|
||||
{
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.text;
|
||||
}
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
#pragma warning disable 0649
|
||||
#pragma warning disable 0414
|
||||
class GetBalanceResponse
|
||||
{
|
||||
public int status;
|
||||
public double balance;
|
||||
}
|
||||
|
||||
class CreateRecaptchaTaskRequest
|
||||
{
|
||||
public string googlekey;
|
||||
public string pageurl;
|
||||
public CreateRecaptchaTaskRequest(string url, string key) { pageurl = url; googlekey = key; }
|
||||
}
|
||||
|
||||
class CreateCaptchaTaskRequest
|
||||
{
|
||||
public string clientKey;
|
||||
public CaptchaTask task;
|
||||
public CreateCaptchaTaskRequest(string apiKey, string base64) { clientKey = apiKey; task = new CaptchaTask(base64); }
|
||||
}
|
||||
|
||||
class CaptchaTask
|
||||
{
|
||||
public string type = "ImageToTextTask";
|
||||
public string body;
|
||||
public CaptchaTask(string base64) { body = base64; }
|
||||
}
|
||||
|
||||
class CreateTaskResponse
|
||||
{
|
||||
public int captcha;
|
||||
public int status;
|
||||
public bool is_correct;
|
||||
public string text;
|
||||
public string error;
|
||||
}
|
||||
|
||||
class GetTaskResultRequest
|
||||
{
|
||||
public string clientKey;
|
||||
public int taskId;
|
||||
public GetTaskResultRequest(string apiKey, int id) { clientKey = apiKey; taskId = id; }
|
||||
}
|
||||
|
||||
class GetTaskResultCaptchaResponse
|
||||
{
|
||||
public int errorId;
|
||||
public string errorCode;
|
||||
public string status;
|
||||
public CaptchaSolution solution;
|
||||
}
|
||||
|
||||
class GetTaskResultRecaptchaResponse
|
||||
{
|
||||
public int errorId;
|
||||
public string errorCode;
|
||||
public string status;
|
||||
public RecaptchaSolution solution;
|
||||
}
|
||||
|
||||
class RecaptchaSolution
|
||||
{
|
||||
public string gRecaptchaResponse;
|
||||
}
|
||||
|
||||
class CaptchaSolution
|
||||
{
|
||||
public string text;
|
||||
}
|
||||
|
||||
#pragma warning restore 0414
|
||||
#pragma warning restore 0649
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of http://www.imagetyperz.com/
|
||||
/// </summary>
|
||||
public class ImageTyperz : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates an ImageTyperz client.
|
||||
/// </summary>
|
||||
/// <param name="apiKey">The ImageTyperz API key</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public ImageTyperz(string apiKey, int timeout) : base(apiKey, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
|
||||
var res = client.UploadString("http://captchatypers.com/Forms/RequestBalanceToken.ashx", $"token={ApiKey}&action=REQUESTBALANCE");
|
||||
if (res.Contains("ERROR")) throw new Exception(res);
|
||||
return double.Parse(res, CultureInfo.InvariantCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
var res = client.UploadString("http://captchatypers.com/captchaapi/UploadRecaptchaToken.ashx",
|
||||
$"token={ApiKey}&action=UPLOADCAPTCHA&pageurl={siteUrl}&googlekey={siteKey}");
|
||||
if (res.Contains("ERROR")) throw new Exception(res);
|
||||
TaskId = res;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
while (Status == CaptchaStatus.Processing && (DateTime.Now - start).TotalSeconds < Timeout)
|
||||
{
|
||||
Thread.Sleep(5000);
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
res = client.UploadString("http://captchatypers.com/captchaapi/GetRecaptchaTextToken.ashx",
|
||||
$"token={ApiKey}&action=GETTEXT&captchaID={TaskId}");
|
||||
if (res.Contains("NOTDECODED")) continue;
|
||||
if (res.Contains("ERROR")) throw new Exception(res);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return res;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
client.Headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
|
||||
var res = client.UploadString("http://captchatypers.com/Forms/UploadFileAndGetTextNEWToken.ashx",
|
||||
$"token={ApiKey}&action=UPLOADCAPTCHA&chkCase=1&file={WebUtility.UrlEncode(GetBase64(bitmap, ImageFormat.Bmp))}");
|
||||
if (res.Contains("ERROR")) throw new Exception(res);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return res.Split('|')[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of https://www.solverecaptcha.com/
|
||||
/// </summary>
|
||||
public class SolveReCaptcha : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a SolveRecaptcha client.
|
||||
/// </summary>
|
||||
/// <param name="userId">The id of the user</param>
|
||||
/// <param name="apiKey">The SolveRecaptcha API key</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public SolveReCaptcha(string userId, string apiKey, int timeout) : base(userId, apiKey, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
if (Timeout > 0) client.Timeout = Timeout;
|
||||
var response = client.DownloadString($"https://api.solverecaptcha.com/?userid={User}&key={Pass}&sitekey={siteKey}&pageurl={siteUrl}");
|
||||
if (response.Contains("ERROR")) throw new Exception(response);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return response.Split('|')[1];
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
client.Timeout = 3;
|
||||
try
|
||||
{
|
||||
var response = client.DownloadString($"https://api.solverecaptcha.com/?userid={User}&key={Pass}&sitekey=test&pageurl=test");
|
||||
if (response.Contains("ERROR_ACCESS_DENIED")) return 0; // Invalid key
|
||||
}
|
||||
catch { } // Catch the timeout exception, this means it's trying to process a captcha so the key is valid
|
||||
return 999;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Globalization;
|
||||
using System.Net;
|
||||
using System.Threading;
|
||||
|
||||
namespace RuriLib.CaptchaServices
|
||||
{
|
||||
/// <summary>
|
||||
/// Implements the API of https://2captcha.com
|
||||
/// </summary>
|
||||
public class TwoCaptcha : CaptchaService
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a 2Captcha client.
|
||||
/// </summary>
|
||||
/// <param name="apiKey">The 2Captcha API key</param>
|
||||
/// <param name="timeout">The maximum time to wait for the challenge to be solved</param>
|
||||
public TwoCaptcha(string apiKey, int timeout) : base(apiKey, timeout) { }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override double GetBalance()
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveRecaptcha(string siteKey, string siteUrl)
|
||||
{
|
||||
// Create task
|
||||
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;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
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("NOTREADY")) continue;
|
||||
if (gtrr.status == 0) throw new Exception(gtrr.request);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.request;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string SolveCaptcha(Bitmap bitmap)
|
||||
{
|
||||
// Create task
|
||||
using (CWebClient client = new CWebClient())
|
||||
{
|
||||
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;
|
||||
Status = CaptchaStatus.Processing;
|
||||
|
||||
// Check if task has been completed
|
||||
DateTime start = DateTime.Now;
|
||||
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("NOTREADY")) continue;
|
||||
if (gtrr.status == 0) throw new Exception(gtrr.request);
|
||||
Status = CaptchaStatus.Completed;
|
||||
return gtrr.request;
|
||||
}
|
||||
throw new TimeoutException();
|
||||
}
|
||||
}
|
||||
|
||||
#pragma warning disable 0414
|
||||
#pragma warning disable 0649
|
||||
class GenericResponse
|
||||
{
|
||||
public int status;
|
||||
public string request;
|
||||
}
|
||||
#pragma warning restore 0414
|
||||
#pragma warning restore 0649
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user