Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…into Developer
  • Loading branch information
JeffreySu committed Nov 27, 2023
2 parents 2680508 + d12f69c commit 83fd876
Show file tree
Hide file tree
Showing 9 changed files with 403 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,50 @@ public void RequestMessageEvent_Change_Contact_User_Create()

}


/// <summary>
/// 创建成员
/// </summary>
[TestMethod]
public async Task RequestMessageEvent_Change_External_Chat_Update()
{
//官方提供
var xml = @"<xml>
<ToUserName><![CDATA[wwea4ccebadeefd11a]]></ToUserName>
<FromUserName><![CDATA[sys]]></FromUserName>
<CreateTime>1700642907</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[change_external_chat]]></Event>
<ChatId><![CDATA[wree9uDgAAfxkLu5-lEbsmQBjsb7V8Cg]]></ChatId>
<ChangeType><![CDATA[update]]></ChangeType>
<UpdateDetail><![CDATA[change_name]]></UpdateDetail>
<JoinScene>0</JoinScene>
<MemChangeCnt>2</MemChangeCnt>
<LastMemVer><![CDATA[6ebe7c3f89cb839ec2e1720f04eae2e0]]></LastMemVer>
<CurMemVer><![CDATA[15722766561cf8bce92480a3d1457654]]></CurMemVer>
</xml>";

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));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ and limitations under the License.
创建标识:lishewen - 20200318
修改标识:XiaoPoTian - 20231122
修改描述:v3.18.1 添加“当前群成员版本号。可以配合客户群变更事件减少主动调用本接口的次数”(member_version)
----------------------------------------------------------------*/

Expand Down Expand Up @@ -78,6 +81,11 @@ public class Group_Chat
/// </summary>
public string notice { get; set; }

/// <summary>
/// 当前群成员版本号。可以配合客户群变更事件减少主动调用本接口的次数
/// </summary>
public string member_version { get; set; }

/// <summary>
/// 群成员列表
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
修改标识:Senparc - 20231026
修改描述:v3.17.0 成员对外联系 > 客户消息通知处理
修改标识:XiaopPoTian - 20231121
修改描述:v3.18.1 删除企业客户事件 > 新加Source,删除客户的操作来源
----------------------------------------------------------------*/

namespace Senparc.Weixin.Work.Entities.Request.Event
Expand Down Expand Up @@ -117,6 +120,11 @@ public class RequestMessageEvent_Change_ExternalContact_Del : RequestMessageEven
/// 外部联系人的userid
/// </summary>
public string ExternalUserID { get; set; }
/// <summary>
/// 删除客户的操作来源,DELETE_BY_TRANSFER表示此客户是因在职继承自动被转接成员删除
///
/// </summary>
public string Source { get; set; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -32,21 +39,24 @@ public override Event Event
/// <summary>
/// 群ID
/// </summary>
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;
/// <summary>
Expand All @@ -67,19 +77,33 @@ public RequestMessageEvent_Change_External_Chat_Update(string UpdateDetailStr)
/// 当是成员入群或退群时有值。表示成员变更数量
/// </summary>
public int MemChangeCnt { get; set; }
/// <summary>
/// 当是成员入群或退群时有值。变更的成员列表
/// </summary>
public string[] MemberChangeList { get; set; }
/// <summary>
/// 当是成员入群或退群时有值。 变更前的群成员版本号
/// </summary>
public string LastMemVer { get; set; }
/// <summary>
/// 当是成员入群或退群时有值。变更后的群成员版本号
/// </summary>
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,
update,
dismiss
}


public enum ExternalChatUpdateDetailType
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*----------------------------------------------------------------
Copyright (C) 2023 XiaoPoTian
文件名:RequestMessageEvent_Change_External_Tag_Base.cs
文件功能描述:企业客户标签或标签组事件
创建标识:XiaoPoTian - 20231119
----------------------------------------------------------------*/

using System;

