mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-15 23:13:32 +08:00
feat(openai): 新增智能对话相关接口
This commit is contained in:
parent
eb1b544c6e
commit
38f05bc467
@ -0,0 +1,68 @@
|
||||
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
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "sign", client.Credentials.PushToken!);
|
||||
|
||||
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
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "aibot", client.Credentials.PushToken!);
|
||||
|
||||
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
|
||||
.CreateRequest(request, HttpMethod.Post, "openapi", "gethotquerylist", client.Credentials.PushToken!);
|
||||
|
||||
return await client.SendRequestWithJsonAsync<Models.OpenApiGetHotQueryListResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
@ -24,12 +24,11 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置最后有效时间戳。
|
||||
/// 获取或设置最后有效时间字符串。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("last_effective_time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("last_effective_time")]
|
||||
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
|
||||
public long LastEffectiveTimestamp { get; set; }
|
||||
public string? LastEffectiveTimeString { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,8 +13,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
/// <summary>
|
||||
/// 获取或设置微信 AppId。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("authorizer_appid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("authorizer_appid")]
|
||||
[XmlElement("authorizer_appid")]
|
||||
public string AuthorizerAppId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/aibot/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiAIBotRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置请求签名。
|
||||
/// </summary>
|
||||
[XmlElement("signature")]
|
||||
public string Signature { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置询问语句。
|
||||
/// </summary>
|
||||
[XmlElement("query")]
|
||||
public string QueryString { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置环境。
|
||||
/// </summary>
|
||||
[XmlElement("env", IsNullable = true)]
|
||||
public string? Environment { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/aibot/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiAIBotResponse : WechatOpenAIResponse<OpenApiAIBotResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class BotState
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置机器人配置错误信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("err_msg")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("err_msg")]
|
||||
public string? ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置最后有效时间字符串。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("latest_time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("latest_time")]
|
||||
public string? LatestTimeString { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置最后有效时间字符串。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("latest_valid")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("latest_valid")]
|
||||
public bool IsLatestValid { get; set; }
|
||||
}
|
||||
|
||||
public class Message
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置技能 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ans_node_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ans_node_id")]
|
||||
public int AnswerNodeId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置技能名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ans_node_name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ans_node_name")]
|
||||
public string AnswerNodeName { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置置信度。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("confidence")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("confidence")]
|
||||
public int Confidence { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置消息类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("msg_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("msg_type")]
|
||||
public string MessageType { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置消息内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("content")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("content")]
|
||||
public string Content { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置消息状态。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("status")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("status")]
|
||||
public string Status { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置窗口标题。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("resp_title")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("resp_title")]
|
||||
public string? ResponseTitle { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置技能名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ans_node_name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ans_node_name")]
|
||||
public string AnswerNodeName { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置回复类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("answer_type")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("answer_type")]
|
||||
public string AnswerType { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置回复内容。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("answer")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("answer")]
|
||||
public string Answer { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置意图标题。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("title")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("title")]
|
||||
public string Title { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置回复状态。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("status")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("status")]
|
||||
public string Status { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置发起用户。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("from_user_name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("from_user_name")]
|
||||
public string FromUserName { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置接收机器人。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("to_user_name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("to_user_name")]
|
||||
public string ToUserName { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置机器人状态信息。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("bot_state")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("bot_state")]
|
||||
public Types.BotState? BotState { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置详细回答列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("msg")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("msg")]
|
||||
public Types.Message[] MessageList { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/gethotquerylist/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiGetHotQueryListRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置分页页数。
|
||||
/// <para>默认值:1</para>
|
||||
/// </summary>
|
||||
[XmlElement("pageNo")]
|
||||
public int Page { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分页每页数量。
|
||||
/// <para>默认值:10</para>
|
||||
/// </summary>
|
||||
[XmlElement("pageSize")]
|
||||
public int Limit { get; set; } = 10;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置命中类型。
|
||||
/// </summary>
|
||||
[XmlElement("matchType", IsNullable = true)]
|
||||
public int? MatchType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置问题类型。
|
||||
/// </summary>
|
||||
[XmlElement("cluesType", IsNullable = true)]
|
||||
public int? ClueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置报告类型。
|
||||
/// </summary>
|
||||
[XmlElement("reportType", IsNullable = true)]
|
||||
public int? ReportType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置日期字符串(格式:yyyy-MM-dd)。
|
||||
/// </summary>
|
||||
[XmlElement("date")]
|
||||
public string DateString { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置开发者的 OpenId。
|
||||
/// </summary>
|
||||
[XmlElement("openid")]
|
||||
public string OpenId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/gethotquerylist/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiGetHotQueryListResponse : WechatOpenAIResponse<OpenApiGetHotQueryListResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class HotQuery
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Example
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置相似问题。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("ques")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("ques")]
|
||||
public string Question { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分数
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("score")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("score")]
|
||||
public int Score { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置提问总数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("askCount")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("askCount")]
|
||||
public int AskCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置提问用户数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("askUserCount")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("askUserCount")]
|
||||
public int AskUserCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置问法总数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("askUserCount")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("askUserCount")]
|
||||
public int QuestionCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置问题类型。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("cluesType")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("cluesType")]
|
||||
public int ClueType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置示例列表
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("exampleQues")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("exampleQues")]
|
||||
public Types.Example[] ExampleList { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置问题类别数量。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("hotQuesClusterCount")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("hotQuesClusterCount")]
|
||||
public int HotQuestionClusterCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置问题数量。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("hotQuesCount")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("hotQuesCount")]
|
||||
public int HotQuestionCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置分页总页数。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("totalPages")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("totalPages")]
|
||||
public int TotalPageCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置热问列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("list")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("list")]
|
||||
public Types.HotQuery[] HotQueryList { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/sign/{TOKEN} 接口的请求。</para>
|
||||
/// </summary>
|
||||
[XmlRoot("xml")]
|
||||
public class OpenApiSignRequest : WechatOpenAIRequest, WechatOpenAIRequest.Serialization.IEncryptedXmlable
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置用户 ID。
|
||||
/// </summary>
|
||||
[XmlElement("userid")]
|
||||
public string UserId { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户昵称。
|
||||
/// </summary>
|
||||
[XmlElement("username")]
|
||||
public string Nickname { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户头像 URL。
|
||||
/// </summary>
|
||||
[XmlElement("avatar", IsNullable = true)]
|
||||
public string? AvatarUrl { get; set; }
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /openapi/sign/{TOKEN} 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class OpenApiSignResponse : WechatOpenAIResponse<OpenApiSignResponse.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置请求签名。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("signature")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("signature")]
|
||||
public string Signature { get; set; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置有效期(单位:秒)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("expiresIn")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("expiresIn")]
|
||||
public int ExpiresIn { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user