private static string GetProxyUrl(TranslateBaiDuProxyParam param) { if (string.IsNullOrEmpty(_appid) || string.IsNullOrEmpty(_salt) || string.IsNullOrEmpty(_url)) { throw new Exception("请在webconfig中 设置百度翻译参数代理 Appid,Salt,Sign,TranslateProxyUrl"); } var sign = $"{_appid}{param.Text}{_salt}12345678".GetMd5Str32(); return($"{_url}?{param.ToString()}&appid={_appid}&salt={_salt}&sign={sign}"); }
public static IEnumerable <TranslateBaiDuProxyResult> Translate(TranslateBaiDuProxyParam param) { using (var client = new HttpClient()) { var httpParam = new HttpParam() { IsUseBase = false, Method = HttpMethod.GET, Content = null, Url = GetProxyUrl(param) }; var result = HttpRequest.Send(httpParam, httpClient: client).DeserializeObject <JObject>(); return(result["trans_result"]?.ToObject <IEnumerable <TranslateBaiDuProxyResult> >()); } }