1
0
mirror of synced 2026-02-11 14:17:48 +08:00

issue #77 添加自定义消息匹配器的支持

This commit is contained in:
Daniel Qian
2015-01-22 20:37:26 +08:00
parent b00bf13bd7
commit 36dad7b8d0
6 changed files with 90 additions and 7 deletions

View File

@@ -0,0 +1,17 @@
package me.chanjar.weixin.cp.api;
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
/**
* 消息匹配器,用在消息路由的时候
*/
public interface WxCpMessageMatcher {
/**
* 消息是否匹配某种模式
* @param message
* @return
*/
public boolean match(WxCpXmlMessage message);
}

View File

@@ -228,6 +228,8 @@ public class WxCpMessageRouter {
private String rContent;
private WxCpMessageMatcher matcher;
private boolean reEnter = false;
private Integer agentId;
@@ -320,6 +322,16 @@ public class WxCpMessageRouter {
return this;
}
/**
* 如果消息匹配某个matcher用在用户需要自定义更复杂的匹配规则的时候
* @param matcher
* @return
*/
public Rule matcher(WxCpMessageMatcher matcher) {
this.matcher = matcher;
return this;
}
/**
* 设置微信消息拦截器
* @param interceptor
@@ -403,6 +415,8 @@ public class WxCpMessageRouter {
(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()))
&&
(this.matcher == null || this.matcher.match(wxMessage))
;
}