feat(0): [java]-[mvn]-消息回调配置文件参数名称修改

This commit is contained in:
chandler 2024-12-25 10:52:52 +08:00
parent 0174c97faf
commit e9e2015520
5 changed files with 61 additions and 61 deletions

View File

@ -47,24 +47,24 @@ public class WeChatFerryProperties {
private List<String> openMsgGroups; private List<String> openMsgGroups;
/** /**
* 接收消息转发开关 * 接收消息回调开关
*/ */
private Boolean receiveMsgFwdSwitch = false; private Boolean receiveMsgCallbackSwitch = false;
/** /**
* 接收消息转发URL * 接收消息回调地址
*/ */
private List<String> receiveMsgFwdUrls; private List<String> receiveMsgCallbackUrls;
/** /**
* 发送消息转发标识 1-关闭 2-全转发 3-发送成功才转发 * 发送消息回调标识 1-关闭 2-全部回调 3-发送成功才回调
*/ */
private String sendMsgFwdFlag = "1"; private String sendMsgCallbackFlag = "1";
/** /**
* 发送消息转发URL * 发送消息回调地址
*/ */
private List<String> sendMsgFwdUrls; private List<String> sendMsgCallbackUrls;
/** /**
* 调用第三方服务客户端成功状态码 * 调用第三方服务客户端成功状态码

View File

@ -8,15 +8,15 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/** /**
* 枚举-消息转发开关 * 枚举-消息回调开关
* 1-关闭 2-转发 3-发送成功才转发 * 1-关闭 2-部回调 3-发送成功才回调
* *
* @author chandler * @author chandler
* @date 2024/10/01 15:42 * @date 2024/10/01 15:42
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum MsgFwdTypeEnum { public enum MsgCallbackTypeEnum {
/** /**
* 1-关闭 * 1-关闭
@ -24,14 +24,14 @@ public enum MsgFwdTypeEnum {
CLOSE("1", "关闭"), CLOSE("1", "关闭"),
/** /**
* 2-转发 * 2-部回调
*/ */
ALL("2", "转发"), ALL("2", "部回调"),
/** /**
* 3-发送成功才转发 * 3-发送成功才回调
*/ */
SUCCESS("3", "发送成功才转发"), SUCCESS("3", "发送成功才回调"),
/** /**
* 未匹配上 * 未匹配上
@ -47,12 +47,13 @@ public enum MsgFwdTypeEnum {
/** /**
* map集合 keycode val枚举 * map集合 keycode val枚举
*/ */
public static final Map<String, MsgFwdTypeEnum> codeMap = Arrays.stream(values()).collect(Collectors.toMap(MsgFwdTypeEnum::getCode, v -> v)); public static final Map<String, MsgCallbackTypeEnum> codeMap =
Arrays.stream(values()).collect(Collectors.toMap(MsgCallbackTypeEnum::getCode, v -> v));
/** /**
* 根据code获取枚举 * 根据code获取枚举
*/ */
public static MsgFwdTypeEnum getCodeMap(String code) { public static MsgCallbackTypeEnum getCodeMap(String code) {
return codeMap.getOrDefault(code, UN_MATCH); return codeMap.getOrDefault(code, UN_MATCH);
} }

View File

@ -50,7 +50,7 @@ import com.wechat.ferry.entity.vo.response.WxPpWcfSendRichTextMsgResp;
import com.wechat.ferry.entity.vo.response.WxPpWcfSendTextMsgResp; import com.wechat.ferry.entity.vo.response.WxPpWcfSendTextMsgResp;
import com.wechat.ferry.entity.vo.response.WxPpWcfSendXmlMsgResp; import com.wechat.ferry.entity.vo.response.WxPpWcfSendXmlMsgResp;
import com.wechat.ferry.enums.DatabaseNameEnum; import com.wechat.ferry.enums.DatabaseNameEnum;
import com.wechat.ferry.enums.MsgFwdTypeEnum; import com.wechat.ferry.enums.MsgCallbackTypeEnum;
import com.wechat.ferry.enums.SexEnum; import com.wechat.ferry.enums.SexEnum;
import com.wechat.ferry.enums.WxContactsMixedEnum; import com.wechat.ferry.enums.WxContactsMixedEnum;
import com.wechat.ferry.enums.WxContactsOfficialEnum; import com.wechat.ferry.enums.WxContactsOfficialEnum;
@ -306,9 +306,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
Wcf.Response rsp = wechatSocketClient.sendCmd(req); Wcf.Response rsp = wechatSocketClient.sendCmd(req);
// 0 为成功其他失败 // 0 为成功其他失败
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[文本消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[文本消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -325,9 +325,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
log.debug("sendRichText: {}", wechatSocketClient.bytesToHex(req.toByteArray())); log.debug("sendRichText: {}", wechatSocketClient.bytesToHex(req.toByteArray()));
Wcf.Response rsp = wechatSocketClient.sendCmd(req); Wcf.Response rsp = wechatSocketClient.sendCmd(req);
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[富文本消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[富文本消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -348,9 +348,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
log.debug("sendXml: {}", wechatSocketClient.bytesToHex(req.toByteArray())); log.debug("sendXml: {}", wechatSocketClient.bytesToHex(req.toByteArray()));
Wcf.Response rsp = wechatSocketClient.sendCmd(req); Wcf.Response rsp = wechatSocketClient.sendCmd(req);
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[XML消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[XML消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -366,9 +366,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
log.debug("sendImage: {}", wechatSocketClient.bytesToHex(req.toByteArray())); log.debug("sendImage: {}", wechatSocketClient.bytesToHex(req.toByteArray()));
Wcf.Response rsp = wechatSocketClient.sendCmd(req); Wcf.Response rsp = wechatSocketClient.sendCmd(req);
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[图片消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[图片消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -384,9 +384,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
log.debug("sendEmotion: {}", wechatSocketClient.bytesToHex(req.toByteArray())); log.debug("sendEmotion: {}", wechatSocketClient.bytesToHex(req.toByteArray()));
Wcf.Response rsp = wechatSocketClient.sendCmd(req); Wcf.Response rsp = wechatSocketClient.sendCmd(req);
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[表情消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[表情消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -401,9 +401,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
log.debug("sendFile: {}", wechatSocketClient.bytesToHex(req.toByteArray())); log.debug("sendFile: {}", wechatSocketClient.bytesToHex(req.toByteArray()));
Wcf.Response rsp = wechatSocketClient.sendCmd(req); Wcf.Response rsp = wechatSocketClient.sendCmd(req);
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[文件消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[文件消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -417,9 +417,9 @@ public class WeChatDllServiceImpl implements WeChatDllService {
Wcf.Request wcfReq = Wcf.Request.newBuilder().setFuncValue(Wcf.Functions.FUNC_SEND_PAT_MSG_VALUE).setPm(patMsg).build(); Wcf.Request wcfReq = Wcf.Request.newBuilder().setFuncValue(Wcf.Functions.FUNC_SEND_PAT_MSG_VALUE).setPm(patMsg).build();
Wcf.Response rsp = wechatSocketClient.sendCmd(wcfReq); Wcf.Response rsp = wechatSocketClient.sendCmd(wcfReq);
int state = judgeWcfCmdState(rsp); int state = judgeWcfCmdState(rsp);
// 转发处理 // 回调处理
String stringJson = JSON.toJSONString(request); String stringJson = JSON.toJSONString(request);
sendMsgForward(stringJson, state); sendMsgCallback(stringJson, state);
long endTime = System.currentTimeMillis(); long endTime = System.currentTimeMillis();
log.info("[发送消息]-[拍一拍消息]-处理结束,耗时:{}ms", (endTime - startTime)); log.info("[发送消息]-[拍一拍消息]-处理结束,耗时:{}ms", (endTime - startTime));
return null; return null;
@ -624,7 +624,7 @@ public class WeChatDllServiceImpl implements WeChatDllService {
} }
/** /**
* 消息转发 * 消息回调
* *
* @param jsonString json数据 * @param jsonString json数据
* @param state cmd调用状态 * @param state cmd调用状态
@ -632,27 +632,27 @@ public class WeChatDllServiceImpl implements WeChatDllService {
* @author chandler * @author chandler
* @date 2024-10-10 23:10 * @date 2024-10-10 23:10
*/ */
private void sendMsgForward(String jsonString, Integer state) { private void sendMsgCallback(String jsonString, Integer state) {
// 根据配置文件决定是否转发 // 根据配置文件决定是否回调
if (MsgFwdTypeEnum.CLOSE.getCode().equals(weChatFerryProperties.getSendMsgFwdFlag()) if (MsgCallbackTypeEnum.CLOSE.getCode().equals(weChatFerryProperties.getSendMsgCallbackFlag())
|| (MsgFwdTypeEnum.SUCCESS.getCode().equals(weChatFerryProperties.getSendMsgFwdFlag()) && 0 != state)) { || (MsgCallbackTypeEnum.SUCCESS.getCode().equals(weChatFerryProperties.getSendMsgCallbackFlag()) && 0 != state)) {
// 如果是关闭 或者 配置为成功才转发但发送状态为失败 的情况则取消发送 // 如果是关闭 或者 配置为成功才回调但发送状态为失败 的情况则取消发送
return; return;
} }
// 开启转发且转发地址不为空 // 开启回调且回调地址不为空
if (!CollectionUtils.isEmpty(weChatFerryProperties.getSendMsgFwdUrls())) { if (!CollectionUtils.isEmpty(weChatFerryProperties.getSendMsgCallbackUrls())) {
for (String receiveMsgFwdUrl : weChatFerryProperties.getSendMsgFwdUrls()) { for (String receiveMsgFwdUrl : weChatFerryProperties.getSendMsgCallbackUrls()) {
if (!receiveMsgFwdUrl.startsWith("http")) { if (!receiveMsgFwdUrl.startsWith("http")) {
continue; continue;
} }
try { try {
String responseStr = HttpClientUtil.doPostJson(receiveMsgFwdUrl, jsonString); String responseStr = HttpClientUtil.doPostJson(receiveMsgFwdUrl, jsonString);
if (judgeSuccess(responseStr)) { if (judgeSuccess(responseStr)) {
log.error("[发送消息]-消息转发外部接口,获取响应状态失败!-URL{}", receiveMsgFwdUrl); log.error("[发送消息]-消息回调至外部接口,获取响应状态失败!-URL{}", receiveMsgFwdUrl);
} }
log.debug("[发送消息]-[转发接收到的消息]-转发消息至:{}", receiveMsgFwdUrl); log.debug("[发送消息]-[回调接收到的消息]-回调消息至:{}", receiveMsgFwdUrl);
} catch (Exception e) { } catch (Exception e) {
log.error("[发送消息]-消息转发接口[{}]服务异常:", receiveMsgFwdUrl, e); log.error("[发送消息]-消息回调接口[{}]服务异常:", receiveMsgFwdUrl, e);
} }
} }
} }

View File

@ -4,7 +4,6 @@ import java.util.Map;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
@ -34,7 +33,7 @@ public class WeChatMsgServiceImpl implements WeChatMsgService {
@Override @Override
public void receiveMsg(String jsonString) { public void receiveMsg(String jsonString) {
// 转发接口处理 // 转发接口处理
receiveMsgForward(jsonString); receiveMsgCallback(jsonString);
// 转为JSON对象 // 转为JSON对象
WxPpMsgDTO dto = JSON.parseObject(jsonString, WxPpMsgDTO.class); WxPpMsgDTO dto = JSON.parseObject(jsonString, WxPpMsgDTO.class);
// 有开启的群聊配置 // 有开启的群聊配置
@ -47,21 +46,21 @@ public class WeChatMsgServiceImpl implements WeChatMsgService {
log.debug("[收到消息]-[消息内容]-打印:{}", dto); log.debug("[收到消息]-[消息内容]-打印:{}", dto);
} }
private void receiveMsgForward(String jsonString) { private void receiveMsgCallback(String jsonString) {
// 开启转发且转发地址不为空 // 开启回调且回调地址不为空
if (weChatFerryProperties.getReceiveMsgFwdSwitch() && !CollectionUtils.isEmpty(weChatFerryProperties.getReceiveMsgFwdUrls())) { if (weChatFerryProperties.getReceiveMsgCallbackSwitch() && !CollectionUtils.isEmpty(weChatFerryProperties.getReceiveMsgCallbackUrls())) {
for (String receiveMsgFwdUrl : weChatFerryProperties.getReceiveMsgFwdUrls()) { for (String receiveMsgFwdUrl : weChatFerryProperties.getReceiveMsgCallbackUrls()) {
if (!receiveMsgFwdUrl.startsWith("http")) { if (!receiveMsgFwdUrl.startsWith("http")) {
continue; continue;
} }
try { try {
String responseStr = HttpClientUtil.doPostJson(receiveMsgFwdUrl, jsonString); String responseStr = HttpClientUtil.doPostJson(receiveMsgFwdUrl, jsonString);
if (judgeSuccess(responseStr)) { if (judgeSuccess(responseStr)) {
log.error("[接收消息]-消息转发外部接口,获取响应状态失败!-URL{}", receiveMsgFwdUrl); log.error("[接收消息]-消息回调至外部接口,获取响应状态失败!-URL{}", receiveMsgFwdUrl);
} }
log.debug("[接收消息]-[转发接收到的消息]-转发消息至:{}", receiveMsgFwdUrl); log.debug("[接收消息]-[回调接收到的消息]-回调消息至:{}", receiveMsgFwdUrl);
} catch (Exception e) { } catch (Exception e) {
log.error("[接收消息]-消息转发接口[{}]服务异常:", receiveMsgFwdUrl, e); log.error("[接收消息]-消息回调接口[{}]服务异常:", receiveMsgFwdUrl, e);
} }
} }
} }

View File

@ -35,15 +35,15 @@ wechat:
# 需要开启消息处理的群 # 需要开启消息处理的群
open-msg-groups: open-msg-groups:
- 53257911728@chatroom - 53257911728@chatroom
# 接收消息转发开关 # 接收消息回调开关
receive-msg-fwd-switch: false receive-msg-callback-switch: false
# 接收消息转发URL # 接收消息回调地址
receive-msg-fwd-urls: receive-msg-callback-urls:
- http://localhost:9001/msg - http://localhost:9001/msg
# 发送消息转发标识 1-关闭 2-全转发 3-发送成功才转发 # 发送消息回调标识 1-关闭 2-全部回调 3-发送成功才回调
send-msg-fwd-flag: '1' send-msg-callback-flag: '1'
# 发送消息转发URL # 发送消息回调地址
send-msg-fwd-urls: send-msg-callback-urls:
- http://localhost:9001/msg - http://localhost:9001/msg
# 调用第三方服务客户端成功状态码 # 调用第三方服务客户端成功状态码
third-party-ok-codes: third-party-ok-codes: