mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-18 04:33:16 +08:00
feat(wxapi): 新增小程序硬件设备相关接口
This commit is contained in:
parent
f51c2e2be2
commit
38bb973d41
@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
{
|
||||
public static class WechatApiClientExecuteCgibinMessageDeviceSubscribeExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /cgi-bin/message/device/subscribe/send 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/hardware-device/hardwareDevice.send.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.CgibinMessageDeviceSubscribeSendResponse> ExecuteCgibinMessageDeviceSubscribeSendAsync(this WechatApiClient client, Models.CgibinMessageDeviceSubscribeSendRequest 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", "message", "device", "subscribe", "send")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.CgibinMessageDeviceSubscribeSendResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -1080,5 +1080,27 @@ namespace SKIT.FlurlHttpClient.Wechat.Api
|
||||
return await client.SendRequestWithJsonAsync<Models.WxaDeleteStoreResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region HardwareDevice
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /wxa/getsnticket 接口。</para>
|
||||
/// <para>REF: https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/hardware-device/hardwareDevice.getSnTicket.html </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.WxaGetSnTicketResponse> ExecuteWxaGetSnTicketAsync(this WechatApiClient client, Models.WxaGetSnTicketRequest 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", "getsnticket")
|
||||
.SetQueryParam("access_token", request.AccessToken);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.WxaGetSnTicketResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/message/device/subscribe/send 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class CgibinMessageDeviceSubscribeSendRequest : WechatApiRequest
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class DataItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置消息内容文本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("value")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("value")]
|
||||
public string Value { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置接收消息的用户 OpenId 列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("to_openid_list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("to_openid_list")]
|
||||
public IList<string> ToUserOpenIdList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置订阅模板 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("template_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("template_id")]
|
||||
public string TemplateId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置设备序列号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("sn")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("sn")]
|
||||
public string SerialNumber { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置小程序页面路径。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("page")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("page")]
|
||||
public string? MiniProgramPagePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置小程序版本。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("miniprogram_state")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("miniprogram_state")]
|
||||
public string? MiniProgramState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置语言类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("lang")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("lang")]
|
||||
public string? Language { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置消息正文。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public IDictionary<string, Types.DataItem>? Data { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /cgi-bin/message/device/subscribe/send 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class CgibinMessageDeviceSubscribeSendResponse : WechatApiResponse
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /wxa/getsnticket 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class WxaGetSnTicketRequest : WechatApiRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置设备唯一序列号。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("sn")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("sn")]
|
||||
public string SerialNumber { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置设备型号 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("model_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("model_id")]
|
||||
public string ModelId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.Api.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /wxa/getsnticket 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class WxaGetSnTicketResponse : WechatApiResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置设备票据。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("sn_ticket")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("sn_ticket")]
|
||||
public string SnTicket { get; set; } = default!;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
{
|
||||
"touser": "OPENID",
|
||||
"template_id": "TEMPLATE_ID",
|
||||
"page": "index",
|
||||
"data": {
|
||||
"name01": {
|
||||
"value": "某某"
|
||||
},
|
||||
"amount01": {
|
||||
"value": "¥100"
|
||||
},
|
||||
"thing01": {
|
||||
"value": "广州至北京"
|
||||
},
|
||||
"date01": {
|
||||
"value": "2018-01-01"
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1 @@
|
||||
{}
|
@ -0,0 +1,4 @@
|
||||
{
|
||||
"model_id": "XXXXX",
|
||||
"sn": "XXXXX"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"sn_ticket": "XXXXX"
|
||||
}
|
Loading…
Reference in New Issue
Block a user