2021-10-11 12:35:59 +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 WechatOpenAIClientExecuteOpenApiQueryExtensions
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>异步调用 [POST] /openapi/sign/{TOKEN} 接口。</para>
|
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/INTERFACEDOCUMENT.html </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<Models.OpenApiSignResponse> ExecuteOpenApiSignAsync(this WechatOpenAIClient client, Models.OpenApiSignRequest 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
|
2021-10-11 18:34:21 +08:00
|
|
|
|
.CreateRequest(request, HttpMethod.Post, "openapi", "sign", client.Credentials.Token!);
|
2021-10-11 12:35:59 +08:00
|
|
|
|
|
|
|
|
|
return await client.SendRequestWithJsonAsync<Models.OpenApiSignResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>异步调用 [POST] /openapi/aibot/{TOKEN} 接口。</para>
|
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/INTERFACEDOCUMENT.html </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<Models.OpenApiAIBotResponse> ExecuteOpenApiAIBotAsync(this WechatOpenAIClient client, Models.OpenApiAIBotRequest 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
|
2021-10-11 18:34:21 +08:00
|
|
|
|
.CreateRequest(request, HttpMethod.Post, "openapi", "aibot", client.Credentials.Token!);
|
2021-10-11 12:35:59 +08:00
|
|
|
|
|
|
|
|
|
return await client.SendRequestWithJsonAsync<Models.OpenApiAIBotResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// <para>异步调用 [POST] /openapi/gethotquerylist/{TOKEN} 接口。</para>
|
|
|
|
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/api/gethotquerylist.html </para>
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="client"></param>
|
|
|
|
|
/// <param name="request"></param>
|
|
|
|
|
/// <param name="cancellationToken"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static async Task<Models.OpenApiGetHotQueryListResponse> ExecuteOpenApiGetHotQueryListAsync(this WechatOpenAIClient client, Models.OpenApiGetHotQueryListRequest 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
|
2021-10-11 18:34:21 +08:00
|
|
|
|
.CreateRequest(request, HttpMethod.Post, "openapi", "gethotquerylist", client.Credentials.Token!);
|
2021-10-11 12:35:59 +08:00
|
|
|
|
|
|
|
|
|
return await client.SendRequestWithJsonAsync<Models.OpenApiGetHotQueryListResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|