Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -135,8 +137,9 @@ public WxCpMessageRouterRule rule() {
* 处理微信消息
*
* @param wxMessage
* @param context
*/
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage, final Map<String, Object> context) {
if (isDuplicateMessage(wxMessage)) {
// 如果是重复消息,那么就不做处理
return null;
Expand Down Expand Up @@ -166,12 +169,12 @@ public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
this.executorService.submit(new Runnable() {
@Override
public void run() {
rule.service(wxMessage, WxCpMessageRouter.this.wxCpService, WxCpMessageRouter.this.sessionManager, WxCpMessageRouter.this.exceptionHandler);
rule.service(wxMessage, context, WxCpMessageRouter.this.wxCpService, WxCpMessageRouter.this.sessionManager, WxCpMessageRouter.this.exceptionHandler);
}
})
);
} else {
res = rule.service(wxMessage, this.wxCpService, this.sessionManager, this.exceptionHandler);
res = rule.service(wxMessage, context, this.wxCpService, this.sessionManager, this.exceptionHandler);
// 在同步操作结束,session访问结束
this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUserName());
sessionEndAccess(wxMessage);
Expand Down Expand Up @@ -200,6 +203,16 @@ public void run() {
return res;
}


/**
* 处理微信消息
*
* @param wxMessage
*/
public WxCpXmlOutMessage route(final WxCpXmlMessage wxMessage) {
return this.route(wxMessage, new HashMap<String, Object>());
}

protected boolean isDuplicateMessage(WxCpXmlMessage wxMessage) {

String messageId = "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,16 @@ protected boolean test(WxCpXmlMessage wxMessage) {
* @return true 代表继续执行别的router,false 代表停止执行别的router
*/
protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
Map<String, Object> context,
WxCpService wxCpService,
WxSessionManager sessionManager,
WxErrorExceptionHandler exceptionHandler) {

try {
if (context == null) {
context = new HashMap<>();
}

Map<String, Object> context = new HashMap<>();
try {
// 如果拦截器不通过
for (WxCpMessageInterceptor interceptor : this.interceptors) {
if (!interceptor.intercept(wxMessage, context, wxCpService, sessionManager)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -126,7 +128,7 @@ public WxMpMessageRouterRule rule() {
/**
* 处理微信消息
*/
public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage, final Map<String, Object> context) {
if (isMsgDuplicated(wxMessage)) {
// 如果是重复消息,那么就不做处理
return null;
Expand Down Expand Up @@ -156,12 +158,12 @@ public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
this.executorService.submit(new Runnable() {
@Override
public void run() {
rule.service(wxMessage, WxMpMessageRouter.this.wxMpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
rule.service(wxMessage, context, WxMpMessageRouter.this.wxMpService, WxMpMessageRouter.this.sessionManager, WxMpMessageRouter.this.exceptionHandler);
}
})
);
} else {
res = rule.service(wxMessage, this.wxMpService, this.sessionManager, this.exceptionHandler);
res = rule.service(wxMessage, context, this.wxMpService, this.sessionManager, this.exceptionHandler);
// 在同步操作结束,session访问结束
this.log.debug("End session access: async=false, sessionId={}", wxMessage.getFromUser());
sessionEndAccess(wxMessage);
Expand All @@ -188,6 +190,10 @@ public void run() {
return res;
}

public WxMpXmlOutMessage route(final WxMpXmlMessage wxMessage) {
return this.route(wxMessage, new HashMap<String, Object>());
}

protected boolean isMsgDuplicated(WxMpXmlMessage wxMessage) {

StringBuilder messageId = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,16 @@ protected boolean test(WxMpXmlMessage wxMessage) {
* @return true 代表继续执行别的router,false 代表停止执行别的router
*/
protected WxMpXmlOutMessage service(WxMpXmlMessage wxMessage,
Map<String, Object> context,
WxMpService wxMpService,
WxSessionManager sessionManager,
WxErrorExceptionHandler exceptionHandler) {

try {
if (context == null) {
context = new HashMap<>();
}

Map<String, Object> context = new HashMap<>();
try {
// 如果拦截器不通过
for (WxMpMessageInterceptor interceptor : this.interceptors) {
if (!interceptor.intercept(wxMessage, context, wxMpService, sessionManager)) {
Expand Down