|
@@ -19,6 +19,7 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
public class JuHeApiService: IJuHeApiService
|
|
|
{
|
|
|
private readonly HttpClient _httpClient;
|
|
|
+ private readonly HttpClient _httpClientTranslate;
|
|
|
private readonly string _appKey = "0f5429e9fbb8637c0ff3f14bbb42c732"; //配置您申请的appkey
|
|
|
private readonly string _appkey_textTranslate = "59db9edbac297e30695973aa1d856391"; //文本翻译 appkey
|
|
|
|
|
@@ -28,7 +29,8 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
/// <param name="clientFactory"></param>
|
|
|
public JuHeApiService(IHttpClientFactory clientFactory)
|
|
|
{
|
|
|
- _httpClient = clientFactory.CreateClient("PublicJuHeApi"); ;
|
|
|
+ _httpClient = clientFactory.CreateClient("PublicJuHeApi");
|
|
|
+ _httpClientTranslate = clientFactory.CreateClient("PublicJuHeTranslateApi");
|
|
|
}
|
|
|
|
|
|
#region 汇率
|
|
@@ -344,20 +346,21 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
/// <param name="source">原文,数据类型为字符串,也可为数组(元素必须为字符串类型);每次请求的字符串长度之和尽量不要超过 </param>
|
|
|
/// <param name="trans_type">翻译方向:en2zh(英文-中文),zh2en(中文-英文),ja2zh(日文-中文),zh2ja(中文-日文),ko2zh(韩文-中文),zh2ko(中文-韩文)</param>
|
|
|
/// <returns></returns>
|
|
|
- public async Task<JuHeAPIResult> GetTextTranslateAsync(string source,string trans_type = "zh2en")
|
|
|
+ public async Task<string> GetTextTranslateAsync(string source,string trans_type = "zh2en")
|
|
|
{
|
|
|
+
|
|
|
+ string res = "";
|
|
|
var result = new JuHeAPIResult() { Resultcode = "10020", Reason = "接口维护" };
|
|
|
|
|
|
|
|
|
-
|
|
|
- #region 请求接口并存入缓存
|
|
|
- string url = string.Format("/finance/exchange/rmbquot");
|
|
|
+ #region 请求接口
|
|
|
+ string url = string.Format($"/translate/query");
|
|
|
|
|
|
- var exchangeReq = await _httpClient
|
|
|
+ var exchangeReq = await _httpClientTranslate
|
|
|
.PostAsync(url,
|
|
|
new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
|
|
|
{
|
|
|
- new KeyValuePair<string, string>("key",_appKey),//你申请的key
|
|
|
+ new KeyValuePair<string, string>("key",_appkey_textTranslate),//你申请的key
|
|
|
new KeyValuePair<string, string>("source",source),
|
|
|
new KeyValuePair<string, string>("trans_type",trans_type)
|
|
|
|
|
@@ -366,18 +369,17 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
{
|
|
|
var stringResponse = await exchangeReq.Content.ReadAsStringAsync();
|
|
|
|
|
|
- result = System.Text.Json.JsonSerializer.Deserialize<JuHeAPIResult>(stringResponse,
|
|
|
+ JuHeTransResult result1 = System.Text.Json.JsonSerializer.Deserialize<JuHeTransResult>(stringResponse,
|
|
|
new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
|
|
|
|
- if (result.Resultcode == "200")
|
|
|
+ if (result1.error_code == 0)
|
|
|
{
|
|
|
- string resStr = (string)result.Result.GetType().GetProperty("res").GetValue(result.Result, null);
|
|
|
- result.Result = resStr;
|
|
|
+ res = result1.result.data.res;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- result.Reason = string.Format("聚合APIError[Error_Code:{0} Resultcode:{1} Msg:{2}]",
|
|
|
- result.Error_code, result.Resultcode, result.Result);
|
|
|
+ res = string.Format("聚合APIError[Error_Code:{0} Resultcode:{1} Msg:{2}]",
|
|
|
+ result1.error_code, result1.reason, result1.result);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
@@ -387,7 +389,7 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
- return result;
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
#endregion
|