mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-19 10:29:56 +08:00
feat(wxapi): 新增获取稳定版接口调用凭据接口
This commit is contained in:
@@ -35,6 +35,33 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinTokenResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/stable_token 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html </para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-access-token/getStableAccessToken.html </para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/access-token/auth.getStableAccessToken.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinStableTokenResponse> ExecuteCgibinStableTokenAsync(this WechatApiClient client, Models.CgibinStableTokenRequest 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;
|
||||
|
||||
if (request.AppSecret == null)
|
||||
request.AppSecret = client.Credentials.AppSecret;
|
||||
|
||||
IFlurlRequest flurlReq = client
|
||||
.CreateRequest(request, HttpMethod.Post, "cgi-bin", "stable_token");
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinStableTokenResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /cgi-bin/ticket/getticket 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#54 </para>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/stable_token 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinStableTokenRequest : WechatApiRequest, IInferable<CgibinTokenRequest, CgibinTokenResponse>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppId。如果不指定将使用构造 <see cref="WechatApiClient"/> 时的 <see cref="WechatApiClientOptions.AppId"/> 参数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("appid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("appid")]
|
||||
public string? AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppSecret。如果不指定将使用构造 <see cref="WechatApiClient"/> 时的 <see cref="WechatApiClientOptions.AppSecret"/> 参数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("secret")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("secret")]
|
||||
public string? AppSecret { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// <i>(使用默认值即可,无需修改)</i>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("grant_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("grant_type")]
|
||||
public string GrantType { get; set; } = "client_credential";
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否强制刷新。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("force_refresh")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("force_refresh")]
|
||||
public bool ForceRefresh { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/stable_token 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinStableTokenResponse : CgibinTokenResponse
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
@@ -14,6 +14,15 @@ namespace SKIT.FlurlHttpClient.Wechat.Api.UnitTests
|
||||
Assert.NotNull(response.AccessToken);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:调用 API [POST] /cgi-bin/stable_token")]
|
||||
public async Task TestExecuteCgibinStableToken()
|
||||
{
|
||||
var request = new Models.CgibinStableTokenRequest();
|
||||
var response = await TestClients.Instance.ExecuteCgibinStableTokenAsync(request);
|
||||
|
||||
Assert.NotNull(response.AccessToken);
|
||||
}
|
||||
|
||||
[Fact(DisplayName = "测试用例:调用 API [GET] /cgi-bin/ticket/getticket")]
|
||||
public async Task TestExecuteCgibinTicketGetTicket()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user