mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-18 17:48:12 +08:00
feat(wxapi): 重命名部分内部依赖属性
This commit is contained in:
@@ -21,7 +21,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
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>
|
||||
|
@@ -180,7 +180,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
if (request.CardExtra != null && string.IsNullOrEmpty(request.CardExtra.Nonce))
|
||||
request.CardExtra.Nonce = Guid.NewGuid().ToString("N");
|
||||
|
@@ -25,10 +25,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentSecret))
|
||||
request.ComponentSecret = client.AppSecret;
|
||||
request.ComponentSecret = client.WechatAppSecret;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_start_push_ticket")
|
||||
@@ -51,10 +51,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentSecret))
|
||||
request.ComponentSecret = client.AppSecret;
|
||||
request.ComponentSecret = client.WechatAppSecret;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_component_token")
|
||||
@@ -77,7 +77,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_create_preauthcode")
|
||||
@@ -101,7 +101,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_query_auth")
|
||||
@@ -125,7 +125,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_authorizer_token")
|
||||
@@ -149,7 +149,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_get_authorizer_info")
|
||||
@@ -173,7 +173,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_get_authorizer_list")
|
||||
@@ -197,7 +197,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_get_authorizer_option")
|
||||
@@ -221,7 +221,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_set_authorizer_option")
|
||||
|
@@ -19,12 +19,12 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
|
||||
if (string.IsNullOrEmpty(request.ShopId))
|
||||
{
|
||||
request.ShopId = client.ImmeDeliveryAppKey;
|
||||
request.ShopId = client.WechatImmeDeliveryAppKey;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(request.DeliverySignature))
|
||||
{
|
||||
string plainText = $"{request.ShopId}{request.ShopOrderId}{client.ImmeDeliveryAppSecret}";
|
||||
string plainText = $"{request.ShopId}{request.ShopOrderId}{client.WechatImmeDeliveryAppSecret}";
|
||||
request.DeliverySignature = Security.SHA1Utility.Hash(plainText).ToLower();
|
||||
}
|
||||
|
||||
|
@@ -30,8 +30,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
.CreateRequest(HttpMethod.Get, "cgi-bin", "token")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("appid", client.AppId)
|
||||
.SetQueryParam("secret", client.AppSecret);
|
||||
.SetQueryParam("appid", client.WechatAppId)
|
||||
.SetQueryParam("secret", client.WechatAppSecret);
|
||||
|
||||
return await client.SendRequestAsync<Models.CgibinTokenResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "cgi-bin", "clear_quota")
|
||||
|
@@ -83,7 +83,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
|
||||
string boundary = "--BOUNDARY--" + DateTimeOffset.Now.Ticks.ToString("x");
|
||||
using var fileContent = new ByteArrayContent(request.FileBytes ?? new byte[0]);
|
||||
using var descContent = new ByteArrayContent(Encoding.UTF8.GetBytes(client.JsonSerializer.Serialize(request)));
|
||||
using var descContent = new ByteArrayContent(Encoding.UTF8.GetBytes(client.FlurlJsonSerializer.Serialize(request)));
|
||||
using var httpContent = new MultipartFormDataContent(boundary);
|
||||
httpContent.Add(fileContent, "\"media\"", "\"" + request.FileName + "\"");
|
||||
httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data; boundary=" + boundary);
|
||||
|
@@ -22,7 +22,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
{
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
}
|
||||
|
||||
if (!request.Timestamp.HasValue)
|
||||
@@ -46,8 +46,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
string plainText = string.Join("&", paramMap.Select(e => $"{e.Key}={e.Value}"))
|
||||
+ $"&org_loc={reqLoc}"
|
||||
+ $"&method={method.ToUpper()}"
|
||||
+ $"&secret={client.MidasAppKey}";
|
||||
request.Signature = Security.HMACSHA256Utility.Hash(client.MidasAppKey ?? string.Empty, plainText).ToLower();
|
||||
+ $"&secret={client.WechatMidasAppKey}";
|
||||
request.Signature = Security.HMACSHA256Utility.Hash(client.WechatMidasAppKey ?? string.Empty, plainText).ToLower();
|
||||
}
|
||||
|
||||
return request;
|
||||
|
@@ -72,7 +72,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "insertbill")
|
||||
@@ -97,7 +97,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "queryfee")
|
||||
@@ -121,7 +121,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "unifiedorder")
|
||||
@@ -145,7 +145,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "getorder")
|
||||
@@ -169,7 +169,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "refund")
|
||||
@@ -193,7 +193,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "downloadbill")
|
||||
@@ -217,7 +217,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "notifyinconsistentorder")
|
||||
@@ -241,7 +241,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "mocknotification")
|
||||
@@ -265,7 +265,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "mockqueryfee")
|
||||
@@ -289,7 +289,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "micropay")
|
||||
@@ -313,7 +313,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "nontax", "getorderlist")
|
||||
|
@@ -114,7 +114,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "product", "register", "submit_merchantinfo")
|
||||
@@ -138,7 +138,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "product", "register", "submit_basicinfo")
|
||||
|
@@ -28,7 +28,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "semantic", "semproxy", "search")
|
||||
|
@@ -30,8 +30,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
.CreateRequest(HttpMethod.Get, "sns", "oauth2", "access_token")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("appid", client.AppId)
|
||||
.SetQueryParam("secret", client.AppSecret)
|
||||
.SetQueryParam("appid", client.WechatAppId)
|
||||
.SetQueryParam("secret", client.WechatAppSecret)
|
||||
.SetQueryParam("code", request.Code);
|
||||
|
||||
return await client.SendRequestAsync<Models.SnsOAuth2AccessTokenResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
@@ -56,7 +56,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
.CreateRequest(HttpMethod.Get, "sns", "oauth2", "refresh_token")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("appid", client.AppId)
|
||||
.SetQueryParam("appid", client.WechatAppId)
|
||||
.SetQueryParam("refresh_token", request.RefreshToken);
|
||||
|
||||
return await client.SendRequestAsync<Models.SnsOAuth2RefreshTokenResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
@@ -129,8 +129,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
.CreateRequest(HttpMethod.Get, "sns", "jscode2session")
|
||||
.SetOptions(request)
|
||||
.SetQueryParam("grant_type", request.GrantType)
|
||||
.SetQueryParam("appid", client.AppId)
|
||||
.SetQueryParam("secret", client.AppSecret)
|
||||
.SetQueryParam("appid", client.WechatAppId)
|
||||
.SetQueryParam("secret", client.WechatAppSecret)
|
||||
.SetQueryParam("js_code", request.JsCode);
|
||||
|
||||
return await client.SendRequestAsync<Models.SnsJsCode2SessionResponse>(flurlReq, cancellationToken: cancellationToken);
|
||||
@@ -151,7 +151,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.ComponentAppId))
|
||||
request.ComponentAppId = client.AppId;
|
||||
request.ComponentAppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Get, "sns", "component", "jscode2session")
|
||||
|
@@ -26,7 +26,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "wxa", "business", "getpayfororder")
|
||||
|
@@ -416,7 +416,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (string.IsNullOrEmpty(request.AppId))
|
||||
request.AppId = client.AppId;
|
||||
request.AppId = client.WechatAppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(HttpMethod.Post, "wxa", "getuserriskrank")
|
||||
|
@@ -37,7 +37,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
|
||||
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
|
||||
{
|
||||
{ "appId", client.AppId },
|
||||
{ "appId", client.WechatAppId },
|
||||
{ "timestamp", timestamp },
|
||||
{ "nonceStr", nonce },
|
||||
{ "signature", sign }
|
||||
@@ -63,7 +63,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
SortedSet<string> sortedParams = new SortedSet<string>();
|
||||
sortedParams.Add(cardType);
|
||||
sortedParams.Add(timestamp);
|
||||
sortedParams.Add(client.AppId);
|
||||
sortedParams.Add(client.WechatAppId);
|
||||
sortedParams.Add(nonce);
|
||||
sortedParams.Add(wxcardTicket);
|
||||
string cardSign = Security.SHA1Utility.Hash(string.Join(string.Empty, sortedParams)).ToLower();
|
||||
|
@@ -20,34 +20,34 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的微信 AppId。
|
||||
/// </summary>
|
||||
public string AppId { get; }
|
||||
public string WechatAppId { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的微信 AppSecret。
|
||||
/// </summary>
|
||||
internal string AppSecret { get; }
|
||||
internal string WechatAppSecret { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的即时配送公司帐号 AppKey(用于即使配送相关接口的请求签名)。
|
||||
/// </summary>
|
||||
internal string? ImmeDeliveryAppKey { get; }
|
||||
internal string? WechatImmeDeliveryAppKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的即时配送公司帐号 AppSecret(用于即使配送相关接口的请求签名)。
|
||||
/// </summary>
|
||||
internal string? ImmeDeliveryAppSecret { get; }
|
||||
internal string? WechatImmeDeliveryAppSecret { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置米大师平台 AppKey(用于虚拟支付相关接口的请求签名)。
|
||||
/// </summary>
|
||||
internal string? MidasAppKey { get; }
|
||||
internal string? WechatMidasAppKey { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取当前客户端使用的 JSON 序列化器。
|
||||
/// </summary>
|
||||
internal ISerializer JsonSerializer
|
||||
internal ISerializer FlurlJsonSerializer
|
||||
{
|
||||
get { return ProxyFlurlClient.Settings?.JsonSerializer ?? new FlurlNewtonsoftJsonSerializer(); }
|
||||
get { return FlurlClient.Settings?.JsonSerializer ?? new FlurlNewtonsoftJsonSerializer(); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -59,14 +59,14 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
{
|
||||
if (options == null) throw new ArgumentNullException(nameof(options));
|
||||
|
||||
AppId = options.AppId;
|
||||
AppSecret = options.AppSecret;
|
||||
ImmeDeliveryAppKey = options.ImmeDeliveryAppKey;
|
||||
ImmeDeliveryAppSecret = options.ImmeDeliveryAppSecret;
|
||||
MidasAppKey = options.MidasAppKey;
|
||||
WechatAppId = options.AppId;
|
||||
WechatAppSecret = options.AppSecret;
|
||||
WechatImmeDeliveryAppKey = options.ImmeDeliveryAppKey;
|
||||
WechatImmeDeliveryAppSecret = options.ImmeDeliveryAppSecret;
|
||||
WechatMidasAppKey = options.MidasAppKey;
|
||||
|
||||
ProxyFlurlClient.BaseUrl = options.Endpoints ?? WechatApiEndpoints.DEFAULT;
|
||||
ProxyFlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout));
|
||||
FlurlClient.BaseUrl = options.Endpoints ?? WechatApiEndpoints.DEFAULT;
|
||||
FlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -83,17 +83,17 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
/// 异步发起请求。
|
||||
/// </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 : WechatApiResponse, 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)
|
||||
{
|
||||
@@ -105,17 +105,17 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
/// 异步发起请求。
|
||||
/// </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 : WechatApiResponse, 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)
|
||||
{
|
||||
@@ -123,25 +123,25 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<T> GetResposneAsync<T>(IFlurlResponse response)
|
||||
private async Task<T> GetResposneAsync<T>(IFlurlResponse flurlResponse)
|
||||
where T : WechatApiResponse, new()
|
||||
{
|
||||
string contentType = response.Headers.GetAll("Content-Type").FirstOrDefault() ?? string.Empty;
|
||||
string contentType = flurlResponse.Headers.GetAll("Content-Type").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"));
|
||||
|
||||
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