Skip to content

企业微信关于不同功能的 secret 使用问题 #2753

Description

@CraKeyBoy

简要描述

企业微信官方给出了四种 secret 的解释,个人理解这四种 secret 分别是不同的权限的代表,但是目前提供的 wx-java-cp-spring-boot-starter 只能设置一种 secret,这块是不是需要创建多个 WxCpService 来处理不同的数据才好?

官方文档地址

请提供所需功能对应的微信官方文档地址以便进行确认。
secret
secret是企业应用里面用于保障数据安全的“钥匙”,每一个应用都有一个独立的访问密钥,为了保证数据的安全,secret务必不能泄漏。
目前secret有:

自建应用secret。在管理后台->“应用与小程序”->“应用”->“自建”,点进某个应用,即可看到。
基础应用secret。某些基础应用(如“审批”“打卡”应用),支持通过API进行操作。在管理后台->“应用与小程序”->“应用->”“基础”,点进某个应用,点开“API”小按钮,即可看到。
image
通讯录管理secret。在“管理工具”-“通讯录同步”里面查看(需开启“API接口同步”);
外部联系人管理secret。在“客户联系”栏,点开“API”小按钮,即可看到。
image

https://developer.work.weixin.qq.com/document/path/90665

Activity

  1. changed the title [-]企业关于不同功能的 secret 使用问题[/-] [+]企业微信关于不同功能的 secret 使用问题[/+] on Jul 22, 2022
  2. ycfeng commented on Jul 28, 2022

    @ycfeng

    我这边的做法是:不用自带的starter,而是自己写一个WxCpConfiguration类,提供一个静态方法获取WxCpService,为了避免频繁创建WxCpService造成不必要的资源消耗,可以实现一个简单的ObjectPool用来缓存已经创建过的WxCpService对象,这样就可以实现在一个项目中使用多种类型的企业微信secret

    @Configuration
    public class WxCpConfiguration {
    
        private static RedissonClient redissonClient;
    
        private static final ConcurrentHashMap<String, WxCpService> wxCpServicePool = new ConcurrentHashMap<>();
    
        @Autowired
        public WxCpConfiguration(RedissonClient redissonClient) {
            WxCpConfiguration.redissonClient = redissonClient;
        }
    
        public static WxCpService getWxCpService(String corpid, String secret) {
            return getWxCpService(corpid, secret, null);
        }
    
        public static WxCpService getWxCpService(String corpid, String secret, Integer agentId) {
            String key = corpid + secret;
            WxCpService wxCpService = wxCpServicePool.get(key);
            if (wxCpService == null) {
                wxCpService = new WxCpServiceImpl();
                WxCpRedissonConfigImpl config = new WxCpRedissonConfigImpl(redissonClient, RedisConstants.GLOBAL_KEY_PREFIX + "wxWork:");
                config.setCorpId(corpid);
                config.setCorpSecret(secret);
                config.setAgentId(agentId);
                wxCpService.setWxCpConfigStorage(config);
                wxCpServicePool.put(key, wxCpService);
            }
            return wxCpService;
        }
    
    }
  3. CraKeyBoy commented on Jul 28, 2022

    @CraKeyBoy
    Author

    @yiyingcanfeng 目前也是通过创建多个 wxCpService 实现,非常感谢

  4. su6 commented on Mar 3, 2023

    @su6
    getWxCpService

    getWxCpService 这个方法每次怎么用啊

  5. foreveryang321 commented on Oct 17, 2023

    @foreveryang321

    可以参考该实现:#3149

  6. su6 commented on Oct 17, 2023

    @su6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions