|
@@ -19,6 +19,7 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
public class JuHeApiService: IJuHeApiService
|
|
public class JuHeApiService: IJuHeApiService
|
|
{
|
|
{
|
|
private readonly HttpClient _httpClient;
|
|
private readonly HttpClient _httpClient;
|
|
|
|
+ private readonly HttpClient _httpClientTranslate;
|
|
private readonly string _appKey = "0f5429e9fbb8637c0ff3f14bbb42c732";
|
|
private readonly string _appKey = "0f5429e9fbb8637c0ff3f14bbb42c732";
|
|
private readonly string _appkey_textTranslate = "59db9edbac297e30695973aa1d856391";
|
|
private readonly string _appkey_textTranslate = "59db9edbac297e30695973aa1d856391";
|
|
|
|
|
|
@@ -28,7 +29,8 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
|
|
|
public JuHeApiService(IHttpClientFactory clientFactory)
|
|
public JuHeApiService(IHttpClientFactory clientFactory)
|
|
{
|
|
{
|
|
- _httpClient = clientFactory.CreateClient("PublicJuHeApi"); ;
|
|
+ _httpClient = clientFactory.CreateClient("PublicJuHeApi");
|
|
|
|
+ _httpClientTranslate = clientFactory.CreateClient("PublicJuHeTranslateApi");
|
|
}
|
|
}
|
|
|
|
|
|
#region 汇率
|
|
#region 汇率
|
|
@@ -344,20 +346,21 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- 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 = "接口维护" };
|
|
var result = new JuHeAPIResult() { Resultcode = "10020", Reason = "接口维护" };
|
|
|
|
|
|
|
|
|
|
-
|
|
+ #region 请求接口
|
|
- #region 请求接口并存入缓存
|
|
+ string url = string.Format($"/translate/query");
|
|
- string url = string.Format("/finance/exchange/rmbquot");
|
|
|
|
|
|
|
|
- var exchangeReq = await _httpClient
|
|
+ var exchangeReq = await _httpClientTranslate
|
|
.PostAsync(url,
|
|
.PostAsync(url,
|
|
new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
|
|
new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
|
|
{
|
|
{
|
|
- new KeyValuePair<string, string>("key",_appKey),
|
|
+ new KeyValuePair<string, string>("key",_appkey_textTranslate),
|
|
new KeyValuePair<string, string>("source",source),
|
|
new KeyValuePair<string, string>("source",source),
|
|
new KeyValuePair<string, string>("trans_type",trans_type)
|
|
new KeyValuePair<string, string>("trans_type",trans_type)
|
|
|
|
|
|
@@ -366,18 +369,17 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
{
|
|
{
|
|
var stringResponse = await exchangeReq.Content.ReadAsStringAsync();
|
|
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 });
|
|
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);
|
|
+ res = result1.result.data.res;
|
|
- result.Result = resStr;
|
|
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- result.Reason = string.Format("聚合APIError[Error_Code:{0} Resultcode:{1} Msg:{2}]",
|
|
+ res = string.Format("聚合APIError[Error_Code:{0} Resultcode:{1} Msg:{2}]",
|
|
- result.Error_code, result.Resultcode, result.Result);
|
|
+ result1.error_code, result1.reason, result1.result);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
@@ -387,7 +389,7 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
- return result;
|
|
+ return res;
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
#endregion
|