feat(wxapi): 新增小程序重置登录态接口

This commit is contained in:
Fu Diwei
2024-06-20 16:14:22 +08:00
parent d05fc8437c
commit 2a50fafa0a
5 changed files with 126 additions and 2 deletions

View File

@@ -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();
}
}
}
}

View File

@@ -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();
}
}
}
}

View File

@@ -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!;
}
}