/// <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; }
public async Task <VodUploadResponse> Upload(string region, VodUploadRequest req) { CheckRequest(region, req); TencentCloud.Common.Credential cred = new TencentCloud.Common.Credential { SecretId = SecretId, SecretKey = SecretKey }; VodClient vodClient = new VodClient(cred, region); ApplyUploadResponse applyResp = await DoApplyRequest(vodClient, req); //Console.WriteLine(AbstractModel.ToJsonString(applyResp)); await DoUploadAction(applyResp, req); CommitUploadResponse commitResp = await DoCommitRequest(vodClient, applyResp); //Console.WriteLine(AbstractModel.ToJsonString(commitResp)); VodUploadResponse rsp = AbstractModel.FromJsonString <VodUploadResponse>(AbstractModel.ToJsonString(commitResp)); return(rsp); }
/// <summary> /// DoCdnAction /// </summary> /// <typeparam name="T"></typeparam> /// <param name="client"></param> /// <param name="req"></param> /// <param name="json"></param> private static void DoCdnAction<T>(out CdnClient client, out T req, string json) { DoTencentCloudAction("cdn", out Credential cred, out ClientProfile clientProfile); client = new CdnClient(cred, "", clientProfile); req = AbstractModel.FromJsonString<T>(json); }
public string GetResult() { client = new TmtClient(cred, "ap-guangzhou-open", clientProfile); string strParams = "{\"SourceText\":\"" + SourceText + "\",\"Source\":\"" + Source + "\",\"Target\":\"" + Target + "\",\"ProjectId\":0}"; req = AbstractModel.FromJsonString <TextTranslateRequest>(strParams); TextTranslateResponse resp = client.TextTranslate(req).Result; return(AbstractModel.ToJsonString(resp)); }
/// <summary> /// DoCdnAction /// </summary> /// <typeparam name="T"></typeparam> /// <param name="client"></param> /// <param name="req"></param> /// <param name="json"></param> private static void DoCdnAction <T>(out CdnClient client, out T req, string json) { var cred = new Credential { SecretId = AppSettings.TencentCloud.SecretId, SecretKey = AppSettings.TencentCloud.SecretKey }; var httpProfile = new HttpProfile { Endpoint = "cdn.tencentcloudapi.com" }; var clientProfile = new ClientProfile { HttpProfile = httpProfile }; client = new CdnClient(cred, "", clientProfile); req = AbstractModel.FromJsonString <T>(json); }
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); }