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 { /// /// Implements the API of http://de-captcher.com/ /// public class DeCaptcher : CaptchaService { /// /// Creates a DeCaptcher client. /// /// The DeCaptcher username /// The DeCaptcher password /// The maximum time to wait for the challenge to be solved public DeCaptcher(string user, string pass, int timeout) : base(user, pass, timeout) { } /// public override double GetBalance() { using (HttpClient client = new HttpClient()) using (MultipartFormDataContent data = new MultipartFormDataContent()) { client.Timeout = TimeSpan.FromSeconds(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); } } /// public override string SolveRecaptcha(string siteKey, string siteUrl) { using (HttpClient client = new HttpClient()) using (MultipartFormDataContent data = new MultipartFormDataContent()) { client.Timeout = TimeSpan.FromSeconds(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); } } } /// public override string SolveCaptcha(Bitmap bitmap) { using(HttpClient client = new HttpClient()) using (MultipartFormDataContent data = new MultipartFormDataContent()) { client.Timeout = TimeSpan.FromSeconds(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); } } } } }