mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-09-19 10:08:20 +08:00
feat(wxapi): 新增小程序重置登录态接口
This commit is contained in:
@@ -13,6 +13,7 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
/// <para>异步调用 [GET] /wxa/checksession 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/checkSessionKey.html ]]>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.checkSessionKey.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
@@ -35,6 +36,33 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.WxaCheckSessionResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /wxa/resetusersessionkey 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-login/ResetUserSessionKey.html ]]> <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/minigame/dev/api-backend/open-api/login/auth.ResetUserSessionKey.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.WxaResetUserSessionKeyResponse> ExecuteWxaResetUserSessionKeyAsync(this WechatApiClient client, Models.WxaResetUserSessionKeyRequest 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
|
||||
.CreateFlurlRequest(request, HttpMethod.Get, "wxa", "resetusersessionkey")
|
||||
.SetQueryParam("access_token", request.AccessToken)
|
||||
.SetQueryParam("openid", request.OpenId)
|
||||
.SetQueryParam("signature", request.Signature)
|
||||
.SetQueryParam("sig_method", request.SignMethod);
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.WxaResetUserSessionKeyResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [GET] /wxa/getpaidunionid 接口。</para>
|
||||
/// <para>
|
||||
|
@@ -1,4 +1,6 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
using System;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /wxa/checksession 接口的请求。</para>
|
||||
@@ -21,10 +23,27 @@
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户登录态签名的哈希方法。
|
||||
/// <para>默认值:hmac_sha256</para>
|
||||
/// <para>默认值:"hmac_sha256"</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string SignMethod { get; set; } = "hmac_sha256";
|
||||
|
||||
public void SetSignatureBySessionKey(string sessionKey, string signMethod = "hmac_sha256")
|
||||
{
|
||||
if (sessionKey is null) throw new ArgumentNullException(nameof(sessionKey));
|
||||
if (signMethod is null) throw new ArgumentNullException(nameof(signMethod));
|
||||
|
||||
switch (signMethod)
|
||||
{
|
||||
case "hmac_sha256":
|
||||
Signature = Utilities.HMACUtility.HashWithSHA256(sessionKey, string.Empty).Value!.ToLower();
|
||||
SignMethod = signMethod;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /wxa/resetusersessionkey 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class WxaResetUserSessionKeyRequest : WechatApiRequest, IInferable<WxaResetUserSessionKeyRequest, WxaResetUserSessionKeyResponse>
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户唯一标识。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string OpenId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户登录态签名。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string Signature { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户登录态签名的哈希方法。
|
||||
/// <para>默认值:"hmac_sha256"</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonIgnore]
|
||||
[System.Text.Json.Serialization.JsonIgnore]
|
||||
public string SignMethod { get; set; } = "hmac_sha256";
|
||||
|
||||
public void SetSignatureBySessionKey(string sessionKey, string signMethod = "hmac_sha256")
|
||||
{
|
||||
if (sessionKey is null) throw new ArgumentNullException(nameof(sessionKey));
|
||||
if (signMethod is null) throw new ArgumentNullException(nameof(signMethod));
|
||||
|
||||
switch (signMethod)
|
||||
{
|
||||
case "hmac_sha256":
|
||||
Signature = Utilities.HMACUtility.HashWithSHA256(sessionKey, string.Empty).Value!.ToLower();
|
||||
SignMethod = signMethod;
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [GET] /wxa/resetusersessionkey 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class WxaResetUserSessionKeyResponse : WechatApiResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户唯一标识。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("openid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("openid")]
|
||||
public string OpenId { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置重置后的会话密钥。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("session_key")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("session_key")]
|
||||
public string SessionKey { get; set; } = default!;
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"errcode": 0,
|
||||
"errmsg": "ok",
|
||||
"openid": "xxxxxxx",
|
||||
"session_key": "xxxxxxxx"
|
||||
}
|
Reference in New Issue
Block a user