/// <summary> /// 验证码校验 /// </summary> /// <param name="ticket"></param> /// <param name="randstr"></param> /// <returns></returns> public async Task<ServiceResult<DescribeCaptchaResultResponse>> CaptchaAsync(string ticket, string randstr) { var result = new ServiceResult<DescribeCaptchaResultResponse>(); var ip = _httpContextAccessor.HttpContext.Request.GetClientIp(); var parameters = new { CaptchaType = "9", UserIp = ip, Ticket = ticket, Randstr = randstr, CaptchaAppId = AppSettings.TencentCloud.Captcha.APIKey, AppSecretKey = AppSettings.TencentCloud.Captcha.SecretKey, }; DoTencentCloudAction("captcha", out Credential cred, out ClientProfile clientProfile); var client = new CaptchaClient(cred, "", clientProfile); var req = AbstractModel.FromJsonString<DescribeCaptchaResultRequest>(parameters.ToJson()); var resp = await client.DescribeCaptchaResult(req); if (resp.CaptchaCode != 1) result.IsFailed(resp.CaptchaMsg); else result.IsSuccess(resp); return result; }
async Task <string> decisionRecaptch() { var captcha = new CaptchaClient("b4fe7c5c6917758f6e0ebd99babc00b7"); IJavaScriptExecutor js = (IJavaScriptExecutor)driver; var siteKey = (string)js.ExecuteScript("return $(\".g-recaptcha\").attr(\"data-sitekey\")"); var captchaResult = await captcha.ReCaptchaAsync(siteKey, driver.Url); return(captchaResult.request); }
public async Task <Response <DescribeCaptchaResultResponse> > Captcha(string ticket, string randstr) { var response = new Response <DescribeCaptchaResultResponse>(); var ip = HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (string.IsNullOrEmpty(ip)) { ip = Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); } var parameters = new { CaptchaType = "9", UserIp = ip, Ticket = ticket, Randstr = randstr, CaptchaAppId = AppSettings.TencentCloud.Captcha.APIKey, AppSecretKey = AppSettings.TencentCloud.Captcha.SecretKey, }; DoTencentCloudAction("captcha", out Credential cred, out ClientProfile clientProfile); var client = new CaptchaClient(cred, "", clientProfile); var req = AbstractModel.FromJsonString <DescribeCaptchaResultRequest>(parameters.SerializeToJson()); var resp = await client.DescribeCaptchaResult(req); if (resp.CaptchaCode != 1) { response.Msg = resp.CaptchaMsg; } else { response.Result = resp; } return(response); }
public async Task <Response <DescribeCaptchaResultResponse> > Captcha(string ticket, string randstr) { var response = new Response <DescribeCaptchaResultResponse>(); var ip = HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault(); if (string.IsNullOrEmpty(ip)) { ip = Request.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); } var dic = new Dictionary <string, string> { { "CaptchaType", "9" }, { "UserIp", ip }, { "Ticket", ticket }, { "Randstr", randstr }, { "CaptchaAppId", AppSettings.TencentCloud.Captcha.APIKey }, { "AppSecretKey", AppSettings.TencentCloud.Captcha.SecretKey } }; DoTencentCloudAction("captcha", out Credential cred, out ClientProfile clientProfile); var client = new CaptchaClient(cred, "", clientProfile); var req = AbstractModel.FromJsonString <DescribeCaptchaResultRequest>(dic.SerializeToJson()); var resp = await client.DescribeCaptchaResult(req); if (resp.CaptchaCode != 1) { response.Msg = resp.CaptchaMsg; } else { response.Result = resp; } return(response); }