diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs index 13480ebe..80d38020 100644 --- a/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Extensions/WechatApiClientExecuteWxaComponentExtensions.cs @@ -251,6 +251,46 @@ namespace SKIT.FlurlHttpClient.Wechat.Api return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } + + /// + /// 异步调用 [GET] /wxa/get_prefetchdnsdomain 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/getPrefetchDomain.html + /// + /// + /// + /// + /// + public static async Task ExecuteWxaGetPrefetchDNSDomainAsync(this WechatApiClient client, Models.WxaGetPrefetchDNSDomainRequest 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.Get, "wxa", "get_prefetchdnsdomain") + .SetQueryParam("access_token", request.AccessToken); + + return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); + } + + /// + /// 异步调用 [POST] /wxa/set_prefetchdnsdomain 接口。 + /// REF: https://developers.weixin.qq.com/doc/oplatform/openApi/OpenApiDoc/miniprogram-management/domain-management/setPrefetchDomain.html + /// + /// + /// + /// + /// + public static async Task ExecuteWxaSetPrefetchDNSDomainAsync(this WechatApiClient client, Models.WxaSetPrefetchDNSDomainRequest 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", "set_prefetchdnsdomain") + .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/WxaGetPrefetchDNSDomainRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetPrefetchDNSDomainRequest.cs new file mode 100644 index 00000000..a302f502 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetPrefetchDNSDomainRequest.cs @@ -0,0 +1,9 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [GET] /wxa/get_prefetchdnsdomain 接口的请求。 + /// + public class WxaGetPrefetchDNSDomainRequest : WechatApiRequest, IInferable + { + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetPrefetchDNSDomainResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetPrefetchDNSDomainResponse.cs new file mode 100644 index 00000000..d2c3c5d3 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaGetPrefetchDNSDomainResponse.cs @@ -0,0 +1,42 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [GET] /wxa/get_prefetchdnsdomain 接口的响应。 + /// + public class WxaGetPrefetchDNSDomainResponse : WechatApiResponse + { + public static class Types + { + public class PrefetchDNSDomain + { + /// + /// 获取或设置地址。 + /// + [Newtonsoft.Json.JsonProperty("url")] + [System.Text.Json.Serialization.JsonPropertyName("url")] + public string Url { get; set; } = default!; + + /// + /// 获取或设置状态。 + /// + [Newtonsoft.Json.JsonProperty("status")] + [System.Text.Json.Serialization.JsonPropertyName("status")] + public int Status { get; set; } + } + } + + /// + /// 获取或设置预解析 DNS 域名列表。 + /// + [Newtonsoft.Json.JsonProperty("prefetch_dns_domain")] + [System.Text.Json.Serialization.JsonPropertyName("prefetch_dns_domain")] + public Types.PrefetchDNSDomain[] PrefetchDNSDomainList { get; set; } = default!; + + /// + /// 获取或设置总共可配置域名个数。 + /// + [Newtonsoft.Json.JsonProperty("size_limit")] + [System.Text.Json.Serialization.JsonPropertyName("size_limit")] + public int SizeLimit { get; set; } + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetPrefetchDNSDomainRequest.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetPrefetchDNSDomainRequest.cs new file mode 100644 index 00000000..fa00b51b --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetPrefetchDNSDomainRequest.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/set_prefetchdnsdomain 接口的请求。 + /// + public class WxaSetPrefetchDNSDomainRequest : WechatApiRequest, IInferable + { + public static class Types + { + public class PrefetchDNSDomain + { + /// + /// 获取或设置地址。 + /// + [Newtonsoft.Json.JsonProperty("url")] + [System.Text.Json.Serialization.JsonPropertyName("url")] + public string Url { get; set; } = string.Empty; + } + } + + /// + /// 获取或设置预解析 DNS 域名列表。 + /// + [Newtonsoft.Json.JsonProperty("prefetch_dns_domain")] + [System.Text.Json.Serialization.JsonPropertyName("prefetch_dns_domain")] + public IList PrefetchDNSDomainList { get; set; } = new List(); + } +} diff --git a/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetPrefetchDNSDomainResponse.cs b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetPrefetchDNSDomainResponse.cs new file mode 100644 index 00000000..668a6d20 --- /dev/null +++ b/src/SKIT.FlurlHttpClient.Wechat.Api/Models/WxaComponent/Domain/WxaSetPrefetchDNSDomainResponse.cs @@ -0,0 +1,9 @@ +namespace SKIT.FlurlHttpClient.Wechat.Api.Models +{ + /// + /// 表示 [POST] /wxa/set_prefetchdnsdomain 接口的响应。 + /// + public class WxaSetPrefetchDNSDomainResponse : WechatApiResponse + { + } +} diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetPrefetchDNSDomainResponse.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetPrefetchDNSDomainResponse.json new file mode 100644 index 00000000..9a10e2b8 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaGetPrefetchDNSDomainResponse.json @@ -0,0 +1,15 @@ +{ + "errcode": 0, + "errmsg": "ok", + "prefetch_dns_domain": [ + { + "url": "d1.com", + "status": 0 + }, + { + "url": "d2.com", + "status": 0 + } + ], + "size_limit": 5 +} diff --git a/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaSetPrefetchDNSDomainRequest.json b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaSetPrefetchDNSDomainRequest.json new file mode 100644 index 00000000..7bf2a8c8 --- /dev/null +++ b/test/SKIT.FlurlHttpClient.Wechat.Api.UnitTests/ModelSamples/WxaComponent/Domain/WxaSetPrefetchDNSDomainRequest.json @@ -0,0 +1,10 @@ +{ + "prefetch_dns_domain": [ + { + "url": "d1.com" + }, + { + "url": "d2.com" + } + ] +}