feat(work): 新增数据与智能专区部分基础接口

This commit is contained in:
Fu Diwei 2025-02-01 23:38:56 +08:00
parent cb2cf4f7b3
commit 8270f7642a
17 changed files with 455 additions and 0 deletions

View File

@ -0,0 +1,35 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Events
{
/// <summary>
/// <para>表示 INFO.advanced_api_expired 事件的数据。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.work.weixin.qq.com/document/path/100269 ]]>
/// </para>
/// </summary>
public class AdvancedApiExpiredEvent : AdvancedApiTrialExpiredEvent
{
public static class Types
{
public class ChatArchiveApi
{
/// <summary>
/// 获取或设置到期的账号版本。
/// </summary>
[Newtonsoft.Json.JsonProperty("Edition")]
[System.Text.Json.Serialization.JsonPropertyName("Edition")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
[System.Xml.Serialization.XmlElement("Edition")]
public int Edition { get; set; }
}
}
/// <summary>
/// 获取或设置会话内容数据接口相关信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("ChatArchiveApi")]
[System.Text.Json.Serialization.JsonPropertyName("ChatArchiveApi")]
[System.Xml.Serialization.XmlElement("ChatArchiveApi")]
public Types.ChatArchiveApi ChatArchiveApi { get; set; } = default!;
}
}

View File

@ -0,0 +1,37 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Events
{
/// <summary>
/// <para>表示 INFO.advanced_api_trial_expired 事件的数据。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.work.weixin.qq.com/document/path/100270 ]]>
/// </para>
/// </summary>
public class AdvancedApiTrialExpiredEvent : WechatWorkEvent
{
/// <summary>
/// 获取或设置服务商 CorpId。
/// </summary>
[Newtonsoft.Json.JsonProperty("ServiceCorpId")]
[System.Text.Json.Serialization.JsonPropertyName("ServiceCorpId")]
[System.Xml.Serialization.XmlElement("ServiceCorpId")]
public string ServiceCorpId { get; set; } = default!;
/// <summary>
/// 获取或设置授权方的 CorpId。
/// </summary>
[Newtonsoft.Json.JsonProperty("AuthCorpId")]
[System.Text.Json.Serialization.JsonPropertyName("AuthCorpId")]
[System.Xml.Serialization.XmlElement("AuthCorpId")]
public string AuthorizerCorpId { get; set; } = default!;
/// <summary>
/// 获取或设置高级接口类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("AdvanceApiType")]
[System.Text.Json.Serialization.JsonPropertyName("AdvanceApiType")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
[System.Xml.Serialization.XmlElement("AdvanceApiType")]
public int AdvanceApiType { get; set; }
}
}

View File

@ -32,6 +32,29 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendFlurlRequestAsJsonAsync<Models.CgibinChatDataGetAuthUserListResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); ;
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/chatdata/get_corp_auth_info 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.work.weixin.qq.com/document/path/100237 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinChatDataGetCorpAuthInfoResponse> ExecuteCgibinChatDataGetCorpAuthInfoAsync(this WechatWorkClient client, Models.CgibinChatDataGetCorpAuthInfoRequest 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, "cgi-bin", "chatdata", "get_corp_auth_info")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.CgibinChatDataGetCorpAuthInfoResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); ;
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/chatdata/set_public_key 接口。</para>
/// <para>
@ -55,6 +78,83 @@ namespace SKIT.FlurlHttpClient.Wechat.Work
return await client.SendFlurlRequestAsJsonAsync<Models.CgibinChatDataSetPublicKeyResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); ;
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/chatdata/set_receive_callback 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.work.weixin.qq.com/document/path/100018 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinChatDataSetReceiveCallbackResponse> ExecuteCgibinChatDataSetReceiveCallbackAsync(this WechatWorkClient client, Models.CgibinChatDataSetReceiveCallbackRequest 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, "cgi-bin", "chatdata", "set_receive_callback")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.CgibinChatDataSetReceiveCallbackResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); ;
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/chatdata/set_log_level 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.work.weixin.qq.com/document/path/100109 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinChatDataSetLogLevelResponse> ExecuteCgibinChatDataSetLogLevelAsync(this WechatWorkClient client, Models.CgibinChatDataSetLogLevelRequest 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, "cgi-bin", "chatdata", "set_log_level")
.SetQueryParam("access_token", request.AccessToken);
return await client.SendFlurlRequestAsJsonAsync<Models.CgibinChatDataSetLogLevelResponse>(flurlReq, data: request, cancellationToken: cancellationToken).ConfigureAwait(false); ;
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/chatdata/upload_media 接口。</para>
/// <para>
/// REF: <br/>
/// <![CDATA[ https://developer.work.weixin.qq.com/document/path/100175 ]]>
/// </para>
/// </summary>
/// <param name="client"></param>
/// <param name="request"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public static async Task<Models.CgibinChatDataUploadMediaResponse> ExecuteCgibinChatDataUploadMediaAsync(this WechatWorkClient client, Models.CgibinChatDataUploadMediaRequest request, CancellationToken cancellationToken = default)
{
if (client is null) throw new ArgumentNullException(nameof(client));
if (request is null) throw new ArgumentNullException(nameof(request));
if (request.FileName is null)
request.FileName = Guid.NewGuid().ToString("N").ToLower();
if (request.FileContentType is null)
request.FileContentType = MimeTypes.GetMimeMapping(request.FileName!);
IFlurlRequest flurlReq = client
.CreateFlurlRequest(request, HttpMethod.Post, "cgi-bin", "chatdata", "upload")
.SetQueryParam("access_token", request.AccessToken)
.SetQueryParam("type", request.Type);
using var httpContent = Utilities.HttpContentBuilder.BuildWithFile(fileName: request.FileName, fileBytes: request.FileBytes, fileContentType: request.FileContentType, formDataName: "media");
return await client.SendFlurlRequestAsync<Models.CgibinChatDataUploadMediaResponse>(flurlReq, httpContent: httpContent, cancellationToken: cancellationToken).ConfigureAwait(false);
}
/// <summary>
/// <para>异步调用 [POST] /cgi-bin/chatdata/sync_msg 接口。</para>
/// <para>

