mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-04-05 17:37:54 +08:00
feat(openai): 新增 v2 版机器人配置相关接口
This commit is contained in:
parent
a92a602a71
commit
ea25c0bf24
@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
{
|
||||
public static class WechatOpenAIClientExecuteAsyncExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/async/fetch 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/dialog/bot/fetch.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.AsyncFetchV2Response> ExecuteAsyncFetchV2Async(this WechatOpenAIClient client, Models.AsyncFetchV2Request 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
|
||||
.CreateFlurlRequest(request, HttpMethod.Post, "v2", "async", "fetch");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.AsyncFetchV2Response>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Flurl.Http;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
{
|
||||
public static class WechatOpenAIClientExecuteBotExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/bot/import/json 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/dialog/bot/import.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.BotImportJsonV2Response> ExecuteBotImportJsonV2Async(this WechatOpenAIClient client, Models.BotImportJsonV2Request 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
|
||||
.CreateFlurlRequest(request, HttpMethod.Post, "v2", "bot", "import", "json");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.BotImportJsonV2Response>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/bot/publish 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/dialog/bot/publish.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.BotPublishV2Response> ExecuteBotPublishV2Async(this WechatOpenAIClient client, Models.BotPublishV2Request 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
|
||||
.CreateFlurlRequest(request, HttpMethod.Post, "v2", "bot", "publish");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.BotPublishV2Response>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>异步调用 [POST] /v2/bot/effective_progress 接口。</para>
|
||||
/// <para>
|
||||
/// REF: <br/>
|
||||
/// <![CDATA[ https://developers.weixin.qq.com/doc/aispeech/confapi/dialog/bot/progress.html ]]>
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="client"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancellationToken"></param>
|
||||
/// <returns></returns>
|
||||
public static async Task<Models.BotEffectiveProgressV2Response> ExecuteBotEffectiveProgressV2Async(this WechatOpenAIClient client, Models.BotEffectiveProgressV2Request 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
|
||||
.CreateFlurlRequest(request, HttpMethod.Post, "v2", "bot", "effective_progress");
|
||||
|
||||
return await client.SendFlurlRequestAsJsonAsync<Models.BotEffectiveProgressV2Response>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
@ -30,15 +30,6 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Interceptors
|
||||
_baseUrl = baseUrl;
|
||||
_encodingAESKey = encodingAESKey;
|
||||
_customEncryptedRequestPathMatcher = customEncryptedRequestPathMatcher;
|
||||
|
||||
// AES 密钥的长度不是 4 的倍数需要补齐,确保其始终为有效的 Base64 字符串
|
||||
const int MULTI = 4;
|
||||
int tLen = _encodingAESKey.Length;
|
||||
int tRem = tLen % MULTI;
|
||||
if (tRem > 0)
|
||||
{
|
||||
_encodingAESKey = _encodingAESKey.PadRight(tLen - tRem + MULTI, '=');
|
||||
}
|
||||
}
|
||||
|
||||
public override async Task BeforeCallAsync(HttpInterceptorContext context, CancellationToken cancellationToken = default)
|
||||
@ -83,7 +74,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Interceptors
|
||||
}
|
||||
|
||||
context.FlurlCall.HttpRequestMessage!.Content?.Dispose();
|
||||
context.FlurlCall.HttpRequestMessage!.Content = new ByteArrayContent(reqBytesEncrypted);
|
||||
context.FlurlCall.HttpRequestMessage!.Content = new StringContent(Convert.ToBase64String(reqBytesEncrypted));
|
||||
context.FlurlCall.Request.WithHeader(HttpHeaders.ContentType, MimeTypes.Text);
|
||||
}
|
||||
|
||||
@ -150,9 +141,10 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Interceptors
|
||||
{
|
||||
if (_customEncryptedRequestPathMatcher is not null)
|
||||
return _customEncryptedRequestPathMatcher(relativeUrl);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/async/fetch 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class AsyncFetchV2Request : WechatOpenAIRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置任务 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("task_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("task_id")]
|
||||
public string TaskId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
@ -0,0 +1,133 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/async/fetch 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class AsyncFetchV2Response : WechatOpenAIResponse<AsyncFetchV2Response.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data : WechatOpenAIResponseData
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Intent
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置意图 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id")]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Common.TextualNumberReadOnlyConverter))]
|
||||
public long IntentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置意图名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("name")]
|
||||
public string Name { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class FailedSkill
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置技能名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("name")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("name")]
|
||||
public string Name { get; set; } = default!;
|
||||
}
|
||||
|
||||
public class SucceededSkill : FailedSkill
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置技能 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("id")]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Common.TextualNumberReadOnlyConverter))]
|
||||
public long SkillId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置意图列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("intents")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("intents")]
|
||||
public Types.Intent[] IntentList { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务状态。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("state")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("state")]
|
||||
public int State { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务进度(单位:百分数)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("progress")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("progress")]
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务开始时间戳。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("start")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("start")]
|
||||
public long StartTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务结束时间戳。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("end")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("end")]
|
||||
public long EndTimestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导出任务的 URL。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("url")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("url")]
|
||||
public string? Url { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导入的总数量。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("total_count")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("total_count")]
|
||||
public int TotalCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导入失败的数量。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("fail_count")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("fail_count")]
|
||||
public int FailedCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导入失败的技能列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("fail_skill_info")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("fail_skill_info")]
|
||||
public Types.FailedSkill[]? FailedSkillList { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导入成功的数量。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("success_count")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("success_count")]
|
||||
public int SucceededCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导入成功的技能列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("success_skill_info")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("success_skill_info")]
|
||||
public Types.SucceededSkill[]? SucceededSkillList { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/bot/effective_progress 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class BotEffectiveProgressV2Request : WechatOpenAIRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置查询环境。
|
||||
/// <para>默认值:"online"</para>
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("env")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("env")]
|
||||
public string Environment { get; set; } = "online";
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/bot/effective_progress 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class BotEffectiveProgressV2Response : WechatOpenAIResponse<BotEffectiveProgressV2Response.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data : WechatOpenAIResponseData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置任务状态。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("status")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("status")]
|
||||
public int Status { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务进度(单位:百分数)。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("progress")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("progress")]
|
||||
public int Progress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置任务结束时间字符串。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("end_time")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("end_time")]
|
||||
public string? EndTimeString { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/bot/import/json 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class BotImportJsonV2Request : WechatOpenAIRequest
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Skill
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置技能名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("skill")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("skill")]
|
||||
public string SkillName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置原意图名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("old_intent")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("old_intent")]
|
||||
public string? OldIntentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置意图名称。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("intent")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("intent")]
|
||||
public string IntentName { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置相似度。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("threshold")]
|
||||
[Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.Common.TextualNumberConverter))]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("threshold")]
|
||||
[System.Text.Json.Serialization.JsonConverter(typeof(System.Text.Json.Serialization.Common.TextualNumberConverter))]
|
||||
public decimal Threshold { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置是否关闭。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("disable")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("disable")]
|
||||
public bool IsDisabled { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置问题列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("questions")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("questions")]
|
||||
public IList<string> QuestionList { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置回答列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("answers")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("answers")]
|
||||
public IList<string> AnswerList { get; set; } = new List<string>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置导入模式。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("mode")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("mode")]
|
||||
public int Mode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置技能列表。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("data")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public IList<Types.Skill> SkillList { get; set; } = new List<Types.Skill>();
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/bot/import/json 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class BotImportJsonV2Response : WechatOpenAIResponse<BotImportJsonV2Response.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data : WechatOpenAIResponseData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置任务 ID。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("task_id")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("task_id")]
|
||||
public string TaskId { get; set; } = default!;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/bot/publish 接口的请求。</para>
|
||||
/// </summary>
|
||||
public class BotPublishV2Request : WechatOpenAIRequest
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
/// <summary>
|
||||
/// <para>表示 [POST] /v2/bot/publish 接口的响应。</para>
|
||||
/// </summary>
|
||||
public class BotPublishV2Response : WechatOpenAIResponse<BotPublishV2Response.Types.Data>
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data : WechatOpenAIResponseData
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,6 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("account")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("account")]
|
||||
public string Account { get; set; } = string.Empty;
|
||||
public string AccountId { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||
{
|
||||
public static class Types
|
||||
{
|
||||
public class Data
|
||||
public class Data : WechatOpenAIResponseData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置接口访问令牌。
|
||||
|
@ -25,7 +25,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Settings
|
||||
|
||||
AppId = options.AppId;
|
||||
Token = options.Token;
|
||||
EncodingAESKey = options.EncodingAESKey;
|
||||
EncodingAESKey = PadEncodingAESKey(options.EncodingAESKey);
|
||||
}
|
||||
|
||||
internal Credentials(WechatChatbotClientOptions options)
|
||||
@ -34,7 +34,21 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Settings
|
||||
|
||||
AppId = options.AppId;
|
||||
Token = options.Token;
|
||||
EncodingAESKey = options.EncodingAESKey;
|
||||
EncodingAESKey = PadEncodingAESKey(options.EncodingAESKey);
|
||||
}
|
||||
|
||||
private string PadEncodingAESKey(string encodingAESKey)
|
||||
{
|
||||
// AES 密钥的长度不是 4 的倍数需要补齐,确保其始终为有效的 Base64 字符串
|
||||
const int MULTI = 4;
|
||||
int tLen = encodingAESKey.Length;
|
||||
int tRem = tLen % MULTI;
|
||||
if (tRem > 0)
|
||||
{
|
||||
encodingAESKey = encodingAESKey.PadRight(tLen - tRem + MULTI, '=');
|
||||
}
|
||||
|
||||
return encodingAESKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
|
||||
Interceptors.Add(new Interceptors.WechatOpenAIRequestEncryptionInterceptor(
|
||||
baseUrl: FlurlClient.BaseUrl,
|
||||
encodingAESKey: options.EncodingAESKey,
|
||||
encodingAESKey: Credentials.EncodingAESKey,
|
||||
customEncryptedRequestPathMatcher: options.CustomEncryptedRequestPathMatcher
|
||||
));
|
||||
Interceptors.Add(new Interceptors.WechatOpenAIRequestSigningInterceptor(
|
||||
token: options.Token
|
||||
token: Credentials.Token
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
/// 表示微信智能对话 API 响应的泛型基类。
|
||||
/// </summary>
|
||||
public abstract class WechatOpenAIResponse<TData> : WechatOpenAIResponse
|
||||
where TData : class
|
||||
where TData : WechatOpenAIResponseData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取微信智能对话 API 返回的数据。
|
||||
@ -52,4 +52,17 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||
[System.Text.Json.Serialization.JsonPropertyName("data")]
|
||||
public virtual TData? Data { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 表示微信智能对话 API 响应的返回数据基类。
|
||||
/// </summary>
|
||||
public abstract class WechatOpenAIResponseData
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取或设置错误详情。
|
||||
/// </summary>
|
||||
[Newtonsoft.Json.JsonProperty("err_detail")]
|
||||
[System.Text.Json.Serialization.JsonPropertyName("err_detail")]
|
||||
public virtual string? ErrorDetail { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"task_id": "fad7576d7562429d9c5d8568dc35a41b"
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
{
|
||||
"code": 0,
|
||||
"data": {
|
||||
"end": 1711088874,
|
||||
"fail_count": 0,
|
||||
"fail_skill_info": null,
|
||||
"progress": 100,
|
||||
"start": 1711088873,
|
||||
"state": 2,
|
||||
"success_count": 1,
|
||||
"success_skill_info": [
|
||||
{
|
||||
"id": 2098207,
|
||||
"intents": [
|
||||
{
|
||||
"id": 47147532,
|
||||
"name": "BBC"
|
||||
}
|
||||
],
|
||||
"name": "AAA"
|
||||
}
|
||||
],
|
||||
"total_count": 1,
|
||||
"url": ""
|
||||
},
|
||||
"msg": "success",
|
||||
"request_id": "test123"
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"env": "online"
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
{
|
||||
"code": 0,
|
||||
"data": {
|
||||
"end_time": "",
|
||||
"progress": 100,
|
||||
"status": 1
|
||||
},
|
||||
"msg": "success",
|
||||
"request_id": "7df42cb2-e776-40ac-b0c4-8542aad2b0ec"
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
{
|
||||
"mode": 0,
|
||||
"data": [
|
||||
{
|
||||
"skill": "AAA",
|
||||
"intent": "BBC",
|
||||
"threshold": "0.9",
|
||||
"disable": true,
|
||||
"questions": [
|
||||
"q",
|
||||
"q2"
|
||||
],
|
||||
"answers": [
|
||||
"a"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
{
|
||||
"code": 0,
|
||||
"data": {
|
||||
"task_id": "179ba14fae5f4028b7c00a180cf709e3"
|
||||
},
|
||||
"msg": "",
|
||||
"request_id": "test123"
|
||||
}
|
@ -8,7 +8,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
|
||||
[Fact(DisplayName = "测试用例:调用 API [POST] /v2/token")]
|
||||
public async Task TestExecuteTokenV2()
|
||||
{
|
||||
var request = new Models.TokenV2Request() { Account = "TEST_ACCOUNTID" };
|
||||
var request = new Models.TokenV2Request() { AccountId = TestConfigs.WechatAccountId };
|
||||
var response = await TestClients.OpenAIInstance.ExecuteTokenV2Async(request);
|
||||
|
||||
Assert.NotNull(response.Data?.AccessToken);
|
||||
|
@ -21,6 +21,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
|
||||
WechatAppId = config.GetProperty("AppId").GetString()!;
|
||||
WechatToken = config.GetProperty("Token").GetString()!;
|
||||
WechatEncodingAESKey = config.GetProperty("EncodingAESKey").GetString()!;
|
||||
WechatAccountId = config.GetProperty("AccountId").GetString()!;
|
||||
WechatAccessToken = config.GetProperty("AccessToken").GetString()!;
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -32,6 +33,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.UnitTests
|
||||
public static readonly string WechatAppId;
|
||||
public static readonly string WechatToken;
|
||||
public static readonly string WechatEncodingAESKey;
|
||||
public static readonly string WechatAccountId;
|
||||
public static readonly string WechatAccessToken;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
"AppId": "请在此填写用于测试的微信智能对话 AppId",
|
||||
"Token": "请在此填写用于测试的微信智能对话 Token",
|
||||
"EncodingAESKey": "请在此填写用于测试的微信智能对话 EncodingAESKey",
|
||||
"AccountId": "请在此填写用于测试的微信智能对话管理员账号 ID",
|
||||
"AccessToken": "请在此填写用于测试的微信智能对话 AccessToken"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user