mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-15 23:13:32 +08:00
feat(wxapi): 新增 OpenAPI 管理相关接口
This commit is contained in:
parent
12d04f4241
commit
02071c04ed
@ -118,29 +118,6 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinCallbackCheckResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/clear_quota 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/Message_Management/API_Call_Limits.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinClearQuotaResponse> ExecuteCgibinClearQuotaAsync(this WechatApiClient client, Models.CgibinClearQuotaRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (request.AppId == null)
|
||||
request.AppId = client.Credentials.AppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "clear_quota")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinClearQuotaResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/changeopenid 接口。</para>
|
||||
/// <para>REF: https://kf.qq.com/faq/1901177NrqMr190117nqYJze.html </para>
|
||||
|
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
{
|
||||
public static class WechatApiClientExecuteCgibinOpenApiExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/clear_quota 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/Message_Management/API_Call_Limits.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinClearQuotaResponse> ExecuteCgibinClearQuotaAsync(this WechatApiClient client, Models.CgibinClearQuotaRequest request, CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (client is null) throw new ArgumentNullException(nameof(client));
|
||||
if (request is null) throw new ArgumentNullException(nameof(request));
|
||||
|
||||
if (request.AppId == null)
|
||||
request.AppId = client.Credentials.AppId;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "clear_quota")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinClearQuotaResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/openapi/quota/get 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/openApi/get_api_quota.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinOpenApiQuotaGetResponse> ExecuteCgibinOpenApiQuotaGetAsync(this WechatApiClient client, Models.CgibinOpenApiQuotaGetRequest 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", "openapi", "quota", "get")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinOpenApiQuotaGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/openapi/rid/get 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/openApi/get_rid_info.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinOpenApiRequestIdGetResponse> ExecuteCgibinOpenApiRequestIdGetAsync(this WechatApiClient client, Models.CgibinOpenApiRequestIdGetRequest 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", "openapi", "rid", "get")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinOpenApiRequestIdGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/openapi/quota/get 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinOpenApiQuotaGetRequest : WechatApiRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置 API 请求地址。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("cgi_path")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("cgi_path")]
|
||||
public string CgiPath { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/openapi/quota/get 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinOpenApiQuotaGetResponse : WechatApiResponse
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Quota
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置当天该账号可调用该接口的次数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("daily_limit")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("daily_limit")]
|
||||
public int DailyLimit { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置当天已经调用的次数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("used")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("used")]
|
||||
public int UsedCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置当天剩余调用次数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("remain")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("remain")]
|
||||
public int RemainCount { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置额度信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("quota")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("quota")]
|
||||
public Types.Quota Quota { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/openapi/rid/get 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinOpenApiRequestIdGetRequest : WechatApiRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置调用接口报错返回的 rid。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("rid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("rid")]
|
||||
public string RequestId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/openapi/rid/get 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinOpenApiRequestIdGetResponse : WechatApiResponse
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置请求 URL。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("request_url")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("request_url")]
|
||||
public string RequestUrl { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求参数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("request_body")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("request_body")]
|
||||
public string RequestBody { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置返回参数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("response_body")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("response_body")]
|
||||
public string ResponseBody { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置发起请求的时间戳。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("invoke_time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("invoke_time")]
|
||||
public long InvokeTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求耗时(单位:毫秒)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("cost_in_ms")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("cost_in_ms")]
|
||||
public int CostTime { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("request")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("request")]
|
||||
public Types.Request Request { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"cgi_path": "/wxa/gettemplatedraftlist"
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"quota": {
|
||||
"daily_limit": 0,
|
||||
"used": 0,
|
||||
"remain": 0
|
||||
}
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"rid": "61725984-6126f6f9-040f19c4"
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"request": {
|
||||
"invoke_time": 1635156704,
|
||||
"cost_in_ms": 30,
|
||||
"request_url": "access_token=50_Im7xxxx",
|
||||
"request_body": "",
|
||||
"response_body": "{\"errcode\":45009,\"errmsg\":\"reach max api daily quota limit rid: 617682e0-09059ac5-34a8e2ea\"}"
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user