|
@@ -4,6 +4,7 @@ using OASystem.Domain;
|
|
|
using OASystem.Domain.Dtos.SmallFun;
|
|
|
using OASystem.Domain.ViewModels.JuHeExchangeRate;
|
|
|
using OASystem.Domain.ViewModels.SmallFun;
|
|
|
+using StackExchange.Redis;
|
|
|
using System.DirectoryServices.Protocols;
|
|
|
using System.Net.Http;
|
|
|
using System.Net.Http.Json;
|
|
@@ -338,8 +339,10 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
|
|
|
#region 文本翻译
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
+
|
|
|
+
|
|
|
|
|
|
public async Task<JuHeAPIResult> GetTextTranslateAsync(string source,string trans_type = "zh2en")
|
|
|
{
|
|
@@ -350,78 +353,43 @@ namespace OASystem.API.OAMethodLib.JuHeAPI
|
|
|
#region 请求接口并存入缓存
|
|
|
string url = string.Format("/finance/exchange/rmbquot");
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- var exchangeReq = await _httpClient
|
|
|
- .PostAsync(url,
|
|
|
- new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
|
|
|
- {
|
|
|
+ var exchangeReq = await _httpClient
|
|
|
+ .PostAsync(url,
|
|
|
+ new FormUrlEncodedContent(new List<KeyValuePair<string, string>>()
|
|
|
+ {
|
|
|
new KeyValuePair<string, string>("key",_appKey),
|
|
|
- new KeyValuePair<string, string>("source",source),
|
|
|
- new KeyValuePair<string, string>("trans_type",trans_type)
|
|
|
-
|
|
|
- }));
|
|
|
- if (exchangeReq.IsSuccessStatusCode)
|
|
|
- {
|
|
|
- var stringResponse = await exchangeReq.Content.ReadAsStringAsync();
|
|
|
-
|
|
|
- result = System.Text.Json.JsonSerializer.Deserialize<JuHeAPIResult>(stringResponse,
|
|
|
- new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
|
-
|
|
|
- if (result.Resultcode == "200")
|
|
|
- {
|
|
|
- List<ExchangeRateModel> rateList = new List<ExchangeRateModel>();
|
|
|
-
|
|
|
- #region 处理数据类型
|
|
|
- JArray jar = JArray.Parse(result.Result.ToJson());
|
|
|
- for (int i = 0; i < jar.Count; i++)
|
|
|
- {
|
|
|
- JObject j = JObject.Parse(jar[i].ToString());
|
|
|
- for (int x = 1; x < j.Count + 1; x++)
|
|
|
- {
|
|
|
- string rateName = "data" + x;
|
|
|
- string rateDataStr = j[rateName].ToString();
|
|
|
- if (!string.IsNullOrEmpty(rateDataStr))
|
|
|
- {
|
|
|
- ExchangeRateModel exchangeRate = JsonConvert.DeserializeObject<ExchangeRateModel>(rateDataStr);
|
|
|
- rateList.Add(exchangeRate);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- #endregion
|
|
|
+ new KeyValuePair<string, string>("source",source),
|
|
|
+ new KeyValuePair<string, string>("trans_type",trans_type)
|
|
|
|
|
|
+ }));
|
|
|
+ if (exchangeReq.IsSuccessStatusCode)
|
|
|
+ {
|
|
|
+ var stringResponse = await exchangeReq.Content.ReadAsStringAsync();
|
|
|
|
|
|
- TimeSpan ts = DateTime.Now.AddMinutes(120) - DateTime.Now;
|
|
|
- await RedisRepository
|
|
|
- .RedisFactory
|
|
|
- .CreateRedisRepository()
|
|
|
- .StringSetAsync<string>("JuHeApiExchangeRate", rateList.ToJson(), ts);
|
|
|
-
|
|
|
- result.Result = rateList;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- result.Reason = string.Format("聚合APIError[Error_Code:{0} Resultcode:{1} Msg:{2}]",
|
|
|
- result.Error_code, result.Resultcode, result.Result);
|
|
|
- }
|
|
|
+ result = System.Text.Json.JsonSerializer.Deserialize<JuHeAPIResult>(stringResponse,
|
|
|
+ new JsonSerializerOptions() { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
|
|
|
|
|
|
+ if (result.Resultcode == "200")
|
|
|
+ {
|
|
|
+ string resStr = (string)result.Result.GetType().GetProperty("res").GetValue(result.Result, null);
|
|
|
+ result.Result = resStr;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- result.Reason = "汇率接口请求失败!";
|
|
|
+ result.Reason = string.Format("聚合APIError[Error_Code:{0} Resultcode:{1} Msg:{2}]",
|
|
|
+ result.Error_code, result.Resultcode, result.Result);
|
|
|
}
|
|
|
}
|
|
|
- catch (Exception ex)
|
|
|
+ else
|
|
|
{
|
|
|
- result.Reason = ex.Message;
|
|
|
+ result.Reason = "汇率接口请求失败!";
|
|
|
}
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
-
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
#endregion
|
|
|
}
|
|
|
}
|