Browse Source

#947 修复WxCpMessageRouter同时存在两个StandardSessionManager的问题

shilianwang 6 years ago
parent
commit
28affd2d11

+ 7 - 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java

@@ -166,6 +166,13 @@ public interface WxCpService {
   WxSession getSession(String id, boolean create);
 
   /**
+   * 获取WxSessionManager 对象
+   *
+   * @return WxSessionManager
+   */
+  WxSessionManager getSessionManager();
+  
+  /**
    * <pre>
    * 设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
    * WxCpService默认使用的是{@link me.chanjar.weixin.common.session.StandardSessionManager}

+ 5 - 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java

@@ -286,6 +286,11 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
   }
 
   @Override
+  public WxSessionManager getSessionManager() {
+    return this.sessionManager;
+  }
+
+  @Override
   public String replaceParty(String mediaId) throws WxErrorException {
     String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
     JsonObject jsonObject = new JsonObject();

+ 1 - 1
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/message/WxCpMessageRouter.java

@@ -73,7 +73,7 @@ public class WxCpMessageRouter {
     this.wxCpService = wxCpService;
     this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
     this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
-    this.sessionManager = new StandardSessionManager();
+    this.sessionManager = wxCpService.getSessionManager();
     this.exceptionHandler = new LogExceptionHandler();
   }