using System; using System.Collections.Generic; using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; using Flurl; using Flurl.Http; namespace SKIT.FlurlHttpClient.Wechat.Work { public static class WechatWorkClientExecuteCgibinMessageExtensions { /// /// 异步调用 [POST] /cgi-bin/message/send 接口。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/90236 /// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/90372 /// REF: https://open.work.weixin.qq.com/api/doc/90002/90151/90854 /// /// /// /// /// public static async Task ExecuteCgibinMessageSendAsync(this WechatWorkClient client, Models.CgibinMessageSendRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); if (!request.AgentId.HasValue) request.AgentId = client.Credentials.AgentId; IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "cgi-bin", "message", "send"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/message/update_taskcard 接口。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/91579 /// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/91585 /// /// /// /// /// public static async Task ExecuteCgibinMessageUpdateTaskCardAsync(this WechatWorkClient client, Models.CgibinMessageUpdateTaskCardRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); if (!request.AgentId.HasValue) request.AgentId = client.Credentials.AgentId; IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "cgi-bin", "message", "update_taskcard"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/message/update_template_card 接口。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/94888 /// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/94888 /// /// /// /// /// public static async Task ExecuteCgibinMessageUpdateTemplateCardAsync(this WechatWorkClient client, Models.CgibinMessageUpdateTemplateCardRequest request, CancellationToken cancellationToken = default) { if (client is null) throw new ArgumentNullException(nameof(client)); if (request is null) throw new ArgumentNullException(nameof(request)); if (!request.AgentId.HasValue) request.AgentId = client.Credentials.AgentId; IFlurlRequest flurlReq = client .CreateRequest(request, HttpMethod.Post, "cgi-bin", "message", "update_template_card"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/message/get_statistics 接口。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/92369 /// /// /// /// /// public static async Task ExecuteCgibinMessageGetStatisticsAsync(this WechatWorkClient client, Models.CgibinMessageGetStatisticsRequest 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", "get_statistics"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } /// /// 异步调用 [POST] /cgi-bin/message/recall 接口。 /// REF: https://open.work.weixin.qq.com/api/doc/90000/90135/94867 /// REF: https://open.work.weixin.qq.com/api/doc/90001/90143/94867 /// /// /// /// /// public static async Task ExecuteCgibinMessageRecallAsync(this WechatWorkClient client, Models.CgibinMessageRecallRequest 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", "recall"); return await client.SendRequestWithJsonAsync(flurlReq, data: request, cancellationToken: cancellationToken); } } }