public CaptchaResponse Solve(ReCaptchaRequest captcha) { try { if (!ConfigRefresh()) { return(new CaptchaResponse(CaptchaStatus.Failed, "Failed to load configuration!")); } } catch (Exception ex) { Logger.Error("Failed to load configuration!", ex); return(new CaptchaResponse(CaptchaStatus.Failed, "Failed to load configuration!")); } var requestQueueId = new RestRequest("in.php", Method.GET); requestQueueId.AddParameter("soft_id", 2370); requestQueueId.AddParameter("googlekey", captcha.SiteKey); requestQueueId.AddParameter("method", "userrecaptcha"); requestQueueId.AddParameter("pageurl", captcha.Url); AddProxy(requestQueueId, captcha.Proxy); return(GetSolution(requestQueueId, true)); }
private static IEnumerable <KeyValuePair <string?, string?> > Encode(ReCaptchaRequest request) { var result = new List <KeyValuePair <string?, string?> > { new(nameof(request.Secret).ToLower(), request.Secret), new(nameof(request.Response).ToLower(), request.Response) }; if (request.RemoteIp != null) { result.Add(new KeyValuePair <string?, string?>(nameof(request.RemoteIp).ToLower(), request.RemoteIp)); } return(result); }
public async Task <bool> Validate(string clientSecret, string?clientIp) { if (!await _parameterManager.GetValue <bool>(ParameterTypes.ContactEmailRecaptchaEnabled)) { return(false); } var reCaptchaRequest = new ReCaptchaRequest(await _parameterManager.GetValue <string>(ParameterTypes.ContactEmailRecaptchaServerKey), clientSecret, clientIp); var httpResponse = await _httpClient.PostAsync(PostAddress, new FormUrlEncodedContent(Encode(reCaptchaRequest))); var reCaptchaResponse = JsonSerializer.Deserialize <ReCaptchaResponse>(await httpResponse.Content.ReadAsStringAsync(), new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }); return(httpResponse.IsSuccessStatusCode && reCaptchaResponse.Success); }
public CaptchaResponse Solve(ReCaptchaRequest request) => ReCaptcha?.Solve(request);
public CaptchaResponse Solve(ReCaptchaRequest request) { if (!Config.Load()) { Config.Save(); return(new CaptchaResponse(SACModuleBase.Enums.Captcha.CaptchaStatus.CannotSolve, "Config load error")); } var _params = new Dictionary <string, object>() { { "key", Config?.Running?.ApiKey ?? "" }, { "soft_id", "2370" }, { "json", "0" }, { "method", "userrecaptcha" }, { "pageurl", request.Url }, { "googlekey", request.SiteKey } }; var _captchaIdResponse = Misc.TwoCaptcha("in.php", _params); var _captchaStatus = _captchaIdResponse?.FirstOrDefault()?.ToUpper() ?? "UNKNOWN"; switch (_captchaStatus) { case "OK": break; case "ERROR_NO_SLOT_AVAILABLE": Thread.Sleep(6000); return(new CaptchaResponse(SACModuleBase.Enums.Captcha.CaptchaStatus.RetryAvailable, _captchaStatus, null)); default: return(new CaptchaResponse(SACModuleBase.Enums.Captcha.CaptchaStatus.Failed, _captchaStatus, null)); } var _captchaId = _captchaIdResponse.ElementAt(1); Thread.Sleep(TimeSpan.FromSeconds(20)); var solution = string.Empty; for (int i = 0; i < 3; i++) { var _captchaResponse = Misc.TwoCaptcha("res.php", new Dictionary <string, object>() { { "key", Config?.Running?.ApiKey ?? "" }, { "action", "get" }, { "id", _captchaId }, { "json", "0" }, }); var _status = _captchaResponse?.FirstOrDefault()?.ToUpper() ?? "UNKNOWN"; switch (_status) { case "OK": return(new CaptchaResponse(_captchaResponse.ElementAt(1), _captchaId)); case "CAPCHA_NOT_READY": case "ERROR_NO_SLOT_AVAILABLE": Thread.Sleep(6000); continue; default: return(new CaptchaResponse(SACModuleBase.Enums.Captcha.CaptchaStatus.RetryAvailable, _status)); } } return(new CaptchaResponse(SACModuleBase.Enums.Captcha.CaptchaStatus.CannotSolve, "Something went wrong...")); }