feat(wxapi): 新增小程序获取用户加密 Key 相关接口

This commit is contained in:
Fu Diwei 2021-07-21 11:31:35 +08:00
parent bf610f8f20
commit cbd1b8a935
3 changed files with 117 additions and 0 deletions

View File

@ -222,5 +222,30 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
return await client.SendRequestWithJsonAsync<Models.WxaBusinessRuntimeAddDeviceResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#endregion
#region Internet
/// <summary>
/// <para>异步调用 [POST] /wxa/business/getuserencryptkey 接口。</para>
/// <para>REF: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/internet/internet.getUserEncryptKey.html </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.WxaBusinessGetUserEncryptKeyResponse> ExecuteWxaBusinessGetUserEncryptKeyAsync(this WechatApiClient client, Models.WxaBusinessGetUserEncryptKeyRequest 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, "wxa", "business", "getuserencryptkey")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("openid", request.OpenId)
.SetQueryParam("signature", request.Signature)
.SetQueryParam("sig_method", request.SignMethod);
return await client.SendRequestWithJsonAsync<Models.WxaBusinessGetUserEncryptKeyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
}
#endregion
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /wxa/business/getuserencryptkey 接口的请求。</para>
/// </summary>
public class WxaBusinessGetUserEncryptKeyRequest : WechatApiRequest
{
/// <summary>
/// 获取或设置用户 OpenId。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string OpenId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置用 SessionKey 对空字符串签名得到的结果。
/// </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";
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
{
/// <summary>
/// <para>表示 [POST] /wxa/business/getuserencryptkey 接口的响应。</para>
/// </summary>
public class WxaBusinessGetUserEncryptKeyResponse : WechatApiResponse
{
public static class Types
{
public class Key
{
/// <summary>
/// 获取或设置加密 Key。
/// </summary>
[Newtonsoft.Json.JsonProperty("encrypt_key")]
[System.Text.Json.Serialization.JsonPropertyName("encrypt_key")]
public string EncryptKey { get; set; } = default!;
/// <summary>
/// 获取或设置加密 IV。
/// </summary>
[Newtonsoft.Json.JsonProperty("iv")]
[System.Text.Json.Serialization.JsonPropertyName("iv")]
public string IV { get; set; } = default!;
/// <summary>
/// 获取或设置版本号。
/// </summary>
[Newtonsoft.Json.JsonProperty("version")]
[System.Text.Json.Serialization.JsonPropertyName("version")]
public int Version { get; set; }
/// <summary>
/// 获取或设置剩余有效时间(单位:秒)。
/// </summary>
[Newtonsoft.Json.JsonProperty("expire_in")]
[System.Text.Json.Serialization.JsonPropertyName("expire_in")]
public int ExpiresIn { get; set; }
/// <summary>
/// 获取或设置创建时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("create_time")]
[System.Text.Json.Serialization.JsonPropertyName("create_time")]
public long CreateTimestamp { get; set; }
}
}
/// <summary>
/// 获取或设置用户最近的加密 Key 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("key_info_list")]
[System.Text.Json.Serialization.JsonPropertyName("key_info_list")]
public Types.Key[] KeyList { get; set; } = default!;
}
}