12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using OASystem.Domain.ViewModels.JuHeExchangeRate;
- using System.Net.Http;
- using System.Net.Http.Json;
- using Ubiety.Dns.Core;
- namespace OASystem.API.OAMethodLib.JuHeAPI
- {
- /// <summary>
- /// 聚合Api 服务
- /// </summary>
- public class JuHeApiService: IJuHeApiService
- {
- private readonly HttpClient _httpClient;
- private readonly string _appKey = "0f5429e9fbb8637c0ff3f14bbb42c732"; //配置您申请的appkey
- /// <summary>
- /// 初始化
- /// </summary>
- /// <param name="httpClient"></param>
- public JuHeApiService(HttpClient httpClient)
- {
- _httpClient = httpClient;
- _httpClient.BaseAddress = new Uri("http://web.juhe.cn:8080");
- }
- /// <summary>
- /// 汇率转换
- /// </summary>
- /// <returns></returns>
- /// <exception cref="NotImplementedException"></exception>
- public async Task<string> GetExchangeRateAsync()
- {
- string url = string.Format("/finance/exchange/rmbquot");
- var parameters2 = new Dictionary<string, string>();
- parameters2.Add("key", _appKey);//你申请的key
- parameters2.Add("type", "0"); //两种格式(0或者1,默认为0)
- parameters2.Add("bank", "3"); //(0:工商银行,1:招商银行,2:建设银行,3:中国银行,4:交通银行,5:农业银行,默认为:0)
- var httpContent = new StringContent(JsonConvert.SerializeObject(parameters2), Encoding.UTF8, "application/json");
- var exchangeReq = await _httpClient.PostAsync(url, httpContent);
- if (exchangeReq.IsSuccessStatusCode)
- {
- var stringResponse = await exchangeReq.Content.ReadAsStringAsync();
- }
- else {
-
- }
- throw new HttpRequestException(exchangeReq.ReasonPhrase);
- }
- }
- }
|