using OASystem.Domain.ViewModels.JuHeExchangeRate;
using System.Net.Http;
using System.Net.Http.Json;
using Ubiety.Dns.Core;
namespace OASystem.API.OAMethodLib.JuHeAPI
{
///
/// 聚合Api 服务
///
public class JuHeApiService: IJuHeApiService
{
private readonly HttpClient _httpClient;
private readonly string _appKey = "0f5429e9fbb8637c0ff3f14bbb42c732"; //配置您申请的appkey
///
/// 初始化
///
///
public JuHeApiService(HttpClient httpClient)
{
_httpClient = httpClient;
_httpClient.BaseAddress = new Uri("http://web.juhe.cn:8080");
}
///
/// 汇率转换
///
///
///
public async Task GetExchangeRateAsync()
{
string url = string.Format("/finance/exchange/rmbquot");
var parameters2 = new Dictionary();
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);
}
}
}