diff --git a/Communications/SimApiBaseResponse.cs b/Communications/SimApiBaseResponse.cs
index f55b7d7..6c48fd6 100644
--- a/Communications/SimApiBaseResponse.cs
+++ b/Communications/SimApiBaseResponse.cs
@@ -46,23 +46,15 @@ public class SimApiBaseResponse(int code = 200, string message = "成功")
}
///
-/// 动态内容分页
+/// 分页内容返回
///
///
-public class SimApiBasePageResponse() : SimApiBaseResponse
+public class PageResponse
{
public T? List { get; set; }
public int Page { get; set; } = 1;
public int Count { get; set; } = 20;
public int Total { get; set; }
-
- public SimApiBasePageResponse(T list, int page, int count, int total) : this()
- {
- List = list;
- Page = page;
- Count = count;
- Total = total;
- }
}
///
diff --git a/Helpers/SimApiHttpClient.cs b/Helpers/SimApiHttpClient.cs
index 2ec31d1..9092520 100644
--- a/Helpers/SimApiHttpClient.cs
+++ b/Helpers/SimApiHttpClient.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Net.Http;
using System.Net.Http.Json;
using SimApi.Communications;
+using SimApi.Exceptions;
namespace SimApi.Helpers;
@@ -37,9 +38,7 @@ public class SimApiHttpClient(string? appId, string appKey)
.Aggregate(path, (current, q) => current + $"&{q.Key}={q.Value}");
}
- var http = new HttpClient();
- var resp = http.PostAsJsonAsync(path, body).Result;
- return resp.Content.ReadFromJsonAsync().Result;
+ return Query(path, body);
}
public T? AesQuery(string url, object body)
@@ -54,9 +53,7 @@ public class SimApiHttpClient(string? appId, string appKey)
{
Data = SimApiAesUtil.Encrypt(SimApiUtil.Json(body), appKey)
};
- var http = new HttpClient();
- var resp = http.PostAsJsonAsync(url, req).Result;
- return resp.Content.ReadFromJsonAsync().Result;
+ return Query(url, req);
}
public T? AesSignQuery(string url, object body, Dictionary? queries = null)
@@ -67,4 +64,17 @@ public class SimApiHttpClient(string? appId, string appKey)
};
return SignQuery(url, req, queries);
}
+
+ private T? Query(string url, object? req)
+ {
+ var http = new HttpClient();
+ var resp = http.PostAsJsonAsync(url, req).Result;
+ var res = resp.Content.ReadFromJsonAsync>().Result;
+ if (res == null)
+ {
+ throw new SimApiException(500, "请求发生错误");
+ }
+
+ return res.Code != 200 ? throw new SimApiException(res.Code, res.Message) : res.Data;
+ }
}
\ No newline at end of file