#281 消息路由器增加对EventKey正则表达式匹配的支持

This commit is contained in:
Binary Wang
2017-07-15 18:05:00 +08:00
committed by Binary Wang
parent 33d5f87229
commit e36d16f2a2
3 changed files with 37 additions and 14 deletions

View File

@@ -6,6 +6,7 @@ import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
import org.apache.commons.lang3.StringUtils;
import java.util.ArrayList;
import java.util.HashMap;
@@ -27,6 +28,8 @@ public class WxCpMessageRouterRule {
private String eventKey;
private String eventKeyRegex;
private String content;
private String rContent;
@@ -95,6 +98,14 @@ public class WxCpMessageRouterRule {
return this;
}
/**
* 如果eventKey匹配该正则表达式
*/
public WxCpMessageRouterRule eventKeyRegex(String regex) {
this.eventKeyRegex = regex;
return this;
}
/**
* 如果content等于某值
*
@@ -207,17 +218,17 @@ public class WxCpMessageRouterRule {
&&
(this.agentId == null || this.agentId.equals(wxMessage.getAgentId()))
&&
(this.msgType == null || this.msgType.equals(wxMessage.getMsgType()))
(this.msgType == null || this.msgType.equalsIgnoreCase(wxMessage.getMsgType()))
&&
(this.event == null || this.event.equals(wxMessage.getEvent()))
(this.event == null || this.event.equalsIgnoreCase(wxMessage.getEvent()))
&&
(this.eventKey == null || this.eventKey.equals(wxMessage.getEventKey()))
(this.eventKey == null || this.eventKey.equalsIgnoreCase(wxMessage.getEventKey()))
&&
(this.content == null || this.content
.equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
(this.eventKeyRegex == null || Pattern.matches(this.eventKeyRegex, StringUtils.trimToEmpty(wxMessage.getEventKey())))
&&
(this.rContent == null || Pattern
.matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
(this.content == null || this.content.equals(StringUtils.trimToNull(wxMessage.getContent())))
&&
(this.rContent == null || Pattern.matches(this.rContent, StringUtils.trimToEmpty(wxMessage.getContent())))
&&
(this.matcher == null || this.matcher.match(wxMessage))
;