feat: [java]-[mvn]-修改群消息策略功能,支持指定对应的群开启对应的功能
This commit is contained in:
parent
8cfb5a2f82
commit
197550aead
2
clients/java/wechat-ferry-mvn/CHANGELOG.md
vendored
2
clients/java/wechat-ferry-mvn/CHANGELOG.md
vendored
@ -61,6 +61,8 @@ ___
|
|||||||
### 2025-05-01
|
### 2025-05-01
|
||||||
|
|
||||||
- 1.更新DLL版本迭代
|
- 1.更新DLL版本迭代
|
||||||
|
- 2.更新说明文件
|
||||||
|
- 3.修改群消息策略功能,支持指定对应的群开启对应的功能
|
||||||
|
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
|
@ -42,9 +42,16 @@ public class WeChatFerryProperties {
|
|||||||
private List<String> contactsTypeOfficial;
|
private List<String> contactsTypeOfficial;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 需要开启消息处理的群
|
* 消息处理的群开关
|
||||||
*/
|
*/
|
||||||
private List<String> openMsgGroups;
|
private Boolean openMsgGroupSwitch = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 需要开启消息处理的群
|
||||||
|
* 格式:key:群编号 val:开启的功能号,对应ReceiveMsgChannelEnum枚举中的code
|
||||||
|
* 53257911728@chatroom: 1,2
|
||||||
|
*/
|
||||||
|
private Map<String, String> openMsgGroups;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 接收消息回调开关
|
* 接收消息回调开关
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
package com.wechat.ferry.service.impl;
|
package com.wechat.ferry.service.impl;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@ -39,21 +44,57 @@ public class WeChatMsgServiceImpl implements WeChatMsgService {
|
|||||||
// 转为JSON对象
|
// 转为JSON对象
|
||||||
WxPpMsgDTO dto = JSON.parseObject(jsonString, WxPpMsgDTO.class);
|
WxPpMsgDTO dto = JSON.parseObject(jsonString, WxPpMsgDTO.class);
|
||||||
// 有开启的群聊配置
|
// 有开启的群聊配置
|
||||||
if (!CollectionUtils.isEmpty(weChatFerryProperties.getOpenMsgGroups())) {
|
if (weChatFerryProperties.getOpenMsgGroupSwitch() && !weChatFerryProperties.getOpenMsgGroups().isEmpty()) {
|
||||||
// 指定处理的群聊
|
Map<String, List<String>> openMsgGroupMap = new HashMap<>();
|
||||||
if (weChatFerryProperties.getOpenMsgGroups().contains(dto.getRoomId()) || weChatFerryProperties.getOpenMsgGroups().contains("ALL")) {
|
String allFnNoStr = "";
|
||||||
// TODO 模式有多种 1-根据消息类型单独调用某一个 2-全部调用,各业务类中自己决定是否继续
|
List<String> allFnNoList = new ArrayList<>();
|
||||||
if (true) {
|
if (weChatFerryProperties.getOpenMsgGroups().containsKey("ALL")) {
|
||||||
// 因为一种消息允许进行多种处理,这里采用执行所有策略,请自行在各策略中判断是否需要执行
|
allFnNoStr = weChatFerryProperties.getOpenMsgGroups().get("ALL");
|
||||||
for (ReceiveMsgStrategy value : ReceiveMsgFactory.getAllStrategyContainers().values()) {
|
// 分割字符串并去除空格及空元素
|
||||||
value.doHandle(dto);
|
allFnNoList = Arrays.stream(allFnNoStr.split(","))
|
||||||
|
// 去掉前后空格
|
||||||
|
.map(String::trim)
|
||||||
|
// 过滤掉空字符串
|
||||||
|
.filter(s -> !s.isEmpty())
|
||||||
|
// 去重
|
||||||
|
.distinct().collect(Collectors.toList());
|
||||||
|
openMsgGroupMap.put("ALL", allFnNoList);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 遍历
|
||||||
|
for (String key : weChatFerryProperties.getOpenMsgGroups().keySet()) {
|
||||||
|
List<String> valList = new ArrayList<>();
|
||||||
|
if (!"ALL".equals(key)) {
|
||||||
|
String str = weChatFerryProperties.getOpenMsgGroups().get(key);
|
||||||
|
String[] arr = str.split(",");
|
||||||
|
for (String s : arr) {
|
||||||
|
// 去重,且ALL中不包含
|
||||||
|
if (!valList.contains(s) && !allFnNoList.contains(s)) {
|
||||||
|
valList.add(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
openMsgGroupMap.put(key, valList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 指定处理的群聊
|
||||||
|
if (!openMsgGroupMap.isEmpty()) {
|
||||||
|
List<String> fnNoList = new ArrayList<>();
|
||||||
|
// 先执行所有群都需要执行的
|
||||||
|
if (openMsgGroupMap.containsKey("ALL")) {
|
||||||
|
fnNoList = openMsgGroupMap.get("ALL");
|
||||||
|
}
|
||||||
|
// 加入个性化的
|
||||||
|
if (openMsgGroupMap.containsKey(dto.getRoomId())) {
|
||||||
|
fnNoList.addAll(openMsgGroupMap.get(dto.getRoomId()));
|
||||||
|
}
|
||||||
|
// 需要执行的策略
|
||||||
|
if (!CollectionUtils.isEmpty(fnNoList)) {
|
||||||
|
for (String no : fnNoList) {
|
||||||
|
// 根据功能号获取对应的策略
|
||||||
|
ReceiveMsgStrategy receiveMsgStrategy = ReceiveMsgFactory.getStrategy(no);
|
||||||
|
receiveMsgStrategy.doHandle(dto);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// 单独调用某一种
|
|
||||||
// 这里自己把消息类型转为自己的枚举类型
|
|
||||||
String handleType = "1";
|
|
||||||
ReceiveMsgStrategy receiveMsgStrategy = ReceiveMsgFactory.getStrategy(handleType);
|
|
||||||
receiveMsgStrategy.doHandle(dto);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,9 +32,13 @@ wechat:
|
|||||||
# 联系人类型-公众号,禁止与其他分类重复(格式:代码|名称)
|
# 联系人类型-公众号,禁止与其他分类重复(格式:代码|名称)
|
||||||
contacts-type-official:
|
contacts-type-official:
|
||||||
- weixinguanhaozhushou|微信公众平台
|
- weixinguanhaozhushou|微信公众平台
|
||||||
|
# 接收消息回调开关
|
||||||
|
open-msg-group-switch: false
|
||||||
# 需要开启消息处理的群
|
# 需要开启消息处理的群
|
||||||
open-msg-groups:
|
open-msg-groups:
|
||||||
- 53257911728@chatroom
|
# key:群编号 val:开启的功能号,对应ReceiveMsgChannelEnum枚举中的code
|
||||||
|
ALL: '1'
|
||||||
|
53257911730@chatroom: '1,2'
|
||||||
# 接收消息回调开关
|
# 接收消息回调开关
|
||||||
receive-msg-callback-switch: false
|
receive-msg-callback-switch: false
|
||||||
# 接收消息回调地址
|
# 接收消息回调地址
|
||||||
|
Loading…
Reference in New Issue
Block a user