2021-10-09 15:17:35 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Flurl.Http;
|
|
|
|
|
|
|
|
|
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
|
|
|
|
{
|
|
|
|
|
public static class WechatOpenAIClientExecuteOpenApiThirdKfExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>异步调用 [POST] /openapi/sendmsg/{TOKEN} 接口。</para>
|
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/sendmsg.html </para>
|
2021-10-11 11:53:22 +08:00
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/sendmsg.html </para>
|
2021-10-09 15:17:35 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<Models.OpenApiSendMessageResponse> ExecuteOpenApiSendMessageAsync(this WechatOpenAIClient client, Models.OpenApiSendMessageRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
|
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
|
|
2021-10-09 16:57:16 +08:00
|
|
|
|
if (request.AppId == null)
|
|
|
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
|
|
2021-10-09 15:17:35 +08:00
|
|
|
|
IFlurlRequest flurlReq = client
|
2021-10-11 18:34:21 +08:00
|
|
|
|
.CreateRequest(request, HttpMethod.Post, "openapi", "sendmsg", client.Credentials.Token!);
|
2021-10-09 15:17:35 +08:00
|
|
|
|
|
|
|
|
|
return await client.SendRequestWithJsonAsync<Models.OpenApiSendMessageResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>异步调用 [POST] /openapi/kefustate/get/{TOKEN} 接口。</para>
|
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/getstate.html </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<Models.OpenApiKefuStateGetResponse> ExecuteOpenApiKefuStateGetAsync(this WechatOpenAIClient client, Models.OpenApiKefuStateGetRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
|
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
|
|
2021-10-09 16:57:16 +08:00
|
|
|
|
if (request.AppId == null)
|
|
|
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
|
|
2021-10-09 15:17:35 +08:00
|
|
|
|
IFlurlRequest flurlReq = client
|
2021-10-11 18:34:21 +08:00
|
|
|
|
.CreateRequest(request, HttpMethod.Post, "openapi", "kefustate", "get", client.Credentials.Token!);
|
2021-10-09 15:17:35 +08:00
|
|
|
|
|
|
|
|
|
return await client.SendRequestWithJsonAsync<Models.OpenApiKefuStateGetResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>异步调用 [POST] /openapi/kefustate/change/{TOKEN} 接口。</para>
|
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/thirdkefu/getstate.html </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<Models.OpenApiKefuStateChangeResponse> ExecuteOpenApiKefuStateChangeAsync(this WechatOpenAIClient client, Models.OpenApiKefuStateChangeRequest request, CancellationToken cancellationToken = default)
|
|
|
|
|
{
|
|
|
|
|
if (client is null) throw new ArgumentNullException(nameof(client));
|
|
|
|
|
if (request is null) throw new ArgumentNullException(nameof(request));
|
|
|
|
|
|
2021-10-09 16:57:16 +08:00
|
|
|
|
if (request.AppId == null)
|
|
|
|
|
request.AppId = client.Credentials.AppId;
|
|
|
|
|
|
2021-10-09 15:17:35 +08:00
|
|
|
|
IFlurlRequest flurlReq = client
|
2021-10-11 18:34:21 +08:00
|
|
|
|
.CreateRequest(request, HttpMethod.Post, "openapi", "kefustate", "change", client.Credentials.Token!);
|
2021-10-09 15:17:35 +08:00
|
|
|
|
|
|
|
|
|
return await client.SendRequestWithJsonAsync<Models.OpenApiKefuStateChangeResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|