View File

@ -0,0 +1,9 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/get_corp_auth_info 接口的请求。</para>
/// </summary>
public class CgibinChatDataGetCorpAuthInfoRequest : WechatWorkRequest
{
}
}

View File

@ -0,0 +1,90 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/get_corp_auth_info 接口的响应。</para>
/// </summary>
public class CgibinChatDataGetCorpAuthInfoResponse : WechatWorkResponse
{
public static class Types
{
public class AuthEdition
{
public static class Types
{
public class AuthScope
{
/// <summary>
/// 获取或设置企业授权存档的成员账号列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("userid_list")]
[System.Text.Json.Serialization.JsonPropertyName("userid_list")]
public string[]? UserIdList { get; set; }
/// <summary>
/// 获取或设置企业授权存档的部门 ID 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("department_id_list")]
[System.Text.Json.Serialization.JsonPropertyName("department_id_list")]
public long[]? DepartmentIdList { get; set; }
/// <summary>
/// 获取或设置企业授权存档的标签 ID 列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("tag_id_list")]
[System.Text.Json.Serialization.JsonPropertyName("tag_id_list")]
public long[]? TagIdList { get; set; }
}
}
/// <summary>
/// 获取或设置会话版本类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("edition")]
[System.Text.Json.Serialization.JsonPropertyName("edition")]
public int Edition { get; set; }
/// <summary>
/// 获取或设置授权范围信息。
/// </summary>
[Newtonsoft.Json.JsonProperty("auth_scope")]
[System.Text.Json.Serialization.JsonPropertyName("auth_scope")]
public Types.AuthScope AuthScope { get; set; } = default!;
/// <summary>
/// 获取或设置状态。
/// </summary>
[Newtonsoft.Json.JsonProperty("status")]
[System.Text.Json.Serialization.JsonPropertyName("status")]
public int Status { get; set; }
/// <summary>
/// 获取或设置开始生效时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("begin_time")]
[System.Text.Json.Serialization.JsonPropertyName("begin_time")]
public long BeginTimestamp { get; set; }
/// <summary>
/// 获取或设置结束生效时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("end_time")]
[System.Text.Json.Serialization.JsonPropertyName("end_time")]
public long EndTimestamp { get; set; }
/// <summary>
/// 获取或设置会话授权的天数。
/// </summary>
[Newtonsoft.Json.JsonProperty("msg_duration_days")]
[System.Text.Json.Serialization.JsonPropertyName("msg_duration_days")]
public int MessageDurationDays { get; set; }
}
}
/// <summary>
/// 获取或设置企业授权的会话版本列表。
/// </summary>
[Newtonsoft.Json.JsonProperty("auth_edition_list")]
[System.Text.Json.Serialization.JsonPropertyName("auth_edition_list")]
public Types.AuthEdition[] AuthEditionList { get; set; } = default!;
}
}

View File

@ -0,0 +1,22 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/set_log_level 接口的请求。</para>
/// </summary>
public class CgibinChatDataSetLogLevelRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置应用关联的程序 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("program_id")]
[System.Text.Json.Serialization.JsonPropertyName("program_id")]
public string ProgramId { get; set; } = string.Empty;
/// <summary>
/// 获取或设置日志级别。
/// </summary>
[Newtonsoft.Json.JsonProperty("log_level")]
[System.Text.Json.Serialization.JsonPropertyName("log_level")]
public int LogLevel { get; set; }
}
}

View File

