|
@@ -0,0 +1,75 @@
|
|
|
+//using System.Net.Http.Json;
|
|
|
+//using System.Text.Json;
|
|
|
+
|
|
|
+//namespace Tr.Sdk;
|
|
|
+
|
|
|
+//public partial class TrClient : ITrClient
|
|
|
+//{
|
|
|
+// private readonly IHttpClientFactory _httpClientFactory;
|
|
|
+
|
|
|
+// public TrClient(IHttpClientFactory httpClientFactory)
|
|
|
+// {
|
|
|
+// _httpClientFactory = httpClientFactory;
|
|
|
+// }
|
|
|
+
|
|
|
+// /// <summary>
|
|
|
+// /// 执行操作呼叫中心请求
|
|
|
+// /// </summary>
|
|
|
+// /// <typeparam name="TRequest"></typeparam>
|
|
|
+// /// <typeparam name="TResponse"></typeparam>
|
|
|
+// /// <param name="request"></param>
|
|
|
+// /// <param name="cancellationToken"></param>
|
|
|
+// /// <returns></returns>
|
|
|
+// public async Task<TResponse?> ExecuteAsync<TRequest, TResponse>(TRequest request, CancellationToken cancellationToken) where TRequest : ITrRequest
|
|
|
+// {
|
|
|
+// //var httpClient = _httpClientFactory.CreateClient(Defaults.ServiceName);
|
|
|
+// //var token = await _tokenManager.GetTokenAsync(cancellationToken);
|
|
|
+// //httpClient.DefaultRequestHeaders.Add("X-Auth-Token", token);
|
|
|
+// //try
|
|
|
+// //{
|
|
|
+// // if (request.Method == HttpMethod.Get)
|
|
|
+// // {
|
|
|
+// // return await httpClient.GetFromJsonAsync<TResponse>(request.Url, cancellationToken);
|
|
|
+// // }
|
|
|
+// // else if (request.Method == HttpMethod.Post)
|
|
|
+// // {
|
|
|
+// // using var content = new FormUrlEncodedContent
|
|
|
+// // await httpClient.PostAsync(request.Url, new FormUrlEncodedContent(), cancellationToken);
|
|
|
+// // }
|
|
|
+// // else
|
|
|
+// // {
|
|
|
+// // throw new ArgumentOutOfRangeException();
|
|
|
+// // }
|
|
|
+
|
|
|
+// // var rsp = await httpClient.PostAsJsonAsync(request.Url, request, cancellationToken: cancellationToken);
|
|
|
+// // if (!rsp.IsSuccessStatusCode)
|
|
|
+// // throw new HttpRequestException("请求呼叫中心服务失败");
|
|
|
+// // var response = await rsp.Content.ReadFromJsonAsync<TResponse>(new JsonSerializerOptions
|
|
|
+// // {
|
|
|
+// // PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
|
+// // }, cancellationToken);
|
|
|
+// // if (response?.Code == 401)
|
|
|
+// // {
|
|
|
+// // await _tokenManager.RefreshTokenAsync(cancellationToken);
|
|
|
+// // response = await rsp.Content.ReadFromJsonAsync<TResponse>(new JsonSerializerOptions
|
|
|
+// // {
|
|
|
+// // PropertyNamingPolicy = JsonNamingPolicy.CamelCase
|
|
|
+// // }, cancellationToken);
|
|
|
+// // }
|
|
|
+// // if (response?.Code != 200)
|
|
|
+// // throw new HttpRequestException(response?.Msg);
|
|
|
+// // return response;
|
|
|
+// //}
|
|
|
+// //catch (Exception)
|
|
|
+// //{
|
|
|
+// // throw;
|
|
|
+// //}
|
|
|
+
|
|
|
+// throw new NotImplementedException();
|
|
|
+// }
|
|
|
+
|
|
|
+// public async Task<string> GetTokenAsync(TokenRequest request, CancellationToken cancellationToken)
|
|
|
+// {
|
|
|
+// throw new NotImplementedException();
|
|
|
+// }
|
|
|
+//}
|