55import me .chanjar .weixin .common .session .WxSessionManager ;
66import me .chanjar .weixin .mp .bean .message .WxMpXmlMessage ;
77import me .chanjar .weixin .mp .bean .message .WxMpXmlOutMessage ;
8+ import org .apache .commons .lang3 .StringUtils ;
89
910import java .util .ArrayList ;
1011import java .util .HashMap ;
@@ -26,6 +27,8 @@ public class WxMpMessageRouterRule {
2627
2728 private String eventKey ;
2829
30+ private String eventKeyRegex ;
31+
2932 private String content ;
3033
3134 private String rContent ;
@@ -74,6 +77,14 @@ public WxMpMessageRouterRule eventKey(String eventKey) {
7477 return this ;
7578 }
7679
80+ /**
81+ * 如果eventKey匹配该正则表达式
82+ */
83+ public WxMpMessageRouterRule eventKeyRegex (String regex ) {
84+ this .eventKeyRegex = regex ;
85+ return this ;
86+ }
87+
7788 /**
7889 * 如果content等于某值
7990 */
@@ -170,17 +181,17 @@ protected boolean test(WxMpXmlMessage wxMessage) {
170181 return
171182 (this .fromUser == null || this .fromUser .equals (wxMessage .getFromUser ()))
172183 &&
173- (this .msgType == null || this .msgType .toLowerCase ().equals ((wxMessage .getMsgType () == null ? null : wxMessage .getMsgType ().toLowerCase ())))
184+ (this .msgType == null || this .msgType .equalsIgnoreCase (wxMessage .getMsgType ()))
185+ &&
186+ (this .event == null || this .event .equalsIgnoreCase (wxMessage .getEvent ()))
174187 &&
175- (this .event == null || this .event . toLowerCase (). equals (( wxMessage .getEvent () == null ? null : wxMessage . getEvent (). toLowerCase () )))
188+ (this .eventKey == null || this .eventKey . equalsIgnoreCase ( wxMessage .getEventKey ( )))
176189 &&
177- (this .eventKey == null || this . eventKey . toLowerCase (). equals (( wxMessage . getEventKey () == null ? null : wxMessage .getEventKey (). toLowerCase ())))
190+ (this .eventKeyRegex == null || Pattern . matches ( this . eventKeyRegex , StringUtils . trimToEmpty ( wxMessage .getEventKey ())))
178191 &&
179- (this .content == null || this .content
180- .equals (wxMessage .getContent () == null ? null : wxMessage .getContent ().trim ()))
192+ (this .content == null || this .content .equals (StringUtils .trimToNull (wxMessage .getContent ())))
181193 &&
182- (this .rContent == null || Pattern
183- .matches (this .rContent , wxMessage .getContent () == null ? "" : wxMessage .getContent ().trim ()))
194+ (this .rContent == null || Pattern .matches (this .rContent , StringUtils .trimToEmpty (wxMessage .getContent ())))
184195 &&
185196 (this .matcher == null || this .matcher .match (wxMessage ))
186197 ;
0 commit comments