mirror of
https://gitee.com/fudiwei/DotNetCore.SKIT.FlurlHttpClient.Wechat.git
synced 2025-07-16 16:50:43 +08:00
feat(openai): 新增直播相关接口
This commit is contained in:
parent
5ca9a48830
commit
ef27073d5f
@ -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 WechatOpenAIClientExecuteOpenApiLivingExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>异步调用 [POST] /openapi/batchreply/{TOKEN} 接口。</para>
|
||||||
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/living/batchreply.html </para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<Models.OpenApiBatchReplyResponse> ExecuteOpenApiSendMessageAsync(this WechatOpenAIClient client, Models.OpenApiBatchReplyRequest 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", "batchreply", client.Credentials.PushToken!);
|
||||||
|
|
||||||
|
return await client.SendRequestWithJsonAsync<Models.OpenApiBatchReplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>异步调用 [POST] /openapi/setautoreply/{TOKEN} 接口。</para>
|
||||||
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/living/setautoreply.html </para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<Models.OpenApiBatchSetAutoReplyResponse> ExecuteOpenApiBatchSetAutoReplyAsync(this WechatOpenAIClient client, Models.OpenApiBatchSetAutoReplyRequest 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", "setautoreply", client.Credentials.PushToken!);
|
||||||
|
|
||||||
|
return await client.SendRequestWithJsonAsync<Models.OpenApiBatchSetAutoReplyResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <para>异步调用 [POST] /openapi/generatereport/{TOKEN} 接口。</para>
|
||||||
|
/// <para>REF: https://developers.weixin.qq.com/doc/aispeech/platform/living/setautoreply.html </para>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="client"></param>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <param name="cancellationToken"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static async Task<Models.OpenApiGenerateReportResponse> ExecuteOpenApiGenerateReportAsync(this WechatOpenAIClient client, Models.OpenApiGenerateReportRequest 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", "generatereport", client.Credentials.PushToken!);
|
||||||
|
|
||||||
|
return await client.SendRequestWithJsonAsync<Models.OpenApiGenerateReportResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Flurl;
|
|
||||||
using Flurl.Http;
|
using Flurl.Http;
|
||||||
|
|
||||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
||||||
@ -67,6 +64,5 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI
|
|||||||
|
|
||||||
return await client.SendRequestWithJsonAsync<Models.OpenApiKefuStateChangeResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
return await client.SendRequestWithJsonAsync<Models.OpenApiKefuStateChangeResponse>(flurlReq, data: request, cancellationToken: cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>表示 [POST] /openapi/batchreply/{TOKEN} 接口的请求。</para>
|
||||||
|
/// </summary>
|
||||||
|
[XmlRoot("xml")]
|
||||||
|
public class OpenApiBatchReplyRequest : WechatOpenAIRequestEncryptedXmlable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置直播 ID。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("liveid")]
|
||||||
|
public string LiveId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置回复内容。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("content")]
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置希望展示给用户的客服人员的名字。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("waitername", IsNullable = true)]
|
||||||
|
public string? WaiterName { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置客希望展示给用户的客服人员的头像 URL。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("waiteravatar", IsNullable = true)]
|
||||||
|
public string? WaiterAvatarUrl { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置要设置标签的 OpenId 列表。
|
||||||
|
/// </summary>
|
||||||
|
[XmlArray("list")]
|
||||||
|
[XmlArrayItem("openid", Type = typeof(string))]
|
||||||
|
public List<string> OpenIdList { get; set; } = new List<string>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>表示 [POST] /openapi/batchreply/{TOKEN} 接口的响应。</para>
|
||||||
|
/// </summary>
|
||||||
|
public class OpenApiBatchReplyResponse : WechatOpenAIResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,44 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>表示 [POST] /openapi/setautoreply/{TOKEN} 接口的请求。</para>
|
||||||
|
/// </summary>
|
||||||
|
[XmlRoot("xml")]
|
||||||
|
public class OpenApiBatchSetAutoReplyRequest : WechatOpenAIRequestEncryptedXmlable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置管理员 ID。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("managerid")]
|
||||||
|
public string ManagerId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置技能名称。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("skillname")]
|
||||||
|
public string SkillName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置标准问题。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("title", IsNullable = true)]
|
||||||
|
public string Title { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置自动回答的内容。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("content", IsNullable = true)]
|
||||||
|
public string Content { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置要设置的相似问题列表。
|
||||||
|
/// </summary>
|
||||||
|
[XmlArray("list")]
|
||||||
|
[XmlArrayItem("question", Type = typeof(string))]
|
||||||
|
public List<string> QuestionId { get; set; } = new List<string>();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>表示 [POST] /openapi/setautoreply/{TOKEN} 接口的响应。</para>
|
||||||
|
/// </summary>
|
||||||
|
public class OpenApiBatchSetAutoReplyResponse : WechatOpenAIResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>表示 [POST] /openapi/generatereport/{TOKEN} 接口的请求。</para>
|
||||||
|
/// </summary>
|
||||||
|
[XmlRoot("xml")]
|
||||||
|
public class OpenApiGenerateReportRequest : WechatOpenAIRequestEncryptedXmlable
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置直播 ID。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("liveid")]
|
||||||
|
public string LiveId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取或设置房间 ID。
|
||||||
|
/// </summary>
|
||||||
|
[XmlElement("bucket")]
|
||||||
|
public string Bucket { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <para>表示 [POST] /openapi/generatereport/{TOKEN} 接口的响应。</para>
|
||||||
|
/// </summary>
|
||||||
|
public class OpenApiGenerateReportResponse : WechatOpenAIResponse
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
@ -31,19 +31,19 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Models
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取或设置事件。
|
/// 获取或设置事件。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlElement("event")]
|
[XmlElement("event", IsNullable = true)]
|
||||||
public string? Event { get; set; }
|
public string? Event { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取或设置客服人员的昵称。
|
/// 获取或设置客服人员的昵称。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlElement("kefuname")]
|
[XmlElement("kefuname", IsNullable = true)]
|
||||||
public string? KfName { get; set; }
|
public string? KfName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取或设置客服人员的头像 URL。
|
/// 获取或设置客服人员的头像 URL。
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[XmlElement("kefuavatar")]
|
[XmlElement("kefuavatar", IsNullable = true)]
|
||||||
public string? KfAvatarUrl { get; set; }
|
public string? KfAvatarUrl { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Xml;
|
||||||
using System.Xml.Serialization;
|
using System.Xml.Serialization;
|
||||||
|
|
||||||
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
||||||
@ -12,9 +13,15 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
|||||||
{
|
{
|
||||||
string xml;
|
string xml;
|
||||||
|
|
||||||
|
var settings = new XmlWriterSettings();
|
||||||
|
settings.Encoding = Encoding.UTF8;
|
||||||
|
settings.Indent = false;
|
||||||
|
settings.OmitXmlDeclaration = true;
|
||||||
|
settings.WriteEndDocumentOnClose = false;
|
||||||
|
settings.NamespaceHandling = NamespaceHandling.OmitDuplicates;
|
||||||
|
|
||||||
using var stream = new MemoryStream();
|
using var stream = new MemoryStream();
|
||||||
using var writer = new System.Xml.XmlTextWriter(stream, Encoding.UTF8);
|
using var writer = XmlWriter.Create(stream, settings);
|
||||||
writer.Formatting = System.Xml.Formatting.None;
|
|
||||||
|
|
||||||
XmlSerializer xmlSerializer = new XmlSerializer(type, new XmlRootAttribute("xml"));
|
XmlSerializer xmlSerializer = new XmlSerializer(type, new XmlRootAttribute("xml"));
|
||||||
XmlSerializerNamespaces xmlNamespace = new XmlSerializerNamespaces();
|
XmlSerializerNamespaces xmlNamespace = new XmlSerializerNamespaces();
|
||||||
@ -22,7 +29,7 @@ namespace SKIT.FlurlHttpClient.Wechat.OpenAI.Utilities
|
|||||||
xmlSerializer.Serialize(writer, obj, xmlNamespace);
|
xmlSerializer.Serialize(writer, obj, xmlNamespace);
|
||||||
writer.Flush();
|
writer.Flush();
|
||||||
xml = Encoding.UTF8.GetString(stream.ToArray());
|
xml = Encoding.UTF8.GetString(stream.ToArray());
|
||||||
xml = Regex.Replace(xml, "\\s+<\\w+ (xsi|d2p1):nil=\"true\"[^>]*/>", string.Empty, RegexOptions.IgnoreCase);
|
xml = Regex.Replace(xml, "\\s*<\\w+ (xsi|d2p1):nil=\"true\"[^>]*/>", string.Empty, RegexOptions.IgnoreCase);
|
||||||
xml = Regex.Replace(xml, "<\\?xml[^>]*\\?>", string.Empty, RegexOptions.IgnoreCase);
|
xml = Regex.Replace(xml, "<\\?xml[^>]*\\?>", string.Empty, RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
return xml;
|
return xml;
|
||||||
|
Loading…
Reference in New Issue
Block a user