mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-12-22 03:19:55 +08:00
87 lines
4.0 KiB
C#
87 lines
4.0 KiB
C#
using System;
|
|
using System.Net.Http;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Flurl.Http;
|
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
|
{
|
|
public static class WechatOpenAIClientExecuteThirdKefuExtensions
|
|
{
|
|
/// <summary>
|
|
/// <para>异步调用 [POST] /sendmsg/{TOKEN} 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/thirdkefu/sendmsg.html ]]>
|
|
/// </para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.SendMessageResponse> ExecuteSendMessageAsync(this WechatOpenAIClient client, Models.SendMessageRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.AppId is null)
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Post, "sendmsg", client.Credentials.Token!);
|
|
|
|
return await client.SendFlurlRequestAsJsonAsync<Models.SendMessageResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>异步调用 [POST] /kefustate/get/{TOKEN} 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/thirdkefu/getstate.html ]]>
|
|
/// </para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.KefuStateGetResponse> ExecuteKefuStateGetAsync(this WechatOpenAIClient client, Models.KefuStateGetRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.AppId is null)
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Post, "kefustate", "get", client.Credentials.Token!);
|
|
|
|
return await client.SendFlurlRequestAsJsonAsync<Models.KefuStateGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
}
|
|
|
|
/// <summary>
|
|
/// <para>异步调用 [POST] /kefustate/change/{TOKEN} 接口。</para>
|
|
/// <para>
|
|
/// REF: <br/>
|
|
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/thirdkefu/changestate.html ]]>
|
|
/// </para>
|
|
/// </summary>
|
|
/// <param name="client"></param>
|
|
/// <param name="request"></param>
|
|
/// <param name="cancellationToken"></param>
|
|
/// <returns></returns>
|
|
public static async Task<Models.KefuStateChangeResponse> ExecuteKefuStateChangeAsync(this WechatOpenAIClient client, Models.KefuStateChangeRequest request, CancellationToken cancellationToken = default)
|
|
{
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
if (request.AppId is null)
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
IFlurlRequest flurlReq = client
|
|
.CreateFlurlRequest(request, HttpMethod.Post, "kefustate", "change", client.Credentials.Token!);
|
|
|
|
return await client.SendFlurlRequestAsJsonAsync<Models.KefuStateChangeResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
}
|
|
}
|
|
}
|