binarywang / weixin-java-cp-demo

基于Spring Boot 和 WxJava 实现的微信企业号/企业微信 后端Demo
366 stars 245 forks source link

企业微信第三方应用如何初始化 #13

Closed kkkangke closed 3 years ago

kkkangke commented 3 years ago

企业微信第三方应用如何初始化,后面想使用授权的企业微信号接口该如何调用

binarywang commented 3 years ago

仿照本demo,构建WxCpTpService实例对象

kkkangke commented 3 years ago

仿照本demo,内置WxCpTpService实例对象

image

需要将 val service = new WxCpServiceImpl();改为val service = new WxCpServiceOnTpImpl(new WxCpTpServiceImpl());吗?

menglikaibin commented 3 years ago
public static WxCpTpService getCpTpService(String suiteId) {
    return cpTpServices.get(suiteId);
}

@PostConstruct
public void initServices() {
    cpTpServices = this.properties.getAppConfigs().stream().map(appConfig -> {
        val configStorage = new WxCpTpDefaultConfigImpl();
        configStorage.setCorpId(this.properties.getCorpId());
        configStorage.setSuiteId(appConfig.getSuiteId());
        configStorage.setSuiteSecret(appConfig.getSuiteSecret());
        configStorage.setToken(appConfig.getToken());
        configStorage.setAesKey(appConfig.getAesKey());

        val service = new WxCpTpServiceImpl();
        service.setWxCpTpConfigStorage(configStorage);
        routers.put(appConfig.getSuiteId(), this.newRouter(service));
        return service;
    }).collect(Collectors.toMap(service -> service.getWxCpTpConfigStorage().getSuiteId(), appConfig -> appConfig));
}

使用企业微信的第三方应用的参数就可以,类都换成第三方应用的类