Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CP_如何动态支持多个企业号 #2594

Closed
tang226 opened this issue Apr 18, 2022 · 7 comments
Closed

CP_如何动态支持多个企业号 #2594

tang226 opened this issue Apr 18, 2022 · 7 comments
Labels

Comments

@tang226
Copy link

tang226 commented Apr 18, 2022

简要描述

CP_如何支持多个企业号wiki中CP的基本配置信息(secret,token,aesKey)都是配置在配置文件中的,然后启动服务的时候直接生成了多个WxCpService然后存储在map中

@PostConstruct
    public void initServices() {
        cpServices = this.properties.getAppConfigs().stream().map(a -> {
            val configStorage = new WxCpDefaultConfigImpl();
            configStorage.setCorpId(this.properties.getCorpId());
            configStorage.setAgentId(a.getAgentId());
            configStorage.setCorpSecret(a.getSecret());
            configStorage.setToken(a.getToken());
            configStorage.setAesKey(a.getAesKey());
            val service = new WxCpServiceImpl();
            service.setWxCpConfigStorage(configStorage);
            routers.put(a.getAgentId(), this.newRouter(service));
            return service;
        }).collect(Collectors.toMap(service -> service.getWxCpConfigStorage().getAgentId(), a -> a));
    }

问题

我的服务中有很多个CP的配置信息(100个)并且都存在数据库中,我感觉在项目启动的时候生成100个WxCpService非常不妥,并且这个配置信息还会动态递增(每接入一个CP用户,我就要在数据库中新增一条配置信息),请问有较好的方式解决这个问题吗。

就比如说我需要调用某个CP用户的接口,就根据数据库里面的配置信息为它生成一个WxCpService,主要的步骤就是每次都需要调用setWxCpConfigStorage把数据库存储的配置注入进去,但是setWxCpConfigStorage方法中有一个initHttp(),频繁的调用initHttp()会有性能影响吗

@didi12121
Copy link

didi12121 commented Apr 18, 2022

我是写了一个根据租户id来生成不同的cpServices 的组件然后注入到spring
image
然后每次需要cpServices 的时候都通过这个方法拿到对应的cpServices

@tang226
Copy link
Author

tang226 commented Apr 19, 2022

这样感觉可以;
请问每次去获取会很耗时吗

@didi12121
Copy link

目前看来不会

@stale
Copy link

stale bot commented Jun 18, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jun 18, 2022
@izerui
Copy link

izerui commented Jun 23, 2022

已经实现: #2694

@stale stale bot removed the stale label Jun 23, 2022
@nadirvishun
Copy link

可以参考本项目中微信公众号的解决方式,用threadlocal来解决,demo,唯一麻烦点的是本身企业微信就是多个应用的,但如果再加上不同的企业的话话,相当于agentId + corpId才能确定唯一的应用。

@stale
Copy link

stale bot commented Aug 31, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 31, 2022
@stale stale bot closed this as completed Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants