me.chanjar.weixin.cp.api.WxCpService Java Examples

The following examples show how to use me.chanjar.weixin.cp.api.WxCpService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WxCpMsgSender.java    From WePush with MIT License 6 votes vote down vote up
/**
 * 获取微信企业号工具服务
 *
 * @return WxCpService
 */
public static WxCpService getWxCpService() {
    if (wxCpConfigStorage == null) {
        synchronized (WxCpMsgSender.class) {
            if (wxCpConfigStorage == null) {
                wxCpConfigStorage = wxCpConfigStorage();
            }
        }
    }
    if (wxCpService == null && wxCpConfigStorage != null) {
        synchronized (PushControl.class) {
            if (wxCpService == null && wxCpConfigStorage != null) {
                wxCpService = new WxCpServiceApacheHttpClientImpl();
                wxCpService.setWxCpConfigStorage(wxCpConfigStorage);
            }
        }
    }
    return wxCpService;
}
 
Example #2
Source File: WxCpMessageRouter.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
public WxCpMessageRouter(WxCpService wxCpService) {
  this.wxCpService = wxCpService;
  this.executorService = Executors.newFixedThreadPool(DEFAULT_THREAD_POOL_SIZE);
  this.messageDuplicateChecker = new WxMessageInMemoryDuplicateChecker();
  this.sessionManager = new StandardSessionManager();
  this.exceptionHandler = new LogExceptionHandler();
}
 
Example #3
Source File: WxCpMessageRouterRule.java    From weixin-java-tools with Apache License 2.0 5 votes vote down vote up
/**
 * 处理微信推送过来的消息
 *
 * @param wxMessage
 * @return true 代表继续执行别的router,false 代表停止执行别的router
 */
protected WxCpXmlOutMessage service(WxCpXmlMessage wxMessage,
                                    Map<String, Object> context,
                                    WxCpService wxCpService,
                                    WxSessionManager sessionManager,
                                    WxErrorExceptionHandler exceptionHandler) {

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

  try {
    // 如果拦截器不通过
    for (WxCpMessageInterceptor interceptor : this.interceptors) {
      if (!interceptor.intercept(wxMessage, context, wxCpService, sessionManager)) {
        return null;
      }
    }

    // 交给handler处理
    WxCpXmlOutMessage res = null;
    for (WxCpMessageHandler handler : this.handlers) {
      // 返回最后handler的结果
      res = handler.handle(wxMessage, context, wxCpService, sessionManager);
    }
    return res;

  } catch (WxErrorException e) {
    exceptionHandler.handle(e);
  }

  return null;

}
 
Example #4
Source File: WxCpOAuth2ServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpOAuth2ServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #5
Source File: WxCpOAuth2Servlet.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpOAuth2Servlet(WxCpService wxCpService) {
  this.wxCpService = wxCpService;
}
 
Example #6
Source File: WxCpEndpointServlet.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpEndpointServlet(WxCpConfigStorage wxCpConfigStorage, WxCpService wxCpService,
    WxCpMessageRouter wxCpMessageRouter) {
  this.wxCpConfigStorage = wxCpConfigStorage;
  this.wxCpService = wxCpService;
  this.wxCpMessageRouter = wxCpMessageRouter;
}
 
Example #7
Source File: WxCpTagServiceImplTest.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
@Test
public void testGet() throws WxErrorException {
  String apiResultJson = "{\"errcode\": 0,\"errmsg\": \"ok\",\"userlist\": [{\"userid\": \"0124035\",\"name\": \"王五\"},{\"userid\": \"0114035\",\"name\": \"梦雪\"}],\"partylist\": [9576,9567,9566],\"tagname\": \"测试标签-001\"}";
  WxCpService wxService = mock(WxCpService.class);
  when(wxService.get("https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagId=150", null)).thenReturn(apiResultJson);
  when(wxService.getTagService()).thenReturn(new WxCpTagServiceImpl(wxService));

  WxCpTagService wxCpTagService = wxService.getTagService();

  WxCpTagGetResult wxCpTagGetResult = wxCpTagService.get(String.valueOf(150));

  assertEquals(0, wxCpTagGetResult.getErrcode().intValue());

  assertEquals(2, wxCpTagGetResult.getUserlist().size());
  assertEquals(3, wxCpTagGetResult.getPartylist().size());
  assertEquals("测试标签-001", wxCpTagGetResult.getTagname());


}
 
Example #8
Source File: WxCpOAuth2Servlet.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpOAuth2Servlet(WxCpService wxCpService) {
  this.wxCpService = wxCpService;
}
 
Example #9
Source File: WxCpEndpointServlet.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpEndpointServlet(WxCpConfigStorage wxCpConfigStorage, WxCpService wxCpService,
                           WxCpMessageRouter wxCpMessageRouter) {
  this.wxCpConfigStorage = wxCpConfigStorage;
  this.wxCpService = wxCpService;
  this.wxCpMessageRouter = wxCpMessageRouter;
}
 
Example #10
Source File: WxCpDepartmentServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpDepartmentServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #11
Source File: WxCpMediaServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpMediaServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #12
Source File: WxCpMenuServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpMenuServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #13
Source File: WxCpTagServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpTagServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #14
Source File: WxCpUserServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpUserServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #15
Source File: WxCpAgentServiceImpl.java    From weixin-java-tools with Apache License 2.0 4 votes vote down vote up
public WxCpAgentServiceImpl(WxCpService mainService) {
  this.mainService = mainService;
}
 
Example #16
Source File: WxCpMessageInterceptor.java    From weixin-java-tools with Apache License 2.0 2 votes vote down vote up
/**
 * 拦截微信消息
 *
 * @param wxMessage
 * @param context        上下文,如果handler或interceptor之间有信息要传递,可以用这个
 * @param wxCpService
 * @param sessionManager
 * @return true代表OK,false代表不OK
 */
boolean intercept(WxCpXmlMessage wxMessage,
                  Map<String, Object> context,
                  WxCpService wxCpService,
                  WxSessionManager sessionManager) throws WxErrorException;
 
Example #17
Source File: WxCpMessageHandler.java    From weixin-java-tools with Apache License 2.0 2 votes vote down vote up
/**
 * @param wxMessage
 * @param context        上下文,如果handler或interceptor之间有信息要传递,可以用这个
 * @param wxCpService
 * @param sessionManager
 * @return xml格式的消息,如果在异步规则里处理的话,可以返回null
 */
WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
                         Map<String, Object> context,
                         WxCpService wxCpService,
                         WxSessionManager sessionManager) throws WxErrorException;