feat(wxapi): 重命名部分内部依赖属性

This commit is contained in:
Fu Diwei
2021-06-17 19:45:30 +08:00
parent 60b8d6cac1
commit 30d0eaadd4
15 changed files with 75 additions and 75 deletions

View File

@@ -21,7 +21,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (client == null) throw new ArgumentNullException(nameof(client)); if (client == null) throw new ArgumentNullException(nameof(client));
if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson); if (string.IsNullOrEmpty(callbackJson)) throw new ArgumentNullException(callbackJson);
return client.JsonSerializer.Deserialize<TEvent>(callbackJson); return client.FlurlJsonSerializer.Deserialize<TEvent>(callbackJson);
} }
/// <summary> /// <summary>

View File

@@ -180,7 +180,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
if (request.CardExtra != null && string.IsNullOrEmpty(request.CardExtra.Nonce)) if (request.CardExtra != null && string.IsNullOrEmpty(request.CardExtra.Nonce))
request.CardExtra.Nonce = Guid.NewGuid().ToString("N"); request.CardExtra.Nonce = Guid.NewGuid().ToString("N");

View File

@@ -25,10 +25,10 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
if (string.IsNullOrEmpty(request.ComponentSecret)) if (string.IsNullOrEmpty(request.ComponentSecret))
request.ComponentSecret = client.AppSecret; request.ComponentSecret = client.WechatAppSecret;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_start_push_ticket") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
if (string.IsNullOrEmpty(request.ComponentSecret)) if (string.IsNullOrEmpty(request.ComponentSecret))
request.ComponentSecret = client.AppSecret; request.ComponentSecret = client.WechatAppSecret;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_component_token") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_create_preauthcode") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_query_auth") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_authorizer_token") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_get_authorizer_info") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_get_authorizer_list") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_get_authorizer_option") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_set_authorizer_option") .CreateRequest(HttpMethod.Post, "cgi-bin", "component", "api_set_authorizer_option")

View File

@@ -19,12 +19,12 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (string.IsNullOrEmpty(request.ShopId)) if (string.IsNullOrEmpty(request.ShopId))
{ {
request.ShopId = client.ImmeDeliveryAppKey; request.ShopId = client.WechatImmeDeliveryAppKey;
} }
if (string.IsNullOrEmpty(request.DeliverySignature)) 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(); request.DeliverySignature = Security.SHA1Utility.Hash(plainText).ToLower();
} }

View File

@@ -30,8 +30,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
.CreateRequest(HttpMethod.Get, "cgi-bin", "token") .CreateRequest(HttpMethod.Get, "cgi-bin", "token")
.SetOptions(request) .SetOptions(request)
.SetQueryParam("grant_type", request.GrantType) .SetQueryParam("grant_type", request.GrantType)
.SetQueryParam("appid", client.AppId) .SetQueryParam("appid", client.WechatAppId)
.SetQueryParam("secret", client.AppSecret); .SetQueryParam("secret", client.WechatAppSecret);
return await client.SendRequestAsync<Models.CgibinTokenResponse>(flurlReq, cancellationToken: cancellationToken); 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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "cgi-bin", "clear_quota") .CreateRequest(HttpMethod.Post, "cgi-bin", "clear_quota")

View File

@@ -83,7 +83,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
string boundary = "--BOUNDARY--" + DateTimeOffset.Now.Ticks.ToString("x"); string boundary = "--BOUNDARY--" + DateTimeOffset.Now.Ticks.ToString("x");
using var fileContent = new ByteArrayContent(request.FileBytes ?? new byte[0]); 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); using var httpContent = new MultipartFormDataContent(boundary);
httpContent.Add(fileContent, "\"media\"", "\"" + request.FileName + "\""); httpContent.Add(fileContent, "\"media\"", "\"" + request.FileName + "\"");
httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data; boundary=" + boundary); httpContent.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data; boundary=" + boundary);

View File

