using Newtonsoft.Json; using System; using System.Drawing; using System.Drawing.Imaging; using System.Globalization; using System.Net; using System.Threading; namespace RuriLib.CaptchaServices { /// /// Implements the API of https://www.solverecaptcha.com/ /// public class SolveReCaptcha : CaptchaService { /// /// Creates a SolveRecaptcha client. /// /// The id of the user /// The SolveRecaptcha API key /// The maximum time to wait for the challenge to be solved public SolveReCaptcha(string userId, string apiKey, int timeout) : base(userId, apiKey, timeout) { } /// 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]; } } /// 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; } } } }