Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5eb7fe081 | ||
|
|
b04a7c86d7 | ||
|
|
8759b593db | ||
|
|
5a46a026a7 |
@@ -10,11 +10,11 @@ jobs:
|
|||||||
name: Publish Project to Nuget
|
name: Publish Project to Nuget
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v4
|
||||||
- name: Setup .NET Core
|
- name: Setup .NET Core
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v5
|
||||||
with:
|
with:
|
||||||
dotnet-version: "9.0.305"
|
dotnet-version: "10.x.x"
|
||||||
- name: Publish
|
- name: Publish
|
||||||
run: |
|
run: |
|
||||||
version=`git describe --tags`
|
version=`git describe --tags`
|
||||||
|
|||||||
@@ -46,23 +46,15 @@ public class SimApiBaseResponse(int code = 200, string message = "成功")
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 动态内容分页
|
/// 分页内容返回
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <typeparam name="T"></typeparam>
|
/// <typeparam name="T"></typeparam>
|
||||||
public class SimApiBasePageResponse<T>() : SimApiBaseResponse
|
public class PageResponse<T>
|
||||||
{
|
{
|
||||||
public T? List { get; set; }
|
public T? List { get; set; }
|
||||||
public int Page { get; set; } = 1;
|
public int Page { get; set; } = 1;
|
||||||
public int Count { get; set; } = 20;
|
public int Count { get; set; } = 20;
|
||||||
public int Total { get; set; }
|
public int Total { get; set; }
|
||||||
|
|
||||||
public SimApiBasePageResponse(T list, int page, int count, int total) : this()
|
|
||||||
{
|
|
||||||
List = list;
|
|
||||||
Page = page;
|
|
||||||
Count = count;
|
|
||||||
Total = total;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -4,11 +4,13 @@ using System.Linq;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using SimApi.Communications;
|
using SimApi.Communications;
|
||||||
|
using SimApi.Exceptions;
|
||||||
|
|
||||||
namespace SimApi.Helpers;
|
namespace SimApi.Helpers;
|
||||||
|
|
||||||
public class SimApiHttpClient(string? appId, string appKey)
|
public class SimApiHttpClient(string? appId, string appKey)
|
||||||
{
|
{
|
||||||
|
public string Server { get; init; } = string.Empty;
|
||||||
public string SignName { get; init; } = "sign";
|
public string SignName { get; init; } = "sign";
|
||||||
public string TimestampName { get; init; } = "timestamp";
|
public string TimestampName { get; init; } = "timestamp";
|
||||||
public string NonceName { get; init; } = "nonce";
|
public string NonceName { get; init; } = "nonce";
|
||||||
@@ -16,8 +18,9 @@ public class SimApiHttpClient(string? appId, string appKey)
|
|||||||
public string[] SignFields { get; init; } = [];
|
public string[] SignFields { get; init; } = [];
|
||||||
|
|
||||||
|
|
||||||
public T? SignQuery<T>(string url, object body, Dictionary<string, string>? queries = null)
|
public T? SignQuery<T>(string url, object? body = null, Dictionary<string, string>? queries = null)
|
||||||
{
|
{
|
||||||
|
url = Server + url;
|
||||||
var queryUrl = SignFields.Aggregate(string.Empty,
|
var queryUrl = SignFields.Aggregate(string.Empty,
|
||||||
(current, signField) => current + $"{signField}={queries?[signField]}&");
|
(current, signField) => current + $"{signField}={queries?[signField]}&");
|
||||||
if (!string.IsNullOrEmpty(AppIdName))
|
if (!string.IsNullOrEmpty(AppIdName))
|
||||||
@@ -35,13 +38,12 @@ public class SimApiHttpClient(string? appId, string appKey)
|
|||||||
.Aggregate(path, (current, q) => current + $"&{q.Key}={q.Value}");
|
.Aggregate(path, (current, q) => current + $"&{q.Key}={q.Value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
var http = new HttpClient();
|
return Query<T>(path, body);
|
||||||
var resp = http.PostAsJsonAsync(path, body).Result;
|
|
||||||
return resp.Content.ReadFromJsonAsync<T>().Result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? AesQuery<T>(string url, object body)
|
public T? AesQuery<T>(string url, object body)
|
||||||
{
|
{
|
||||||
|
url = Server + url;
|
||||||
if (!string.IsNullOrEmpty(AppIdName))
|
if (!string.IsNullOrEmpty(AppIdName))
|
||||||
{
|
{
|
||||||
url += $"?{AppIdName}={appId}";
|
url += $"?{AppIdName}={appId}";
|
||||||
@@ -51,9 +53,7 @@ public class SimApiHttpClient(string? appId, string appKey)
|
|||||||
{
|
{
|
||||||
Data = SimApiAesUtil.Encrypt(SimApiUtil.Json(body), appKey)
|
Data = SimApiAesUtil.Encrypt(SimApiUtil.Json(body), appKey)
|
||||||
};
|
};
|
||||||
var http = new HttpClient();
|
return Query<T>(url, req);
|
||||||
var resp = http.PostAsJsonAsync(url, req).Result;
|
|
||||||
return resp.Content.ReadFromJsonAsync<T>().Result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public T? AesSignQuery<T>(string url, object body, Dictionary<string, string>? queries = null)
|
public T? AesSignQuery<T>(string url, object body, Dictionary<string, string>? queries = null)
|
||||||
@@ -64,4 +64,17 @@ public class SimApiHttpClient(string? appId, string appKey)
|
|||||||
};
|
};
|
||||||
return SignQuery<T>(url, req, queries);
|
return SignQuery<T>(url, req, queries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private T? Query<T>(string url, object? req)
|
||||||
|
{
|
||||||
|
var http = new HttpClient();
|
||||||
|
var resp = http.PostAsJsonAsync(url, req).Result;
|
||||||
|
var res = resp.Content.ReadFromJsonAsync<SimApiBaseResponse<T>>().Result;
|
||||||
|
if (res == null)
|
||||||
|
{
|
||||||
|
throw new SimApiException(500, "请求发生错误");
|
||||||
|
}
|
||||||
|
|
||||||
|
return res.Code != 200 ? throw new SimApiException(res.Code, res.Message) : res.Data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user