@@ -22,7 +22,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
{ {
request.AppId = client.AppId; request.AppId = client.WechatAppId;
} }
if (!request.Timestamp.HasValue) if (!request.Timestamp.HasValue)
@@ -46,8 +46,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
string plainText = string.Join("&", paramMap.Select(e => $"{e.Key}={e.Value}")) string plainText = string.Join("&", paramMap.Select(e => $"{e.Key}={e.Value}"))
+ $"&org_loc={reqLoc}" + $"&org_loc={reqLoc}"
+ $"&method={method.ToUpper()}" + $"&method={method.ToUpper()}"
+ $"&secret={client.MidasAppKey}"; + $"&secret={client.WechatMidasAppKey}";
request.Signature = Security.HMACSHA256Utility.Hash(client.MidasAppKey ?? string.Empty, plainText).ToLower(); request.Signature = Security.HMACSHA256Utility.Hash(client.WechatMidasAppKey ?? string.Empty, plainText).ToLower();
} }
return request; return request;

View File

@@ -72,7 +72,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "insertbill") .CreateRequest(HttpMethod.Post, "nontax", "insertbill")
@@ -97,7 +97,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "queryfee") .CreateRequest(HttpMethod.Post, "nontax", "queryfee")
@@ -121,7 +121,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "unifiedorder") .CreateRequest(HttpMethod.Post, "nontax", "unifiedorder")
@@ -145,7 +145,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "getorder") .CreateRequest(HttpMethod.Post, "nontax", "getorder")
@@ -169,7 +169,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "refund") .CreateRequest(HttpMethod.Post, "nontax", "refund")
@@ -193,7 +193,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "downloadbill") .CreateRequest(HttpMethod.Post, "nontax", "downloadbill")
@@ -217,7 +217,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "notifyinconsistentorder") .CreateRequest(HttpMethod.Post, "nontax", "notifyinconsistentorder")
@@ -241,7 +241,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "mocknotification") .CreateRequest(HttpMethod.Post, "nontax", "mocknotification")
@@ -265,7 +265,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "mockqueryfee") .CreateRequest(HttpMethod.Post, "nontax", "mockqueryfee")
@@ -289,7 +289,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "micropay") .CreateRequest(HttpMethod.Post, "nontax", "micropay")
@@ -313,7 +313,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "nontax", "getorderlist") .CreateRequest(HttpMethod.Post, "nontax", "getorderlist")

View File

@@ -114,7 +114,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "product", "register", "submit_merchantinfo") .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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "product", "register", "submit_basicinfo") .CreateRequest(HttpMethod.Post, "product", "register", "submit_basicinfo")

View File

@@ -28,7 +28,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "semantic", "semproxy", "search") .CreateRequest(HttpMethod.Post, "semantic", "semproxy", "search")

View File

@@ -30,8 +30,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
.CreateRequest(HttpMethod.Get, "sns", "oauth2", "access_token") .CreateRequest(HttpMethod.Get, "sns", "oauth2", "access_token")
.SetOptions(request) .SetOptions(request)
.SetQueryParam("grant_type", request.GrantType) .SetQueryParam("grant_type", request.GrantType)
.SetQueryParam("appid", client.AppId) .SetQueryParam("appid", client.WechatAppId)
.SetQueryParam("secret", client.AppSecret) .SetQueryParam("secret", client.WechatAppSecret)
.SetQueryParam("code", request.Code); .SetQueryParam("code", request.Code);
return await client.SendRequestAsync<Models.SnsOAuth2AccessTokenResponse>(flurlReq, cancellationToken: cancellationToken); 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") .CreateRequest(HttpMethod.Get, "sns", "oauth2", "refresh_token")
.SetOptions(request) .SetOptions(request)
.SetQueryParam("grant_type", request.GrantType) .SetQueryParam("grant_type", request.GrantType)
.SetQueryParam("appid", client.AppId) .SetQueryParam("appid", client.WechatAppId)
.SetQueryParam("refresh_token", request.RefreshToken); .SetQueryParam("refresh_token", request.RefreshToken);
return await client.SendRequestAsync<Models.SnsOAuth2RefreshTokenResponse>(flurlReq, cancellationToken: cancellationToken); return await client.SendRequestAsync<Models.SnsOAuth2RefreshTokenResponse>(flurlReq, cancellationToken: cancellationToken);
@@ -129,8 +129,8 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
.CreateRequest(HttpMethod.Get, "sns", "jscode2session") .CreateRequest(HttpMethod.Get, "sns", "jscode2session")
.SetOptions(request) .SetOptions(request)
.SetQueryParam("grant_type", request.GrantType) .SetQueryParam("grant_type", request.GrantType)
.SetQueryParam("appid", client.AppId) .SetQueryParam("appid", client.WechatAppId)
.SetQueryParam("secret", client.AppSecret) .SetQueryParam("secret", client.WechatAppSecret)
.SetQueryParam("js_code", request.JsCode); .SetQueryParam("js_code", request.JsCode);
return await client.SendRequestAsync<Models.SnsJsCode2SessionResponse>(flurlReq, cancellationToken: cancellationToken); 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 (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.ComponentAppId)) if (string.IsNullOrEmpty(request.ComponentAppId))
request.ComponentAppId = client.AppId; request.ComponentAppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Get, "sns", "component", "jscode2session") .CreateRequest(HttpMethod.Get, "sns", "component", "jscode2session")

