mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-21 02:58:06 +08:00
feat(work): 重命名部分内部依赖属性
This commit is contained in:
@@ -21,7 +21,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (client == null) throw new ArgumentNullException(nameof(client));
|
||||
if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson);
|
||||
|
||||
return client.JsonSerializer.Deserialize<TEvent>(callbackJson);
|
||||
return client.FlurlJsonSerializer.Deserialize<TEvent>(callbackJson);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@@ -27,7 +27,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Get, "cgi-bin", "agent", "get")
|
||||
@@ -75,7 +75,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "agent", "set")
|
||||
@@ -100,7 +100,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "agent", "set_scope")
|
||||
@@ -125,7 +125,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "agent", "set_workbench_template")
|
||||
@@ -149,7 +149,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "agent", "get_workbench_template")
|
||||
@@ -173,7 +173,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "agent", "set_workbench_data")
|
||||
|
@@ -26,7 +26,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.ParentAgentId.HasValue)
|
||||
request.ParentAgentId = client.AgentId;
|
||||
request.ParentAgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "corpgroup", "corp", "list_app_share_info")
|
||||
|
@@ -27,8 +27,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Get, "cgi-bin", "gettoken")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("corpid", client.CorpId)
|
||||
.SetQueryParam("corpsecret", client.AgentSecret);
|
||||
.SetQueryParam("corpid", client.WechatCorpId)
|
||||
.SetQueryParam("corpsecret", client.WechatAgentSecret);
|
||||
|
||||
return await client.SendRequestAsync<Models.CgibinGetTokenResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
@@ -995,7 +995,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "externalcontact", "message", "send")
|
||||
|
@@ -131,7 +131,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "linkedcorp", "message", "send")
|
||||
|
@@ -25,7 +25,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "menu", "create")
|
||||
@@ -50,7 +50,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Get, "cgi-bin", "menu", "get")
|
||||
@@ -75,7 +75,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Get, "cgi-bin", "menu", "delete")
|
||||
|
@@ -27,7 +27,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "message", "send")
|
||||
@@ -51,7 +51,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (!request.AgentId.HasValue)
|
||||
request.AgentId = client.AgentId;
|
||||
request.AgentId = client.WechatAgentId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "message", "update_taskcard")
|
||||
|
@@ -30,7 +30,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "service", "get_provider_token")
|
||||
.SetOptions(request);
|
||||
|
||||
var requestData = new { corpid = client.CorpId, provider_secret = client.AgentSecret };
|
||||
var requestData = new { corpid = client.WechatCorpId, provider_secret = client.WechatAgentSecret };
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinServiceGetProviderTokenResponse>(flurlReq, data: requestData, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
@@ -49,10 +49,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.SuiteId))
|
||||
request.SuiteId = client.SuiteId;
|
||||
request.SuiteId = client.WechatSuiteId;
|
||||
|
||||
if (string.IsNullOrEmpty(request.SuiteSecret))
|
||||
request.SuiteSecret = client.SuiteSecret;
|
||||
request.SuiteSecret = client.WechatSuiteSecret;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "service", "get_suite_token")
|
||||
|
@@ -39,7 +39,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
|
||||
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
||||
{
|
||||
{ "appId", client.CorpId },
|
||||
{ "appId", client.WechatCorpId },
|
||||
{ "timestamp", timestamp },
|
||||
{ "nonceStr", nonce },
|
||||
{ "signature", sign }
|
||||
@@ -68,8 +68,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
|
||||
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
||||
{
|
||||
{ "corpid", client.CorpId },
|
||||
{ "agentid", client.AgentId?.ToString() ?? string.Empty },
|
||||
{ "corpid", client.WechatCorpId },
|
||||
{ "agentid", client.WechatAgentId?.ToString() ?? string.Empty },
|
||||
{ "timestamp", timestamp },
|
||||
{ "nonceStr", nonce },
|
||||
{ "signature", sign }
|
||||
|
@@ -20,39 +20,39 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的企业微信 CorpId。
|
||||
/// </summary>
|
||||
public string CorpId { get; }
|
||||
public string WechatCorpId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的企业微信应用的 AgentId。
|
||||
/// </summary>
|
||||
internal int? AgentId { get; }
|
||||
internal int? WechatAgentId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的企业微信应用的 AgentSecret。
|
||||
/// </summary>
|
||||
internal string? AgentSecret { get; }
|
||||
internal string? WechatAgentSecret { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的企业微信服务商 Secret。
|
||||
/// </summary>
|
||||
internal string? ProviderSecret { get; set; }
|
||||
internal string? WechatProviderSecret { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的企业微信第三方应用的 SuiteId。
|
||||
/// </summary>
|
||||
internal string? SuiteId { get; set; }
|
||||
internal string? WechatSuiteId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的企业微信第三方应用的 SuiteSecret。
|
||||
/// </summary>
|
||||
internal string? SuiteSecret { get; set; }
|
||||
internal string? WechatSuiteSecret { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的 JSON 序列化器。
|
||||
/// </summary>
|
||||
internal ISerializer JsonSerializer
|
||||
internal ISerializer FlurlJsonSerializer
|
||||
{
|
||||
get { return ProxyFlurlClient.Settings?.JsonSerializer ?? new FlurlNewtonsoftJsonSerializer(); }
|
||||
get { return FlurlClient.Settings?.JsonSerializer ?? new FlurlNewtonsoftJsonSerializer(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -64,15 +64,15 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
|
||||
CorpId = options.CorpId;
|
||||
AgentId = options.AgentId;
|
||||
AgentSecret = options.AgentSecret;
|
||||
ProviderSecret = options.ProviderSecret;
|
||||
SuiteId = options.SuiteId;
|
||||
SuiteSecret = options.SuiteSecret;
|
||||
WechatCorpId = options.CorpId;
|
||||
WechatAgentId = options.AgentId;
|
||||
WechatAgentSecret = options.AgentSecret;
|
||||
WechatProviderSecret = options.ProviderSecret;
|
||||
WechatSuiteId = options.SuiteId;
|
||||
WechatSuiteSecret = options.SuiteSecret;
|
||||
|
||||
ProxyFlurlClient.BaseUrl = options.Endpoints ?? WechatWorkEndpoints.DEFAULT;
|
||||
ProxyFlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout));
|
||||
FlurlClient.BaseUrl = options.Endpoints ?? WechatWorkEndpoints.DEFAULT;
|
||||
FlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -90,17 +90,17 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
/// 异步发起请求。
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="flurlRequest"></param>
|
||||
/// <param name="content"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> SendRequestAsync<T>(IFlurlRequest request, HttpContent? content = null, CancellationToken cancellationToken = default)
|
||||
public async Task<T> SendRequestAsync<T>(IFlurlRequest flurlRequest, HttpContent? content = null, CancellationToken cancellationToken = default)
|
||||
where T : WechatWorkResponse, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
using IFlurlResponse response = await base.SendRequestAsync(request, content, cancellationToken).ConfigureAwait(false);
|
||||
return await GetResposneAsync<T>(response).ConfigureAwait(false);
|
||||
using IFlurlResponse flurlResponse = await base.SendRequestAsync(flurlRequest, content, cancellationToken).ConfigureAwait(false);
|
||||
return await GetResposneAsync<T>(flurlResponse).ConfigureAwait(false);
|
||||
}
|
||||
catch (FlurlHttpException ex)
|
||||
{
|
||||
@@ -112,17 +112,17 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
/// 异步发起请求。
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="flurlRequest"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<T> SendRequestWithJsonAsync<T>(IFlurlRequest request, object? data = null, CancellationToken cancellationToken = default)
|
||||
public async Task<T> SendRequestWithJsonAsync<T>(IFlurlRequest flurlRequest, object? data = null, CancellationToken cancellationToken = default)
|
||||
where T : WechatWorkResponse, new()
|
||||
{
|
||||
try
|
||||
{
|
||||
using IFlurlResponse response = await base.SendRequestWithJsonAsync(request, data, cancellationToken).ConfigureAwait(false);
|
||||
return await GetResposneAsync<T>(response).ConfigureAwait(false);
|
||||
using IFlurlResponse flurlResponse = await base.SendRequestWithJsonAsync(flurlRequest, data, cancellationToken).ConfigureAwait(false);
|
||||
return await GetResposneAsync<T>(flurlResponse).ConfigureAwait(false);
|
||||
}
|
||||
catch (FlurlHttpException ex)
|
||||
{
|
||||
@@ -130,27 +130,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<T> GetResposneAsync<T>(IFlurlResponse response)
|
||||
private async Task<T> GetResposneAsync<T>(IFlurlResponse flurlResponse)
|
||||
where T : WechatWorkResponse, new()
|
||||
{
|
||||
string contentType = response.Headers.GetAll("Content-Type").FirstOrDefault() ?? string.Empty;
|
||||
string contentDisposition = response.Headers.GetAll("Content-Disposition").FirstOrDefault() ?? string.Empty;
|
||||
string contentType = flurlResponse.Headers.GetAll("Content-Type").FirstOrDefault() ?? string.Empty;
|
||||
string contentDisposition = flurlResponse.Headers.GetAll("Content-Disposition").FirstOrDefault() ?? string.Empty;
|
||||
bool contentTypeIsNotJson =
|
||||
(response.StatusCode != (int)HttpStatusCode.OK) ||
|
||||
(flurlResponse.StatusCode != (int)HttpStatusCode.OK) ||
|
||||
(!contentType.StartsWith("application/json") && !contentType.StartsWith("text/json") && !contentType.StartsWith("text/plain")) ||
|
||||
(contentDisposition.StartsWith("attachment"));
|
||||
|
||||
T result = contentTypeIsNotJson ? new T() : await response.GetJsonAsync<T>().ConfigureAwait(false);
|
||||
result.RawStatus = response.StatusCode;
|
||||
T result = contentTypeIsNotJson ? new T() : await flurlResponse.GetJsonAsync<T>().ConfigureAwait(false);
|
||||
result.RawStatus = flurlResponse.StatusCode;
|
||||
result.RawHeaders = new ReadOnlyDictionary<string, string>(
|
||||
response.Headers
|
||||
flurlResponse.Headers
|
||||
.GroupBy(e => e.Name)
|
||||
.ToDictionary(
|
||||
k => k.Key,
|
||||
v => string.Join(", ", v.Select(e => e.Value))
|
||||
)
|
||||
);
|
||||
result.RawBytes = await response.ResponseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||
result.RawBytes = await flurlResponse.ResponseMessage.Content.ReadAsByteArrayAsync().ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user