From 0bb1e9bda6ba30a070367fca5dae2f74f4f71fdb Mon Sep 17 00:00:00 2001 From: Fu Diwei Date: Wed, 26 Oct 2022 22:12:08 +0800 Subject: [PATCH] =?UTF-8?q?feat(wxapi):=20=E6=96=B0=E5=A2=9E=E4=BB=A3?= =?UTF-8?q?=E5=95=86=E5=AE=B6=E7=AE=A1=E7=90=86=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8F=91=E5=B8=83=E5=90=8E=E7=94=9F=E6=95=88?= =?UTF-8?q?=E5=9F=9F=E5=90=8D=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WechatApiClientExecuteCardExtensions.cs | 2 +- ...tApiClientExecuteWxaComponentExtensions.cs | 60 +++++++++++++ .../Domain/WxaGetEffectiveDomainRequest.cs | 9 ++ .../Domain/WxaGetEffectiveDomainResponse.cs | 84 +++++++++++++++++ .../WxaGetEffectiveWebviewDomainRequest.cs | 9 ++ .../WxaGetEffectiveWebviewDomainResponse.cs | 84 +++++++++++++++++ .../WxaSetWebviewDomainDirectlyRequest.cs | 25 ++++++ .../WxaSetWebviewDomainDirectlyResponse.cs | 15 ++++ .../Domain/WxaGetEffectiveDomainResponse.json | 90 +++++++++++++++++++ .../WxaGetEffectiveWebviewDomainResponse.json | 22 +++++ 10 files changed, 399 insertions(+), 1 deletion(-) create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyRequest.cs create mode 100644 src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyResponse.cs create mode 100644 test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveDomainResponse.json create mode 100644 test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.json diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteCardExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteCardExtensions.cs index 3c83da57..12f52db0 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteCardExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteCardExtensions.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Net.Http; using System.Threading; using System.Threading.Tasks; diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs index 69733b0e..13480ebe 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs @@ -172,6 +172,26 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } + /// + /// 异步调用 [POST] /wxa/setwebviewdomain_directly 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/modifyJumpDomainDirectly.html + /// + /// + /// + /// + /// + public static async Task ExecuteWxaSetWebviewDomainDirectlyAsync(this WechatApiClient client, Models.WxaSetWebviewDomainDirectlyRequest request, CancellationToken cancellationToken = default) + { + if (client is null) throw new ArgumentNullException(nameof(client)); + if (request is null) throw new ArgumentNullException(nameof(request)); + + IFlurlRequest flurlReq = client + .CreateRequest(request, HttpMethod.Post, "wxa", "setwebviewdomain_directly") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + /// /// 异步调用 [POST] /wxa/get_webviewdomain_confirmfile 接口。 /// REF: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/getJumpDomainConfirmFile.html @@ -191,6 +211,46 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } + + /// + /// 异步调用 [POST] /wxa/get_effective_domain 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/getEffectiveServerDomain.html + /// + /// + /// + /// + /// + public static async Task ExecuteWxaGetEffectiveDomainAsync(this WechatApiClient client, Models.WxaGetEffectiveDomainRequest request, CancellationToken cancellationToken = default) + { + if (client is null) throw new ArgumentNullException(nameof(client)); + if (request is null) throw new ArgumentNullException(nameof(request)); + + IFlurlRequest flurlReq = client + .CreateRequest(request, HttpMethod.Post, "wxa", "get_effective_domain") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /wxa/get_effective_webviewdomain 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/getEffectiveJumpDomain.html + /// + /// + /// + /// + /// + public static async Task ExecuteWxaGetEffectiveWebviewDomainAsync(this WechatApiClient client, Models.WxaGetEffectiveWebviewDomainRequest request, CancellationToken cancellationToken = default) + { + if (client is null) throw new ArgumentNullException(nameof(client)); + if (request is null) throw new ArgumentNullException(nameof(request)); + + IFlurlRequest flurlReq = client + .CreateRequest(request, HttpMethod.Post, "wxa", "get_effective_webviewdomain") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } #endregion #region Register diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainRequest.cs new file mode 100644 index 00000000..3c57e211 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainRequest.cs @@ -0,0 +1,9 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/get_effective_domain 接口的请求。 + /// + public class WxaGetEffectiveDomainRequest : WechatApiRequest, IInferable + { + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainResponse.cs new file mode 100644 index 00000000..4d4377e9 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveDomainResponse.cs @@ -0,0 +1,84 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/get_effective_domain 接口的响应。 + /// + public class WxaGetEffectiveDomainResponse : WechatApiResponse + { + public static class Types + { + public class Domain + { + /// + /// 获取或设置 Request 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("requestdomain")] + [System.Text.Json.Serialization.JsonPropertyName("requestdomain")] + public string[] RequestDomainList { get; set; } = default!; + + /// + /// 获取或设置 Socket 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("wsrequestdomain")] + [System.Text.Json.Serialization.JsonPropertyName("wsrequestdomain")] + public string[] WebSocketDomainList { get; set; } = default!; + + /// + /// 获取或设置 UploadFile 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("uploaddomain")] + [System.Text.Json.Serialization.JsonPropertyName("uploaddomain")] + public string[] UploadDomainList { get; set; } = default!; + + /// + /// 获取或设置 DownloadFile 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("downloaddomain")] + [System.Text.Json.Serialization.JsonPropertyName("downloaddomain")] + public string[] DownloadDomainList { get; set; } = default!; + + /// + /// 获取或设置 UDP 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("udpdomain")] + [System.Text.Json.Serialization.JsonPropertyName("udpdomain")] + public string[] UdpDomainList { get; set; } = default!; + + /// + /// 获取或设置 TCP 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("tcpdomain")] + [System.Text.Json.Serialization.JsonPropertyName("tcpdomain")] + public string[] TcpDomainList { get; set; } = default!; + } + } + + /// + /// 获取或设置通过公众平台配置的服务器域名信息。 + /// + [Newtonsoft.Json.JsonProperty("mp_domain")] + [System.Text.Json.Serialization.JsonPropertyName("mp_domain")] + public Types.Domain? MpDomain { get; set; } + + /// + /// 获取或设置通过第三方平台接口配置的服务器域名信息。 + /// + [Newtonsoft.Json.JsonProperty("third_domain")] + [System.Text.Json.Serialization.JsonPropertyName("third_domain")] + public Types.Domain? ThirdDomain { get; set; } + + /// + /// 获取或设置通过 ModifyServerDomainDirectly 接口配置的服务器域名信息。 + /// + [Newtonsoft.Json.JsonProperty("direct_domain")] + [System.Text.Json.Serialization.JsonPropertyName("direct_domain")] + public Types.Domain? DirectlyDomain { get; set; } + + /// + /// 获取或设置最后提交代码或者发布上线后生效的域名信息。 + /// + [Newtonsoft.Json.JsonProperty("effective_domain")] + [System.Text.Json.Serialization.JsonPropertyName("effective_domain")] + public Types.Domain? EffectiveDomain { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainRequest.cs new file mode 100644 index 00000000..188c20a3 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainRequest.cs @@ -0,0 +1,9 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/get_effective_webviewdomain 接口的请求。 + /// + public class WxaGetEffectiveWebviewDomainRequest : WechatApiRequest, IInferable + { + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.cs new file mode 100644 index 00000000..6dd3ea2c --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.cs @@ -0,0 +1,84 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/get_effective_webviewdomain 接口的响应。 + /// + public class WxaGetEffectiveWebviewDomainResponse : WechatApiResponse + { + public static class Types + { + public class Domain + { + /// + /// 获取或设置 Request 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("requestdomain")] + [System.Text.Json.Serialization.JsonPropertyName("requestdomain")] + public string[] RequestDomainList { get; set; } = default!; + + /// + /// 获取或设置 Socket 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("wsrequestdomain")] + [System.Text.Json.Serialization.JsonPropertyName("wsrequestdomain")] + public string[] WebSocketDomainList { get; set; } = default!; + + /// + /// 获取或设置 UploadFile 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("uploaddomain")] + [System.Text.Json.Serialization.JsonPropertyName("uploaddomain")] + public string[] UploadDomainList { get; set; } = default!; + + /// + /// 获取或设置 DownloadFile 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("downloaddomain")] + [System.Text.Json.Serialization.JsonPropertyName("downloaddomain")] + public string[] DownloadDomainList { get; set; } = default!; + + /// + /// 获取或设置 UDP 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("udpdomain")] + [System.Text.Json.Serialization.JsonPropertyName("udpdomain")] + public string[] UdpDomainList { get; set; } = default!; + + /// + /// 获取或设置 TCP 合法域名列表。 + /// + [Newtonsoft.Json.JsonProperty("tcpdomain")] + [System.Text.Json.Serialization.JsonPropertyName("tcpdomain")] + public string[] TcpDomainList { get; set; } = default!; + } + } + + /// + /// 获取或设置通过公众平台配置的 Webview 域名列表。 + /// + [Newtonsoft.Json.JsonProperty("mp_webviewdomain")] + [System.Text.Json.Serialization.JsonPropertyName("mp_webviewdomain")] + public string[]? MpWebviewDomain { get; set; } + + /// + /// 获取或设置通过第三方平台接口配置的 Webview 域名列表。 + /// + [Newtonsoft.Json.JsonProperty("third_webviewdomain")] + [System.Text.Json.Serialization.JsonPropertyName("third_webviewdomain")] + public string[]? ThirdWebviewDomain { get; set; } + + /// + /// 获取或设置通过 ModifyServerDomainDirectly 接口配置的 Webview 域名列表。 + /// + [Newtonsoft.Json.JsonProperty("direct_webviewdomain")] + [System.Text.Json.Serialization.JsonPropertyName("direct_webviewdomain")] + public string[]? DirectlyWebviewDomain { get; set; } + + /// + /// 获取或设置最后提交代码或者发布上线后生效的 Webview 域名列表。 + /// + [Newtonsoft.Json.JsonProperty("effective_webviewdomain")] + [System.Text.Json.Serialization.JsonPropertyName("effective_webviewdomain")] + public string[]? EffectiveWebviewDomain { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyRequest.cs new file mode 100644 index 00000000..e5772299 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyRequest.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/setwebviewdomain_directly 接口的请求。 + /// + public class WxaSetWebviewDomainDirectlyRequest : WechatApiRequest, IInferable + { + /// + /// 获取或设置操作类型。 + /// 默认值:get + /// + [Newtonsoft.Json.JsonProperty("action")] + [System.Text.Json.Serialization.JsonPropertyName("action")] + public string Action { get; set; } = "get"; + + /// + /// 获取或设置业务域名列表。 + /// + [Newtonsoft.Json.JsonProperty("webviewdomain")] + [System.Text.Json.Serialization.JsonPropertyName("webviewdomain")] + public IList? WebviewDomainList { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyResponse.cs new file mode 100644 index 00000000..8366c16c --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetWebviewDomainDirectlyResponse.cs @@ -0,0 +1,15 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/setwebviewdomain_directly 接口的响应。 + /// + public class WxaSetWebviewDomainDirectlyResponse : WechatApiResponse + { + /// + /// 获取或设置业务域名列表。 + /// + [Newtonsoft.Json.JsonProperty("webviewdomain")] + [System.Text.Json.Serialization.JsonPropertyName("webviewdomain")] + public string[]? WebviewDomainList { get; set; } + } +} diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveDomainResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveDomainResponse.json new file mode 100644 index 00000000..6103493f --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveDomainResponse.json @@ -0,0 +1,90 @@ +{ + "errcode": 0, + "errmsg": "ok", + "mp_domain": { + "requestdomain": [ + "https://melody1.qq.com" + ], + "wsrequestdomain": [ + "wss://melody2.qq.com" + ], + "uploaddomain": [ + "https://melody3.qq.com" + ], + "downloaddomain": [ + "https://melody4.qq.com" + ], + "udpdomain": [ + "udp://melody2.weixin.qq.com", + "udp://melody5.weixin.qq.com" + ], + "tcpdomain": [ + "tcp://melody2.weixin.qq.com", + "tcp://melody6.weixin.qq.com" + ] + }, + "third_domain": { + "requestdomain": [ + "https://melody1.qq.com" + ], + "wsrequestdomain": [ + "wss://melody2.qq.com" + ], + "uploaddomain": [ + "https://melody3.qq.com" + ], + "downloaddomain": [ + "https://melody4.qq.com" + ], + "udpdomain": [ + "udp://melody2.weixin.qq.com", + "udp://melody5.weixin.qq.com" + ], + "tcpdomain": [ + "tcp://melody2.weixin.qq.com", + "tcp://melody6.weixin.qq.com" + ] + }, + "direct_domain": { + "requestdomain": [ + "https://melody1.qq.com" + ], + "wsrequestdomain": [ + "wss://melody2.qq.com" + ], + "uploaddomain": [ + "https://melody3.qq.com" + ], + "downloaddomain": [ + "https://melody4.qq.com" + ], + "udpdomain": [ + "udp://melody5.weixin.qq.com" + ], + "tcpdomain": [ + "tcp://melody6.weixin.qq.com" + ] + }, + "effective_domain": { + "requestdomain": [ + "https://melody1.qq.com" + ], + "wsrequestdomain": [ + "wss://melody2.qq.com" + ], + "uploaddomain": [ + "https://melody3.qq.com" + ], + "downloaddomain": [ + "https://melody4.qq.com" + ], + "udpdomain": [ + "udp://melody2.weixin.qq.com", + "udp://melody5.weixin.qq.com" + ], + "tcpdomain": [ + "tcp://melody2.weixin.qq.com", + "tcp://melody6.weixin.qq.com" + ] + } +} diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.json new file mode 100644 index 00000000..fbbd5876 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetEffectiveWebviewDomainResponse.json @@ -0,0 +1,22 @@ +{ + "errcode": 0, + "errmsg": "ok", + "mp_webviewdomain": [ + "https://a.b.howielu.top", + "https://developers.weixin.qq.com", + "https://melody2.howielu.top/" + ], + "third_webviewdomain": [ + "https://a.b.howielu.top", + "https://developers.weixin.qq.com", + "https://melody2.howielu.top/" + ], + "direct_webviewdomain": [ + "https://melody2.howielu.top/" + ], + "effective_webviewdomain": [ + "https://a.b.howielu.top", + "https://developers.weixin.qq.com", + "https://melody2.howielu.top/" + ] +}