View File

@@ -26,7 +26,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "wxa", "business", "getpayfororder") .CreateRequest(HttpMethod.Post, "wxa", "business", "getpayfororder")

View File

@@ -416,7 +416,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
if (request is null) throw new ArgumentNullException(nameof(request)); if (request is null) throw new ArgumentNullException(nameof(request));
if (string.IsNullOrEmpty(request.AppId)) if (string.IsNullOrEmpty(request.AppId))
request.AppId = client.AppId; request.AppId = client.WechatAppId;
IFlurlRequest flurlReq = client IFlurlRequest flurlReq = client
.CreateRequest(HttpMethod.Post, "wxa", "getuserriskrank") .CreateRequest(HttpMethod.Post, "wxa", "getuserriskrank")

View File

@@ -37,7 +37,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>() return new ReadOnlyDictionary<string, string>(new Dictionary<string, string>()
{ {
{ "appId", client.AppId }, { "appId", client.WechatAppId },
{ "timestamp", timestamp }, { "timestamp", timestamp },
{ "nonceStr", nonce }, { "nonceStr", nonce },
{ "signature", sign } { "signature", sign }
@@ -63,7 +63,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
SortedSet<string> sortedParams = new SortedSet<string>(); SortedSet<string> sortedParams = new SortedSet<string>();
sortedParams.Add(cardType); sortedParams.Add(cardType);
sortedParams.Add(timestamp); sortedParams.Add(timestamp);
sortedParams.Add(client.AppId); sortedParams.Add(client.WechatAppId);
sortedParams.Add(nonce); sortedParams.Add(nonce);
sortedParams.Add(wxcardTicket); sortedParams.Add(wxcardTicket);
string cardSign = Security.SHA1Utility.Hash(string.Join(string.Empty, sortedParams)).ToLower(); string cardSign = Security.SHA1Utility.Hash(string.Join(string.Empty, sortedParams)).ToLower();

View File

@@ -20,34 +20,34 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
/// <summary> /// <summary>
/// 获取当前客户端使用的微信 AppId。 /// 获取当前客户端使用的微信 AppId。
/// </summary> /// </summary>
public string AppId { get; } public string WechatAppId { get; }
/// <summary> /// <summary>
/// 获取当前客户端使用的微信 AppSecret。 /// 获取当前客户端使用的微信 AppSecret。
/// </summary> /// </summary>
internal string AppSecret { get; } internal string WechatAppSecret { get; }
/// <summary> /// <summary>
/// 获取当前客户端使用的即时配送公司帐号 AppKey用于即使配送相关接口的请求签名 /// 获取当前客户端使用的即时配送公司帐号 AppKey用于即使配送相关接口的请求签名
/// </summary> /// </summary>
internal string? ImmeDeliveryAppKey { get; } internal string? WechatImmeDeliveryAppKey { get; }
/// <summary> /// <summary>
/// 获取当前客户端使用的即时配送公司帐号 AppSecret用于即使配送相关接口的请求签名 /// 获取当前客户端使用的即时配送公司帐号 AppSecret用于即使配送相关接口的请求签名
/// </summary> /// </summary>
internal string? ImmeDeliveryAppSecret { get; } internal string? WechatImmeDeliveryAppSecret { get; }
/// <summary> /// <summary>
/// 获取或设置米大师平台 AppKey用于虚拟支付相关接口的请求签名 /// 获取或设置米大师平台 AppKey用于虚拟支付相关接口的请求签名
/// </summary> /// </summary>
internal string? MidasAppKey { get; } internal string? WechatMidasAppKey { get; }
/// <summary> /// <summary>
/// 获取当前客户端使用的 JSON 序列化器。 /// 获取当前客户端使用的 JSON 序列化器。
/// </summary> /// </summary>
internal ISerializer JsonSerializer internal ISerializer FlurlJsonSerializer
{ {
get { return ProxyFlurlClient.Settings?.JsonSerializer ?? new FlurlNewtonsoftJsonSerializer(); } get { return FlurlClient.Settings?.JsonSerializer ?? new FlurlNewtonsoftJsonSerializer(); }
} }
/// <summary> /// <summary>
@@ -59,14 +59,14 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
{ {
if (options == null) throw new ArgumentNullException(nameof(options)); if (options == null) throw new ArgumentNullException(nameof(options));
AppId = options.AppId; WechatAppId = options.AppId;
AppSecret = options.AppSecret; WechatAppSecret = options.AppSecret;
ImmeDeliveryAppKey = options.ImmeDeliveryAppKey; WechatImmeDeliveryAppKey = options.ImmeDeliveryAppKey;
ImmeDeliveryAppSecret = options.ImmeDeliveryAppSecret; WechatImmeDeliveryAppSecret = options.ImmeDeliveryAppSecret;
MidasAppKey = options.MidasAppKey; WechatMidasAppKey = options.MidasAppKey;
ProxyFlurlClient.BaseUrl = options.Endpoints ?? WechatApiEndpoints.DEFAULT; FlurlClient.BaseUrl = options.Endpoints ?? WechatApiEndpoints.DEFAULT;
ProxyFlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout)); FlurlClient.WithTimeout(TimeSpan.FromMilliseconds(options.Timeout));
} }
/// <summary> /// <summary>
@@ -83,17 +83,17 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
/// 异步发起请求。 /// 异步发起请求。
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="request"></param> /// <param name="flurlRequest"></param>
/// <param name="content"></param> /// <param name="content"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <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() where T : WechatApiResponse, new()
{ {
try try
{ {
using IFlurlResponse response = await base.SendRequestAsync(request, content, cancellationToken).ConfigureAwait(false); using IFlurlResponse flurlResponse = await base.SendRequestAsync(flurlRequest, content, cancellationToken).ConfigureAwait(false);
return await GetResposneAsync<T>(response).ConfigureAwait(false); return await GetResposneAsync<T>(flurlResponse).ConfigureAwait(false);
} }
catch (FlurlHttpException ex) catch (FlurlHttpException ex)
{ {
@@ -105,17 +105,17 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
/// 异步发起请求。 /// 异步发起请求。
/// </summary> /// </summary>
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="request"></param> /// <param name="flurlRequest"></param>
/// <param name="data"></param> /// <param name="data"></param>
/// <param name="cancellationToken"></param> /// <param name="cancellationToken"></param>
/// <returns></returns> /// <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() where T : WechatApiResponse, new()
{ {
try try
{ {
using IFlurlResponse response = await base.SendRequestWithJsonAsync(request, data, cancellationToken).ConfigureAwait(false); using IFlurlResponse flurlResponse = await base.SendRequestWithJsonAsync(flurlRequest, data, cancellationToken).ConfigureAwait(false);
return await GetResposneAsync<T>(response).ConfigureAwait(false); return await GetResposneAsync<T>(flurlResponse).ConfigureAwait(false);
} }
catch (FlurlHttpException ex) 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() 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 = bool contentTypeIsNotJson =
(response.StatusCode != (int)HttpStatusCode.OK) || (flurlResponse.StatusCode != (int)HttpStatusCode.OK) ||
(!contentType.StartsWith("application/json") && !contentType.StartsWith("text/json") && !contentType.StartsWith("text/plain")); (!contentType.StartsWith("application/json") && !contentType.StartsWith("text/json") && !contentType.StartsWith("text/plain"));
T result = contentTypeIsNotJson ? new T() : await response.GetJsonAsync<T>().ConfigureAwait(false); T result = contentTypeIsNotJson ? new T() : await flurlResponse.GetJsonAsync<T>().ConfigureAwait(false);
result.RawStatus = response.StatusCode; result.RawStatus = flurlResponse.StatusCode;
result.RawHeaders = new ReadOnlyDictionary<string, string>( result.RawHeaders = new ReadOnlyDictionary<string, string>(
response.Headers flurlResponse.Headers
.GroupBy(e => e.Name) .GroupBy(e => e.Name)
.ToDictionary( .ToDictionary(
k => k.Key, k => k.Key,
v => string.Join(", ", v.Select(e => e.Value)) 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; return result;
} }
} }