feat(wxapi): 新增第三方平台服务器域名相关接口

This commit is contained in:
Fu Diwei 2021-11-20 14:15:59 +08:00
parent 093e6bf2d7
commit aa3d766284
21 changed files with 487 additions and 1 deletions

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Newtonsoft.Json.Converters
{
internal class TextualStringArrayWithSemicolonConverter : JsonConverter<string[]?>
{
private readonly JsonConverter<List<string>?> _converter = new TextualStringListWithSemicolonConverter();
public override bool CanRead
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override string[]? ReadJson(JsonReader reader, Type objectType, string[]? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
return _converter.ReadJson(reader, objectType, existingValue?.ToList(), hasExistingValue, serializer)?.ToArray();
}
public override void WriteJson(JsonWriter writer, string[]? value, JsonSerializer serializer)
{
_converter.WriteJson(writer, value?.ToList(), serializer);
}
}
}

View File

@ -7,7 +7,7 @@ namespace Newtonsoft.Json.Converters
{
internal class TextualInt32IListConverter : JsonConverter<IList<int>?>
{
private readonly JsonConverter<List<int>?> _converter = new StringTypedInt32ListConverter();
private readonly JsonConverter<List<int>?> _converter = new TextualInt32ListConverter();
public override bool CanRead
{

View File

@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Newtonsoft.Json.Converters
{
internal class TextualStringIListWithSemicolonConverter : JsonConverter<IList<string>?>
{
private readonly JsonConverter<List<string>?> _converter = new TextualStringListWithSemicolonConverter();
public override bool CanRead
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override IList<string>? ReadJson(JsonReader reader, Type objectType, IList<string>? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
return _converter.ReadJson(reader, objectType, ConvertIListToList(existingValue), hasExistingValue, serializer);
}
public override void WriteJson(JsonWriter writer, IList<string>? value, JsonSerializer serializer)
{
_converter.WriteJson(writer, ConvertIListToList(value), serializer);
}
private List<string>? ConvertIListToList(IList<string>? src)
{
if (src == null)
return null;
List<string>? dest = src as List<string>;
if (dest != null)
return dest;
return new List<string>(src);
}
}
}

View File

@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace Newtonsoft.Json.Converters
{
internal class TextualStringListWithSemicolonConverter : JsonConverter<List<string>?>
{
public override bool CanRead
{
get { return true; }
}
public override bool CanWrite
{
get { return true; }
}
public override List<string>? ReadJson(JsonReader reader, Type objectType, List<string>? existingValue, bool hasExistingValue, JsonSerializer serializer)
{
if (reader.TokenType == JsonToken.Null)
{
return null;
}
else if (reader.TokenType == JsonToken.String)
{
string? value = serializer.Deserialize<string>(reader);
if (value == null)
return existingValue;
return value.Split(';').ToList();
}
throw new JsonReaderException();
}
public override void WriteJson(JsonWriter writer, List<string>? value, JsonSerializer serializer)
{
if (value != null)
writer.WriteValue(string.Join(";", value));
else
writer.WriteNull();
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace System.Text.Json.Converters
{
internal class TextualStringArrayWithSemicolonConverter : JsonConverter<string[]?>
{
private readonly JsonConverter<List<string>?> _converter = new TextualStringListWithSemicolonConverter();
public override string[]? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return _converter.Read(ref reader, typeToConvert, options)?.ToArray();
}
public override void Write(Utf8JsonWriter writer, string[]? value, JsonSerializerOptions options)
{
_converter.Write(writer, value?.ToList(), options);
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace System.Text.Json.Converters
{
internal class TextualStringIListWithSemicolonConverter : JsonConverter<IList<string>?>
{
private readonly JsonConverter<List<string>?> _converter = new TextualStringListWithSemicolonConverter();
public override IList<string>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
return _converter.Read(ref reader, typeToConvert, options)?.ToArray();
}
public override void Write(Utf8JsonWriter writer, IList<string>? value, JsonSerializerOptions options)
{
_converter.Write(writer, value?.ToList(), options);
}
}
}

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace System.Text.Json.Converters
{
internal class TextualStringListWithSemicolonConverter : JsonConverter<List<string>?>
{
public override List<string>? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.Null)
{
return null;
}
else if (reader.TokenType == JsonTokenType.String)
{
string? value = reader.GetString();
if (value == null)
return null;
return value.Split(';').ToList();
}
throw new JsonException();
}
public override void Write(Utf8JsonWriter writer, List<string>? value, JsonSerializerOptions options)
{
if (value != null)
writer.WriteStringValue(string.Join(";", value));
else
writer.WriteNullValue();
}
}
}

View File

@ -263,5 +263,65 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
return await client.SendRequestWithJsonAsync<Models.CgibinComponentFastRegisterWeappSearchResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/component/modify_wxa_server_domain 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/modify_server_domain.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinComponentModifyWxaServerDomainResponse> ExecuteCgibinComponentModifyWxaServerDomainAsync(this WechatApiClient client, Models.CgibinComponentModifyWxaServerDomainRequest 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, "cgi-bin", "component", "modify_wxa_server_domain")
.SetQueryParam("access_token", request.ComponentAccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinComponentModifyWxaServerDomainResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/component/get_domain_confirmfile 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/get_domain_confirmfile.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinComponentGetDomainConfirmFileResponse> ExecuteCgibinComponentGetDomainConfirmFileAsync(this WechatApiClient client, Models.CgibinComponentGetDomainConfirmFileRequest 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, "cgi-bin", "component", "get_domain_confirmfile")
.SetQueryParam("access_token", request.ComponentAccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinComponentGetDomainConfirmFileResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/component/modify_wxa_jump_domain 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/ThirdParty/domain/modify_jump_domain.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinComponentModifyWxaJumpDomainResponse> ExecuteCgibinComponentModifyWxaJumpDomainAsync(this WechatApiClient client, Models.CgibinComponentModifyWxaJumpDomainRequest 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, "cgi-bin", "component", "modify_wxa_jump_domain")
.SetQueryParam("access_token", request.ComponentAccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinComponentModifyWxaJumpDomainResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
}
}

View File

@ -14,6 +14,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/clear_quota 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/Message_Management/API_Call_Limits.html </para>
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/openApi/clear_quota.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
@ -37,6 +38,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/openapi/quota/get 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/openApi/get_api_quota.html </para>
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/openApi/get_api_quota.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
@ -57,6 +59,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/openapi/rid/get 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/openApi/get_rid_info.html </para>
/// <para>REF: https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/openApi/get_rid_info.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>

View File

@ -0,0 +1,15 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/component/get_domain_confirmfile 接口的请求。</para>
/// </summary>
public class CgibinComponentGetDomainConfirmFileRequest : WechatApiRequest
{
/// <summary>
/// 获取或设置第三方平台 AccessToken。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string ComponentAccessToken { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/component/get_domain_confirmfile 接口的响应。</para>
/// </summary>
public class CgibinComponentGetDomainConfirmFileResponse : WechatApiResponse
{
/// <summary>
/// 获取或设置文件名。
/// </summary>
[Newtonsoft.Json.JsonProperty("file_name")]
[System.Text.Json.Serialization.JsonPropertyName("file_name")]
public string FileName { get; set; } = default!;
/// <summary>
/// 获取或设置文件内容。
/// </summary>
[Newtonsoft.Json.JsonProperty("file_content")]
[System.Text.Json.Serialization.JsonPropertyName("file_content")]
public string FileContent { get; set; } = default!;
}
}

View File

@ -0,0 +1,40 @@
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/component/modify_wxa_jump_domain 接口的请求。</para>
/// </summary>
public class CgibinComponentModifyWxaJumpDomainRequest : WechatApiRequest
{
/// <summary>
/// 获取或设置第三方平台 AccessToken。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string ComponentAccessToken { get; set; } = string.Empty;
/// <summary>
/// 获取或设置操作类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("action")]
[System.Text.Json.Serialization.JsonPropertyName("action")]
public string Action { get; set; } = string.Empty;
/// <summary>
/// 获取或设置是否同时修改全网发布版本的值。
/// </summary>
[Newtonsoft.Json.JsonProperty("is_modify_published_together")]
[System.Text.Json.Serialization.JsonPropertyName("is_modify_published_together")]
public bool? IsModifyPublishedTogether { get; set; }
/// <summary>
/// 获取或设置业务域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("wxa_jump_h5_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringIListWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("wxa_jump_h5_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringIListWithSemicolonConverter))]
public IList<string>? WxaJumpH5DomainList { get; set; }
}
}

View File

@ -0,0 +1,35 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/component/modify_wxa_jump_domain 接口的响应。</para>
/// </summary>
public class CgibinComponentModifyWxaJumpDomainResponse : WechatApiResponse
{
/// <summary>
/// 获取或设置目前生效的全网发布版第三方平台小程序业务域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("published_wxa_jump_h5_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringArrayWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("published_wxa_jump_h5_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringArrayWithSemicolonConverter))]
public string[]? PublishedWxaJumpH5DomainList { get; set; }
/// <summary>
/// 获取或设置目前生效的测试版第三方平台小程序业务域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("testing_wxa_jump_h5_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringArrayWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("testing_wxa_jump_h5_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringArrayWithSemicolonConverter))]
public string[]? TestingWxaJumpH5DomainList { get; set; }
/// <summary>
/// 获取或设置未通过验证的第三方平台小程序业务域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("invalid_wxa_jump_h5_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringArrayWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("invalid_wxa_jump_h5_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringArrayWithSemicolonConverter))]
public string[]? InvalidWxaJumpH5DomainList { get; set; }
}
}

View File

@ -0,0 +1,40 @@
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/component/modify_wxa_server_domain 接口的请求。</para>
/// </summary>
public class CgibinComponentModifyWxaServerDomainRequest : WechatApiRequest
{
/// <summary>
/// 获取或设置第三方平台 AccessToken。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string ComponentAccessToken { get; set; } = string.Empty;
/// <summary>
/// 获取或设置操作类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("action")]
[System.Text.Json.Serialization.JsonPropertyName("action")]
public string Action { get; set; } = string.Empty;
/// <summary>
/// 获取或设置是否同时修改全网发布版本的值。
/// </summary>
[Newtonsoft.Json.JsonProperty("is_modify_published_together")]
[System.Text.Json.Serialization.JsonPropertyName("is_modify_published_together")]
public bool? IsModifyPublishedTogether { get; set; }
/// <summary>
/// 获取或设置服务器域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("wxa_server_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringIListWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("wxa_server_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringIListWithSemicolonConverter))]
public IList<string>? WxaServerDomainList { get; set; }
}
}

View File

@ -0,0 +1,35 @@
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/component/modify_wxa_server_domain 接口的响应。</para>
/// </summary>
public class CgibinComponentModifyWxaServerDomainResponse : WechatApiResponse
{
/// <summary>
/// 获取或设置目前生效的全网发布版第三方平台小程序服务器域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("published_wxa_server_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringArrayWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("published_wxa_server_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringArrayWithSemicolonConverter))]
public string[]? PublishedWxaServerDomainList { get; set; }
/// <summary>
/// 获取或设置目前生效的测试版第三方平台小程序服务器域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("testing_wxa_server_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringArrayWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("testing_wxa_server_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringArrayWithSemicolonConverter))]
public string[]? TestingWxaServerDomainList { get; set; }
/// <summary>
/// 获取或设置未通过验证的第三方平台小程序服务器域名列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("invalid_wxa_server_domain")]
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.TextualStringArrayWithSemicolonConverter))]
[System.Text.Json.Serialization.JsonPropertyName("invalid_wxa_server_domain")]
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Converters.TextualStringArrayWithSemicolonConverter))]
public string[]? InvalidWxaServerDomainList { get; set; }
}
}

View File

@ -0,0 +1,6 @@
{
"errcode": 0,
"errmsg": "ok",
"file_name": "xxx",
"file_content": "xxxxxx"
}

View File

@ -0,0 +1,5 @@
{
"action": "delete",
"is_modify_published_together": false,
"wxa_jump_h5_domain": "www.qq.com;wx.qq.com"
}

View File

@ -0,0 +1,6 @@
{
"errcode": 0,
"errmsg": "ok",
"published_wxa_jump_h5_domain": "www.qq.com;wx.qq.com",
"testing_wxa_jump_h5_domain": "www.qq.com;wx.qq.com"
}

View File

@ -0,0 +1,5 @@
{
"action": "add",
"is_modify_published_together": true,
"wxa_server_domain": "www.qq.com;wx.qq.com"
}

View File

@ -0,0 +1,6 @@
{
"errcode": 0,
"errmsg": "ok",
"published_wxa_server_domain": "www.qq.com;wx.qq.com",
"testing_wxa_server_domain": "www.qq.com;wx.qq.com"
}