@ -0,0 +1,9 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/set_log_level 接口的响应。</para>
/// </summary>
public class CgibinChatDataSetLogLevelResponse : WechatWorkResponse
{
}
}

View File

@ -0,0 +1,15 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/set_receive_callback 接口的请求。</para>
/// </summary>
public class CgibinChatDataSetReceiveCallbackRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置应用关联的程序 ID。
/// </summary>
[Newtonsoft.Json.JsonProperty("program_id")]
[System.Text.Json.Serialization.JsonPropertyName("program_id")]
public string ProgramId { get; set; } = string.Empty;
}
}

View File

@ -0,0 +1,9 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/set_receive_callback 接口的响应。</para>
/// </summary>
public class CgibinChatDataSetReceiveCallbackResponse : WechatWorkResponse
{
}
}

View File

@ -0,0 +1,38 @@
using System;
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/upload_media 接口的请求。</para>
/// </summary>
public class CgibinChatDataUploadMediaRequest : WechatWorkRequest
{
/// <summary>
/// 获取或设置媒体文件类型。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string Type { get; set; } = string.Empty;
/// <summary>
/// 获取或设置文件字节数组。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public byte[] FileBytes { get; set; } = Array.Empty<byte>();
/// <summary>
/// 获取或设置文件名。如果不指定将由系统自动生成。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? FileName { get; set; }
/// <summary>
/// 获取或设置文件 Conent-Type。如果不指定将由系统自动生成。
/// </summary>
[Newtonsoft.Json.JsonIgnore]
[System.Text.Json.Serialization.JsonIgnore]
public string? FileContentType { get; set; }
}
}

View File

@ -0,0 +1,30 @@
namespace SKIT.FlurlHttpClient.Wechat.Work.Models
{
/// <summary>
/// <para>表示 [POST] /cgi-bin/chatdata/upload_media 接口的响应。</para>
/// </summary>
public class CgibinChatDataUploadMediaResponse : WechatWorkResponse
{
/// <summary>
/// 获取或设置媒体文件类型。
/// </summary>
[Newtonsoft.Json.JsonProperty("type")]
[System.Text.Json.Serialization.JsonPropertyName("type")]
public string Type { get; set; } = default!;
/// <summary>
/// 获取或设置媒体文件标识。
/// </summary>
[Newtonsoft.Json.JsonProperty("media_id")]
[System.Text.Json.Serialization.JsonPropertyName("media_id")]
public string MediaId { get; set; } = default!;
/// <summary>
/// 获取或设置媒体文件上传时间戳。
/// </summary>
[Newtonsoft.Json.JsonProperty("created_at")]
[System.Text.Json.Serialization.JsonPropertyName("created_at")]
[System.Text.Json.Serialization.JsonNumberHandling(System.Text.Json.Serialization.JsonNumberHandling.AllowReadingFromString)]
public long CreateTimestamp { get; set; }
}
}

View File

@ -0,0 +1,10 @@
<xml>
<ServiceCorpId><![CDATA[xxxx]]></ServiceCorpId>
<InfoType><![CDATA[advanced_api_expired]]></InfoType>
<AuthCorpId><![CDATA[yyyy]]></AuthCorpId>
<AdvanceApiType><![CDATA[1]]></AdvanceApiType>
<ChatArchiveApi>
<Edition><![CDATA[2]]></Edition>
</ChatArchiveApi>
<TimeStamp>1403610513</TimeStamp>
</xml>

View File

@ -0,0 +1,7 @@
<xml>
<ServiceCorpId><![CDATA[xxxx]]></ServiceCorpId>
<InfoType><![CDATA[advanced_api_trial_expired]]></InfoType>
<AuthCorpId><![CDATA[yyyy]]></AuthCorpId>
<AdvanceApiType><![CDATA[1]]></AdvanceApiType>
<TimeStamp>1403610513</TimeStamp>
</xml>

View File

@ -0,0 +1,30 @@
{
"errcode": 0,
"errmsg": "ok",
"auth_edition_list": [
{
"edition": 1,
"auth_scope": {
"userid_list": [ "xxxx" ],
"department_id_list": [ 1, 2, 3 ],
"tag_id_list": [ 10, 11 ]
},
"status": 1,
"begin_time": 1726588800,
"end_time": 1729180799,
"msg_duration_days": 90
},
{
"edition": 2,
"auth_scope": {
"userid_list": [ "xxxx" ],
"department_id_list": [ 1, 2 ],
"tag_id_list": [ 10 ]
},
"status": 1,
"begin_time": 1726588800,
"end_time": 1729180799,
"msg_duration_days": 90
}
]
}

View File

@ -0,0 +1,4 @@
{
"program_id": "xxxx",
"log_level": 2
}

View File

@ -0,0 +1,7 @@
{
"errcode": 0,
"errmsg": "",
"type": "file",
"media_id": "1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0",
"created_at": "1380000000"
}