Dun.Jason преди 1 година
родител
ревизия
982ae6ca73
променени са 2 файла, в които са добавени 31 реда и са изтрити 0 реда
  1. 9 0
      src/Hotline/Permissions/EPermission.cs
  2. 22 0
      src/Tr.Sdk/TrClient.cs

+ 9 - 0
src/Hotline/Permissions/EPermission.cs

@@ -16,6 +16,15 @@ namespace Hotline.Permissions
         [Display(GroupName = "首页", Name = "首页", Description = "首页")]
         Home = 000000,
 
+
+        #region 业务待办
+
+
+
+        #endregion
+
+
+
         #region 系统管理相关接口(100)
 
         /// <summary>

+ 22 - 0
src/Tr.Sdk/TrClient.cs

@@ -8,9 +8,15 @@ namespace Tr.Sdk;
 public class TrClient : ITrClient, IDisposable
 {
     private readonly RestClient _client;
+    private readonly string _baseUrl;
+    private readonly string _apiKey;
+    private readonly string _apiSecret;
 
     public TrClient(string baseUrl, string apiKey, string apiSecret)
     {
+        _baseUrl = baseUrl;
+        _apiKey = apiKey;
+        _apiSecret = apiSecret;
         var options = new RestClientOptions(baseUrl)
         {
             Authenticator = new TrAuthenticator(baseUrl, apiKey, apiSecret)
@@ -36,7 +42,23 @@ public class TrClient : ITrClient, IDisposable
         {
             var response = await _client.ExecuteAsync<TResponse>(req, cancellationToken);
             if (!response?.IsSuccessful ?? false)
+            {
+                if(response.StatusCode ==  System.Net.HttpStatusCode.Unauthorized)
+                {
+                    //TODO 清除Token
+                    var options = new RestClientOptions(_baseUrl)
+                    {
+                        Authenticator = new TrAuthenticator(_baseUrl, _apiKey, _apiSecret)
+                    };
+                    RestClient _newClient = new RestClient(options);
+                    response = await _newClient.ExecuteAsync<TResponse>(req, cancellationToken);
+                    if (!response?.IsSuccessful ?? false)
+                        throw new HttpRequestException($"请求呼叫中心服务失败, HttpCode: {response.StatusCode}, Error: {response.ErrorMessage}");
+
+                    return response.Data;
+                }
                 throw new HttpRequestException($"请求呼叫中心服务失败, HttpCode: {response.StatusCode}, Error: {response.ErrorMessage}");
+            }
 
             return response.Data;
         }