From 0ace8294a5c490c9278142d44f01a70a32e1a5c7 Mon Sep 17 00:00:00 2001 From: zoulu <545926080@qq.com> Date: Sun, 19 Nov 2023 14:57:46 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=96=B0=E5=8A=A0=E4=BC=81=E4=B8=9A?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E4=BC=81=E4=B8=9A=E5=AE=A2=E6=88=B7=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=9B=9E=E8=B0=83=E4=BA=8B=E4=BB=B6=20https://develop?= =?UTF-8?q?er.work.weixin.qq.com/document/path/92130#%E4%BC%81%E4%B8%9A%E5?= =?UTF-8?q?%AE%A2%E6%88%B7%E6%A0%87%E7%AD%BE%E5%88%9B%E5%BB%BA%E4%BA%8B%E4?= =?UTF-8?q?%BB%B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/RequestMessageEvent_External_Tag.cs | 131 ++++++++++++++++++ .../Senparc.Weixin.Work/Enums.cs | 7 + .../DefaultWorkMessageContext.cs | 23 +++ .../Async/WorkMessageHandler.Async.cs | 77 ++++++++++ .../MessageHandlers/WorkMessageHandler.cs | 50 +++++++ 5 files changed, 288 insertions(+) create mode 100644 src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs new file mode 100644 index 0000000000..f12c357a9f --- /dev/null +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs @@ -0,0 +1,131 @@ +/*---------------------------------------------------------------- + Copyright (C) 2023 XiaoPoTian + + 文件名:RequestMessageEvent_Change_External_Tag_Base.cs + 文件功能描述:企业客户标签或标签组事件 + + + 创建标识:XiaoPoTian - 20231119 + +----------------------------------------------------------------*/ + +using System; + +namespace Senparc.Weixin.Work.Entities +{ + /// + /// 企业客户标签或标签组事件 + /// + public class RequestMessageEvent_Change_External_Tag_Base : RequestMessageEventBase, IRequestMessageEventBase + { + public override Event Event + { + get { return Event.CHANGE_EXTERNAL_TAG; } + } + + /// + /// 标签或标签组ID + /// + public string Id { get; set; } + + /// + /// 标签或标签组所属的规则组id,只回调给“客户联系”应用 + /// + public string StrategyId { get; set; } + + public virtual ExternalTagChangeType ChangeType { get { return ExternalTagChangeType.create; } } + } + + /// + /// 企业客户标签创建 + /// + public class RequestMessageEvent_Change_External_Tag_Create : RequestMessageEvent_Change_External_Tag_Base + { + /// + /// 变更类型 + /// + public ExternalTagChangeTagType TagType { get; set; } + public RequestMessageEvent_Change_External_Tag_Create(string TagTypeStr) + { + TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true); + } + } + + /// + /// 企业客户标签变更 + /// + public class RequestMessageEvent_Change_External_Tag_Update : RequestMessageEvent_Change_External_Tag_Base + { + /// + /// 变更类型 + /// + public ExternalTagChangeTagType TagType { get; set; } + public RequestMessageEvent_Change_External_Tag_Update(string TagTypeStr) + { + TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true); + } + public override ExternalTagChangeType ChangeType => ExternalTagChangeType.update; + + } + + /// + /// 企业客户标签删除 + /// + public class RequestMessageEvent_Change_External_Tag_Delete : RequestMessageEvent_Change_External_Tag_Base + { + /// + /// 变更类型 + /// + public ExternalTagChangeTagType TagType { get; set; } + public RequestMessageEvent_Change_External_Tag_Delete(string TagTypeStr) + { + TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true); + } + public override ExternalTagChangeType ChangeType => ExternalTagChangeType.delete; + } + + /// + /// 企业客户标签重排 + /// + public class RequestMessageEvent_Change_External_Tag_Shuffle : RequestMessageEvent_Change_External_Tag_Base + { + public override ExternalTagChangeType ChangeType => ExternalTagChangeType.shuffle; + } + + + + public enum ExternalTagChangeType + { + /// + /// 创建 + /// + create, + /// + /// 更新 + /// + update, + /// + /// 删除 + /// + delete, + /// + /// 重新排序 + /// + shuffle, + } + + /// + /// 变更类型 + /// + public enum ExternalTagChangeTagType + { + /// + /// 变更标签 + /// + tag, + /// + /// 变更标签组 + /// + tag_group, + } +} diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Enums.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Enums.cs index 38223d822d..e70290cf33 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Enums.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Enums.cs @@ -52,6 +52,9 @@ GroupTaskSentStatus 枚举 修改标识:Senparc - 20230914 修改描述:v3.16.4 企业微信三方代开发处理事件: 修复 Async 方法循环调用的 Bug,添加 ThirdPartyInfo 枚举值 + 修改标识:XiaoPoTian - 20231119 + 修改描述:v3.18.1 添加枚举“企业客户标签变更事件”(CHANGE_EXTERNAL_Tag) + ----------------------------------------------------------------*/ using static System.Net.WebRequestMethods; @@ -180,6 +183,10 @@ public enum Event /// CHANGE_EXTERNAL_CHAT, /// + /// 企业客户标签变更事件 + /// + CHANGE_EXTERNAL_TAG, + /// /// 直播回调事件 /// LIVING_STATUS_CHANGE, diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs index 837b2376ef..2ee2a4ab75 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs @@ -21,6 +21,9 @@ 修改标识:Senparc - 20210324 修改描述:v3.14.6 添加:审批申请状态变化回调通知: "SYS_APPROVAL_CHANGE" + + 修改标识:XiaoPoTian - 20231119 + 修改描述:v3.18.1 添加“企业客户标签变更事件回调通知”(CHANGE_EXTERNAL_Tag) ----------------------------------------------------------------*/ using Senparc.NeuChar; @@ -192,6 +195,26 @@ public override IWorkRequestMessageBase GetRequestEntityMappingResult(RequestMsg break; } break; + case "CHANGE_EXTERNAL_TAG"://企业客户标签变更事件推送 + switch (doc.Root.Element("ChangeType").Value.ToUpper()) + { + case "CREATE": + requestMessage = new RequestMessageEvent_Change_External_Tag_Create(doc.Root.Element("TagType").Value); + break; + case "UPDATE": + requestMessage = new RequestMessageEvent_Change_External_Tag_Update(doc.Root.Element("TagType").Value); + break; + case "DELETE": + requestMessage = new RequestMessageEvent_Change_External_Tag_Delete(doc.Root.Element("TagType").Value); + break; + case "SHUFFLE": + requestMessage = new RequestMessageEvent_Change_External_Tag_Shuffle(); + break; + default://其他意外类型(也可以选择抛出异常) + requestMessage = new RequestMessageEventBase(); + break; + } + break; case "LIVING_STATUS_CHANGE"://直播回调事件(living_status_change) requestMessage = new RequestMessageEvent_Living_Status_Change_Base(); break; diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs index 244d6bb7d2..2cebfc0618 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/Async/WorkMessageHandler.Async.cs @@ -331,6 +331,36 @@ public virtual async Task OnEventRequestAsync(IRequest OnEvent_ChangeExternalChatDismissRequestAsync( RequestMessage as RequestMessageEvent_Change_External_Chat_Dismiss); break; + default: + throw new UnknownRequestMsgTypeException("未知的企业客户标签变更事件Event.CHANGE_EXTERNAL_Tag下属请求信息", + null); + } + + break; + case Event.CHANGE_EXTERNAL_TAG: //企业客户标签变更事件 + var tag = RequestMessage as RequestMessageEvent_Change_External_Tag_Base; + switch (tag.ChangeType) + { + case ExternalTagChangeType.create: + responseMessage = await + OnEvent_ChangeExternalTagCreateRequestAsync( + RequestMessage as RequestMessageEvent_Change_External_Tag_Create); + break; + case ExternalTagChangeType.update: + responseMessage = await + OnEvent_ChangeExternalTagUpdateRequestAsync( + RequestMessage as RequestMessageEvent_Change_External_Tag_Update); + break; + case ExternalTagChangeType.delete: + responseMessage = await + OnEvent_ChangeExternalTagDeleteRequestAsync( + RequestMessage as RequestMessageEvent_Change_External_Tag_Delete); + break; + case ExternalTagChangeType.shuffle: + responseMessage = await + OnEvent_ChangeExternalTagShuffleRequestAsync( + RequestMessage as RequestMessageEvent_Change_External_Tag_Shuffle); + break; default: throw new UnknownRequestMsgTypeException("未知的客户群变更事件Event.CHANGE_EXTERNAL_CHAT下属请求信息", null); @@ -671,6 +701,53 @@ public virtual async Task OnEvent_ChangeExternalChatDi return await Task.Run(() => OnEvent_ChangeExternalChatDismissRequest(requestMessage)).ConfigureAwait(false); } + #region 企业客户标签事件 + /// + /// 企业客户标签-创建 + /// + /// + /// + public virtual async Task OnEvent_ChangeExternalTagCreateRequestAsync( + RequestMessageEvent_Change_External_Tag_Create requestMessage) + { + return await Task.Run(() => OnEvent_ChangeExternalTagCreateRequest(requestMessage)).ConfigureAwait(false); + } + + + /// + /// 企业客户标签-变更 + /// + /// + /// + public virtual async Task OnEvent_ChangeExternalTagUpdateRequestAsync( + RequestMessageEvent_Change_External_Tag_Update requestMessage) + { + return await Task.Run(() => OnEvent_ChangeExternalTagUpdateRequest(requestMessage)).ConfigureAwait(false); + } + + /// + /// 企业客户标签-删除 + /// + /// + /// + public virtual async Task OnEvent_ChangeExternalTagDeleteRequestAsync( + RequestMessageEvent_Change_External_Tag_Delete requestMessage) + { + return await Task.Run(() => OnEvent_ChangeExternalTagDeleteRequest(requestMessage)).ConfigureAwait(false); + } + + /// + /// 企业客户标签-重排 + /// + /// + /// + public virtual async Task OnEvent_ChangeExternalTagShuffleRequestAsync( + RequestMessageEvent_Change_External_Tag_Shuffle requestMessage) + { + return await Task.Run(() => OnEvent_ChangeExternalTagShuffleRequest(requestMessage)).ConfigureAwait(false); + } + #endregion + public virtual async Task OnEvent_Living_Status_ChangeRequestAsync( RequestMessageEvent_Living_Status_Change_Base requestMessage) { diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/WorkMessageHandler.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/WorkMessageHandler.cs index 8e7b9c8377..93a0e7113f 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/WorkMessageHandler.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageHandlers/WorkMessageHandler.cs @@ -65,6 +65,9 @@ OnThirdPartyEvent_Contact_Sync 改名为 OnThirdPartyEvent_Change_Contact() 修改标识:Senparc - 20230914 修改描述:v3.16.4 企业微信三方代开发处理事件: 修复 Async 方法循环调用的 Bug + + 修改标识:XiaoPoTian - 20231119 + 修改描述:3.18.1 添加 RequestMessageEvent_Change_External_Tag_Base 事件中 ChangeType 的判断 ----------------------------------------------------------------*/ using System; @@ -796,6 +799,53 @@ public virtual IWorkResponseMessageBase OnEvent_ChangeExternalChatDismissRequest return DefaultResponseMessage(requestMessage); } + #region 企业客户标签事件 + /// + /// 企业客户标签事件-创建 + /// + /// + /// + public virtual IWorkResponseMessageBase OnEvent_ChangeExternalTagCreateRequest( + RequestMessageEvent_Change_External_Tag_Create requestMessage) + { + return DefaultResponseMessage(requestMessage); + } + + + /// + /// 企业客户标签事件-变更 + /// + /// + /// + public virtual IWorkResponseMessageBase OnEvent_ChangeExternalTagUpdateRequest( + RequestMessageEvent_Change_External_Tag_Update requestMessage) + { + return DefaultResponseMessage(requestMessage); + } + + /// + /// 企业客户标签事件-删除 + /// + /// + /// + public virtual IWorkResponseMessageBase OnEvent_ChangeExternalTagDeleteRequest( + RequestMessageEvent_Change_External_Tag_Delete requestMessage) + { + return DefaultResponseMessage(requestMessage); + } + + /// + /// 企业客户标签事件-重排 + /// + /// + /// + public virtual IWorkResponseMessageBase OnEvent_ChangeExternalTagShuffleRequest( + RequestMessageEvent_Change_External_Tag_Shuffle requestMessage) + { + return DefaultResponseMessage(requestMessage); + } + #endregion + public virtual IWorkResponseMessageBase OnEvent_Living_Status_ChangeRequest( RequestMessageEvent_Living_Status_Change_Base requestMessage) { From 60a6bce041e1dc37f28a0c69587ac26a982fd9d8 Mon Sep 17 00:00:00 2001 From: zoulu <545926080@qq.com> Date: Sun, 19 Nov 2023 15:12:28 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Event/RequestMessageEvent_External_Tag.cs | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs index f12c357a9f..3bc000ff46 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Tag.cs @@ -32,7 +32,9 @@ public override Event Event /// 标签或标签组所属的规则组id,只回调给“客户联系”应用 /// public string StrategyId { get; set; } - + /// + /// 具体事件类型 + /// public virtual ExternalTagChangeType ChangeType { get { return ExternalTagChangeType.create; } } } @@ -45,6 +47,10 @@ public class RequestMessageEvent_Change_External_Tag_Create : RequestMessageEven /// 变更类型 /// public ExternalTagChangeTagType TagType { get; set; } + /// + /// TagType类型初始化 + /// + /// public RequestMessageEvent_Change_External_Tag_Create(string TagTypeStr) { TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true); @@ -60,10 +66,17 @@ public class RequestMessageEvent_Change_External_Tag_Update : RequestMessageEven /// 变更类型 /// public ExternalTagChangeTagType TagType { get; set; } + // + /// TagType类型初始化 + /// + /// public RequestMessageEvent_Change_External_Tag_Update(string TagTypeStr) { TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true); } + /// + /// 重写具体事件类型 + /// public override ExternalTagChangeType ChangeType => ExternalTagChangeType.update; } @@ -77,10 +90,17 @@ public class RequestMessageEvent_Change_External_Tag_Delete : RequestMessageEven /// 变更类型 /// public ExternalTagChangeTagType TagType { get; set; } + // + /// TagType类型初始化 + /// + /// public RequestMessageEvent_Change_External_Tag_Delete(string TagTypeStr) { TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true); } + /// + /// 重写具体事件类型 + /// public override ExternalTagChangeType ChangeType => ExternalTagChangeType.delete; } @@ -89,11 +109,16 @@ public RequestMessageEvent_Change_External_Tag_Delete(string TagTypeStr) /// public class RequestMessageEvent_Change_External_Tag_Shuffle : RequestMessageEvent_Change_External_Tag_Base { + /// + /// 重写具体事件类型 + /// public override ExternalTagChangeType ChangeType => ExternalTagChangeType.shuffle; } - + /// + /// 具体的事件类型 + /// public enum ExternalTagChangeType { /// From 6f6bca23e0c50c5725f8b9f9a1a87564a799223c Mon Sep 17 00:00:00 2001 From: zoulu <545926080@qq.com> Date: Wed, 22 Nov 2023 13:42:49 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=BE=A4=E6=96=B0?= =?UTF-8?q?=E5=8A=A0=E7=89=88=E6=9C=AC=E5=8F=B7=20=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E4=BC=81=E4=B8=9A=E5=AE=A2=E6=88=B7=E4=BA=8B=E4=BB=B6=E6=96=B0?= =?UTF-8?q?=E5=8A=A0=E5=88=A0=E9=99=A4=E5=AE=A2=E6=88=B7=E6=93=8D=E4=BD=9C?= =?UTF-8?q?=E6=9D=A5=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AdvancedAPIs/External/GroupChatGetResult.cs | 8 ++++++++ .../Request/Event/RequestMessageEvent_ExternalContact.cs | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/External/GroupChatGetResult.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/External/GroupChatGetResult.cs index 6932119545..b216a65c5b 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/External/GroupChatGetResult.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/AdvancedAPIs/External/GroupChatGetResult.cs @@ -29,6 +29,9 @@ and limitations under the License. 创建标识:lishewen - 20200318 + 修改标识:XiaoPoTian - 20231122 + 修改描述:v3.18.1 添加“当前群成员版本号。可以配合客户群变更事件减少主动调用本接口的次数”(member_version) + ----------------------------------------------------------------*/ @@ -78,6 +81,11 @@ public class Group_Chat /// public string notice { get; set; } + /// + /// 当前群成员版本号。可以配合客户群变更事件减少主动调用本接口的次数 + /// + public string member_version { get; set; } + /// /// 群成员列表 /// diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_ExternalContact.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_ExternalContact.cs index fc2515b4a9..c355e0d24c 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_ExternalContact.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_ExternalContact.cs @@ -19,6 +19,9 @@ 修改标识:Senparc - 20231026 修改描述:v3.17.0 成员对外联系 > 客户消息通知处理 + 修改标识:XiaopPoTian - 20231121 + 修改描述:v3.18.1 删除企业客户事件 > 新加Source,删除客户的操作来源 + ----------------------------------------------------------------*/ namespace Senparc.Weixin.Work.Entities.Request.Event @@ -117,6 +120,11 @@ public class RequestMessageEvent_Change_ExternalContact_Del : RequestMessageEven /// 外部联系人的userid /// public string ExternalUserID { get; set; } + /// + /// 删除客户的操作来源,DELETE_BY_TRANSFER表示此客户是因在职继承自动被转接成员删除 + /// + /// + public string Source { get; set; } } /// From f8b6a6946e39ad3860b9123c2cf87be305f229e4 Mon Sep 17 00:00:00 2001 From: zoulu <545926080@qq.com> Date: Wed, 22 Nov 2023 21:20:20 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=96=B0=E5=8A=A0=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=BE=A4=E5=8F=98=E6=9B=B4=E4=BA=8B=E4=BB=B6MemChangeList=20La?= =?UTF-8?q?stMemVer=20CurMemVer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../WorkMessageHandlerTest.Change_Contact.cs | 45 +++++++++++++++++++ .../RequestMessageEvent_External_Chat.cs | 32 +++++++++++-- .../DefaultWorkMessageContext.cs | 8 ++-- 3 files changed, 77 insertions(+), 8 deletions(-) diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs index a344aa19aa..a6298daa02 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work.Test/MessageHandlers/WorkMessageHandlerTest.Change_Contact.cs @@ -132,5 +132,50 @@ public void RequestMessageEvent_Change_Contact_User_Create() } + + /// + /// 创建成员 + /// + [TestMethod] + public async Task RequestMessageEvent_Change_External_Chat_Update() + { + //官方提供 + var xml = @" + + +1700642907 + + + + + +0 +2 + + +"; + + var postModel = new PostModel() + { + Msg_Signature = "22cb38c34ae9ba4bdec938405b931ad3ece7e19e", + Timestamp = "1644320363", + Nonce = "1645172247", + + Token = "", + EncodingAESKey = "", + CorpId = "" + }; + + var messageHandler = new CustomMessageHandlers(XDocument.Parse(xml), postModel, 10); + await messageHandler.ExecuteAsync(new System.Threading.CancellationToken()); + var responseMessage = messageHandler.ResponseDocument; + + Assert.IsNotNull(messageHandler.RequestMessage); + Assert.AreEqual(RequestMsgType.Event, messageHandler.RequestMessage.MsgType); + Assert.IsInstanceOfType(messageHandler.RequestMessage, typeof(RequestMessageEvent_Change_External_Chat_Update)); + + var requestMessage = messageHandler.RequestMessage as RequestMessageEvent_Change_External_Chat_Update; + Console.WriteLine(requestMessage.MemberChangeList.ToJson(true)); + } } } diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Chat.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Chat.cs index 445f1a607d..c62f88e381 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Chat.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/Entities/Request/Event/RequestMessageEvent_External_Chat.cs @@ -13,9 +13,16 @@ 修改标识:WangDrama - 20210630 修改描述:v3.9.600 添加群直播回调事件 + 修改标识:XiaoPoTian - 20231122 + 修改描述:v3.18.1 添加客户群变更事件(MemChangeList,LastMemVer,CurMemVer) + ----------------------------------------------------------------*/ +using Senparc.CO2NET.Extensions; using System; +using System.Collections.Generic; +using System.Linq; +using System.Xml.Linq; namespace Senparc.Weixin.Work.Entities { @@ -32,21 +39,24 @@ public override Event Event /// /// 群ID /// - public string ChatId { get; set; } + public string ChatId { get; set; } public virtual ExternalChatChangeType ChangeType { get { return ExternalChatChangeType.create; } } } - public class RequestMessageEvent_Change_External_Chat_Create: RequestMessageEvent_Change_External_Chat_Base + public class RequestMessageEvent_Change_External_Chat_Create : RequestMessageEvent_Change_External_Chat_Base { } public class RequestMessageEvent_Change_External_Chat_Update : RequestMessageEvent_Change_External_Chat_Base { - public RequestMessageEvent_Change_External_Chat_Update(string UpdateDetailStr) + public RequestMessageEvent_Change_External_Chat_Update(XElement memChangeListElement) { - UpdateDetail = (ExternalChatUpdateDetailType)Enum.Parse(typeof(ExternalChatUpdateDetailType), UpdateDetailStr, true); + if(memChangeListElement != null) + { + MemberChangeList = memChangeListElement.Elements().Select(u => u.Value).ToArray(); + } } public override ExternalChatChangeType ChangeType => ExternalChatChangeType.update; /// @@ -67,12 +77,25 @@ public RequestMessageEvent_Change_External_Chat_Update(string UpdateDetailStr) /// 当是成员入群或退群时有值。表示成员变更数量 /// public int MemChangeCnt { get; set; } + /// + /// 当是成员入群或退群时有值。变更的成员列表 + /// + public string[] MemberChangeList { get; set; } + /// + /// 当是成员入群或退群时有值。 变更前的群成员版本号 + /// + public string LastMemVer { get; set; } + /// + /// 当是成员入群或退群时有值。变更后的群成员版本号 + /// + public string CurMemVer { get; set; } } public class RequestMessageEvent_Change_External_Chat_Dismiss : RequestMessageEvent_Change_External_Chat_Base { public override ExternalChatChangeType ChangeType => ExternalChatChangeType.dismiss; } + public enum ExternalChatChangeType { create, @@ -80,6 +103,7 @@ public enum ExternalChatChangeType dismiss } + public enum ExternalChatUpdateDetailType { /// diff --git a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs index 2ee2a4ab75..f72359d1b7 100644 --- a/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs +++ b/src/Senparc.Weixin.Work/Senparc.Weixin.Work/MessageContext/DefaultWorkMessageContext.cs @@ -185,7 +185,7 @@ public override IWorkRequestMessageBase GetRequestEntityMappingResult(RequestMsg requestMessage = new RequestMessageEvent_Change_External_Chat_Create(); break; case "UPDATE": - requestMessage = new RequestMessageEvent_Change_External_Chat_Update(doc.Root.Element("UpdateDetail").Value); + requestMessage = new RequestMessageEvent_Change_External_Chat_Update(doc.Root.Element("MemChangeList")); break; case "DISMISS": requestMessage = new RequestMessageEvent_Change_External_Chat_Dismiss(); @@ -199,13 +199,13 @@ public override IWorkRequestMessageBase GetRequestEntityMappingResult(RequestMsg switch (doc.Root.Element("ChangeType").Value.ToUpper()) { case "CREATE": - requestMessage = new RequestMessageEvent_Change_External_Tag_Create(doc.Root.Element("TagType").Value); + requestMessage = new RequestMessageEvent_Change_External_Tag_Create(); break; case "UPDATE": - requestMessage = new RequestMessageEvent_Change_External_Tag_Update(doc.Root.Element("TagType").Value); + requestMessage = new RequestMessageEvent_Change_External_Tag_Update(); break; case "DELETE": - requestMessage = new RequestMessageEvent_Change_External_Tag_Delete(doc.Root.Element("TagType").Value); + requestMessage = new RequestMessageEvent_Change_External_Tag_Delete(); break; case "SHUFFLE": requestMessage = new RequestMessageEvent_Change_External_Tag_Shuffle();