namespace Senparc.Weixin.Work.Entities
{
/// <summary>
/// 企业客户标签或标签组事件
/// </summary>
public class RequestMessageEvent_Change_External_Tag_Base : RequestMessageEventBase, IRequestMessageEventBase
{
public override Event Event
{
get { return Event.CHANGE_EXTERNAL_TAG; }
}

/// <summary>
/// 标签或标签组ID
/// </summary>
public string Id { get; set; }

/// <summary>
/// 标签或标签组所属的规则组id,只回调给“客户联系”应用
/// </summary>
public string StrategyId { get; set; }
/// <summary>
/// 具体事件类型
/// </summary>
public virtual ExternalTagChangeType ChangeType { get { return ExternalTagChangeType.create; } }
}

/// <summary>
/// 企业客户标签创建
/// </summary>
public class RequestMessageEvent_Change_External_Tag_Create : RequestMessageEvent_Change_External_Tag_Base
{
/// <summary>
/// 变更类型
/// </summary>
public ExternalTagChangeTagType TagType { get; set; }
/// <summary>
/// TagType类型初始化
/// </summary>
/// <param name="TagTypeStr"></param>
public RequestMessageEvent_Change_External_Tag_Create(string TagTypeStr)
{
TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true);
}
}

/// <summary>
/// 企业客户标签变更
/// </summary>
public class RequestMessageEvent_Change_External_Tag_Update : RequestMessageEvent_Change_External_Tag_Base
{
/// <summary>
/// 变更类型
/// </summary>
public ExternalTagChangeTagType TagType { get; set; }
// <summary>
/// TagType类型初始化
/// </summary>
/// <param name="TagTypeStr"></param>
public RequestMessageEvent_Change_External_Tag_Update(string TagTypeStr)
{
TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true);
}
/// <summary>
/// 重写具体事件类型
/// </summary>
public override ExternalTagChangeType ChangeType => ExternalTagChangeType.update;

}

/// <summary>
/// 企业客户标签删除
/// </summary>
public class RequestMessageEvent_Change_External_Tag_Delete : RequestMessageEvent_Change_External_Tag_Base
{
/// <summary>
/// 变更类型
/// </summary>
public ExternalTagChangeTagType TagType { get; set; }
// <summary>
/// TagType类型初始化
/// </summary>
/// <param name="TagTypeStr"></param>
public RequestMessageEvent_Change_External_Tag_Delete(string TagTypeStr)
{
TagType = (ExternalTagChangeTagType)Enum.Parse(typeof(ExternalTagChangeTagType), TagTypeStr, true);
}
/// <summary>
/// 重写具体事件类型
/// </summary>
public override ExternalTagChangeType ChangeType => ExternalTagChangeType.delete;
}

/// <summary>
/// 企业客户标签重排
/// </summary>
public class RequestMessageEvent_Change_External_Tag_Shuffle : RequestMessageEvent_Change_External_Tag_Base
{
/// <summary>
/// 重写具体事件类型
/// </summary>
public override ExternalTagChangeType ChangeType => ExternalTagChangeType.shuffle;
}


/// <summary>
/// 具体的事件类型
/// </summary>
public enum ExternalTagChangeType
{
/// <summary>
/// 创建
/// </summary>
create,
/// <summary>
/// 更新
/// </summary>
update,
/// <summary>
/// 删除
/// </summary>
delete,
/// <summary>
/// 重新排序
/// </summary>
shuffle,
}

/// <summary>
/// 变更类型
/// </summary>
public enum ExternalTagChangeTagType
{
/// <summary>
/// 变更标签
/// </summary>
tag,
/// <summary>
/// 变更标签组
/// </summary>
tag_group,
}
}
7 changes: 7 additions & 0 deletions src/Senparc.Weixin.Work/Senparc.Weixin.Work/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -180,6 +183,10 @@ public enum Event
/// </summary>
CHANGE_EXTERNAL_CHAT,
/// <summary>
/// 企业客户标签变更事件
/// </summary>
CHANGE_EXTERNAL_TAG,
/// <summary>
/// 直播回调事件
/// </summary>
LIVING_STATUS_CHANGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
修改标识:Senparc - 20210324
修改描述:v3.14.6 添加:审批申请状态变化回调通知: "SYS_APPROVAL_CHANGE"
修改标识:XiaoPoTian - 20231119
修改描述:v3.18.1 添加“企业客户标签变更事件回调通知”(CHANGE_EXTERNAL_Tag)
----------------------------------------------------------------*/

using Senparc.NeuChar;
Expand Down Expand Up @@ -182,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();
Expand All @@ -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();
break;
case "UPDATE":
requestMessage = new RequestMessageEvent_Change_External_Tag_Update();
break;
case "DELETE":
requestMessage = new RequestMessageEvent_Change_External_Tag_Delete();
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;
Expand Down
Loading

0 comments on commit 83fd876

Please sign in to comment.