feat(wxapi): 新增网络检测接口

This commit is contained in:
Fu Diwei 2021-10-31 13:41:44 +08:00
parent 0e2e794f3a
commit 12d04f4241
5 changed files with 153 additions and 0 deletions

View File

@ -98,6 +98,26 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
return await client.SendRequestWithJsonAsync<Models.CgibinGetApiDomainIpResponse>(flurlReq, data: request, cancellationToken: cancellationToken); return await client.SendRequestWithJsonAsync<Models.CgibinGetApiDomainIpResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
} }
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/callback/check 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Network_Detection.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinCallbackCheckResponse> ExecuteCgibinCallbackCheckAsync(this WechatApiClient client, Models.CgibinCallbackCheckRequest 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", "callback", "check")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendRequestWithJsonAsync<Models.CgibinCallbackCheckResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
/// <summary> /// <summary>
/// <para>异步调用 [POST] /cgi-bin/clear_quota 接口。</para> /// <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/offiaccount/Message_Management/API_Call_Limits.html </para>

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/callback/check 接口的请求。</para>
/// </summary>
public class CgibinCallbackCheckRequest : WechatApiRequest
{
/// <summary>
/// 获取或设置执行的检测动作。
/// <para>默认值all</para>
/// </summary>
[Newtonsoft.Json.JsonProperty("action")]
[System.Text.Json.Serialization.JsonPropertyName("action")]
public string Action { get; set; } = "all";
/// <summary>
/// 获取或设置指定平台从某个运营商进行检测。
/// <para>默认值DEFAULT</para>
/// </summary>
[Newtonsoft.Json.JsonProperty("check_operator")]
[System.Text.Json.Serialization.JsonPropertyName("check_operator")]
public string CheckOperator { get; set; } = "DEFAULT";
}
}

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/callback/check 接口的响应。</para>
/// </summary>
public class CgibinCallbackCheckResponse : WechatApiResponse
{
public static class Types
{
public class DNS
{
/// <summary>
/// 获取或设置解析 IP。
/// </summary>
[Newtonsoft.Json.JsonProperty("ip")]
[System.Text.Json.Serialization.JsonPropertyName("ip")]
public string IP { get; set; } = default!;
/// <summary>
/// 获取或设置 IP 对应的运营商。
/// </summary>
[Newtonsoft.Json.JsonProperty("real_operator")]
[System.Text.Json.Serialization.JsonPropertyName("real_operator")]
public string RealOperator { get; set; } = default!;
}
public class Ping
{
/// <summary>
/// 获取或设置 ping IP。
/// </summary>
[Newtonsoft.Json.JsonProperty("ip")]
[System.Text.Json.Serialization.JsonPropertyName("ip")]
public string IP { get; set; } = default!;
/// <summary>
/// 获取或设置 IP 源头的运营商。
/// </summary>
[Newtonsoft.Json.JsonProperty("from_operator")]
[System.Text.Json.Serialization.JsonPropertyName("from_operator")]
public string FromOperator { get; set; } = default!;
/// <summary>
/// 获取或设置丢包率字符串。
/// </summary>
[Newtonsoft.Json.JsonProperty("package_loss")]
[System.Text.Json.Serialization.JsonPropertyName("package_loss")]
public string PackageLossString { get; set; } = default!;
/// <summary>
/// 获取或设置耗时字符串。
/// </summary>
[Newtonsoft.Json.JsonProperty("time")]
[System.Text.Json.Serialization.JsonPropertyName("time")]
public string TimeCostString { get; set; } = default!;
}
}
/// <summary>
/// 获取或设置 DNS 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("dns")]
[System.Text.Json.Serialization.JsonPropertyName("dns")]
public Types.DNS[]? DNSList { get; set; }
/// <summary>
/// 获取或设置 ping 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("ping")]
[System.Text.Json.Serialization.JsonPropertyName("ping")]
public Types.Ping[]? PingList { get; set; }
}
}

View File

@ -0,0 +1,4 @@
{
"action": "all",
"check_operator": "DEFAULT"
}

View File

@ -0,0 +1,26 @@
{
"dns": [
{
"ip": "111.161.64.40",
"real_operator": "UNICOM"
},
{
"ip": "111.161.64.48",
"real_operator": "UNICOM"
}
],
"ping": [
{
"ip": "111.161.64.40",
"from_operator": "UNICOM",
"package_loss": "0%",
"time": "23.079ms"
},
{
"ip": "111.161.64.48",
"from_operator": "UNICOM",
"package_loss": "0%",
"time": "21.434ms"
}
]
}