issue #13 添加正则匹配content路由消息的功能
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import chanjarster.weixin.bean.WxXmlMessage;
|
||||
import chanjarster.weixin.bean.WxXmlOutMessage;
|
||||
@@ -110,6 +111,8 @@ public class WxMessageRouter {
|
||||
|
||||
private String content;
|
||||
|
||||
private String rContent;
|
||||
|
||||
private boolean reEnter = false;
|
||||
|
||||
private List<WxMessageHandler> handlers = new ArrayList<WxMessageHandler>();
|
||||
@@ -170,6 +173,16 @@ public class WxMessageRouter {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果content匹配该正则表达式
|
||||
* @param regex
|
||||
* @return
|
||||
*/
|
||||
public Rule rContent(String regex) {
|
||||
this.rContent = regex;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置微信消息拦截器
|
||||
* @param interceptor
|
||||
@@ -247,6 +260,8 @@ public class WxMessageRouter {
|
||||
(this.eventKey == null || this.eventKey.equals(wxMessage.getEventKey()))
|
||||
&&
|
||||
(this.content == null || this.content.equals(wxMessage.getContent() == null ? null : wxMessage.getContent().trim()))
|
||||
&&
|
||||
(this.rContent == null || Pattern.matches(this.rContent, wxMessage.getContent() == null ? "" : wxMessage.getContent().trim()))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user