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

多个企业微信号,获取存档消息解密失败 #2768

Closed
lifuz opened this issue Aug 9, 2022 · 8 comments · Fixed by #2773
Closed

多个企业微信号,获取存档消息解密失败 #2768

lifuz opened this issue Aug 9, 2022 · 8 comments · Fixed by #2773

Comments

@lifuz
Copy link

lifuz commented Aug 9, 2022

简要描述

请简单概括描述下你所遇到的问题。
多个企业微信,获取会话存档消息,解密报错

模块版本情况

  • WxJava 模块名: weixin-java-cp
  • WxJava 版本号: 4.3.9.B

详细描述

尽量详细描述。请不要使用截图,尽量使用文字描述,代码直接贴上来,日志则请附在后面所示区域。
多个企业微信,获取会话存档消息,第一个企业微信可以顺利解密数据,第二个及之后的主体解密报错,解密不了数据

日志

如果日志不多,直接使用md代码引用格式贴在此处,否则如果太长,请将日志放在 pastebin 或者其他地方,然后将其url地址贴在这里

日志请写于此处
javax.crypto.BadPaddingException: Decryption error
	at sun.security.rsa.RSAPadding.unpadV15(RSAPadding.java:370)
	at sun.security.rsa.RSAPadding.unpad(RSAPadding.java:282)
	at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:370)
	at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:404)
	at javax.crypto.Cipher.doFinal(Cipher.java:2168)
	at me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil.decryptPriKeyByPKCS1(WxCpCryptUtil.java:105)
	at me.chanjar.weixin.cp.util.crypto.WxCpCryptUtil.decryptPriKey(WxCpCryptUtil.java:49)
	at me.chanjar.weixin.cp.api.impl.WxCpMsgAuditServiceImpl.decryptChatData(WxCpMsgAuditServiceImpl.java:123)
	at me.chanjar.weixin.cp.api.impl.WxCpMsgAuditServiceImpl.getDecryptData(WxCpMsgAuditServiceImpl.java:109)
	at com.yngw518.weikong.runable.PullRunnable.run(PullRunnable.java:73)
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

@0katekate0
Copy link

是指多个cp分布式部署的,还是指多个企业corpid出现的问题?

@lifuz
Copy link
Author

lifuz commented Aug 10, 2022

同一个应用,多个企业corpid,单机的

@0katekate0
Copy link

0katekate0 commented Aug 10, 2022

多个企业corpid?WxCpConfiguration你是怎样配置的?我看下怎么根据corpId去调整获取会话存档

@lifuz
Copy link
Author

lifuz commented Aug 10, 2022

根据demo做的,这里的agentid是自己定义的
` public static WxCpService getCpService(Integer agentId) {
return cpServices.get(agentId);
}

@PostConstruct
public void initServices() {
    cpServices = this.properties.getAppConfigs().stream().map(a -> {
        val configStorage = new WxCpDefaultConfigImpl();
        configStorage.setCorpId(a.getCorpId());
        configStorage.setAgentId(a.getAgentId());
        configStorage.setCorpSecret(a.getSecret());
        configStorage.setToken(a.getToken());
        configStorage.setAesKey(a.getAesKey());
        String path = properties.getMsgAuditPriKeyPath() + "/" + a.getCorpId() + ".pem";
        String priKey = FileUtil.readString(path, CharsetUtil.defaultCharset());
        configStorage.setMsgAuditPriKey(priKey);
        configStorage.setMsgAuditLibPath(this.properties.getMsgAuditLibPath());
        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));
}`

@0katekate0
Copy link

0katekate0 commented Aug 10, 2022

根据demo做的,这里的agentid是自己定义的 ` public static WxCpService getCpService(Integer agentId) { return cpServices.get(agentId); }

@PostConstruct
public void initServices() {
    cpServices = this.properties.getAppConfigs().stream().map(a -> {
        val configStorage = new WxCpDefaultConfigImpl();
        configStorage.setCorpId(a.getCorpId());
        configStorage.setAgentId(a.getAgentId());
        configStorage.setCorpSecret(a.getSecret());
        configStorage.setToken(a.getToken());
        configStorage.setAesKey(a.getAesKey());
        String path = properties.getMsgAuditPriKeyPath() + "/" + a.getCorpId() + ".pem";
        String priKey = FileUtil.readString(path, CharsetUtil.defaultCharset());
        configStorage.setMsgAuditPriKey(priKey);
        configStorage.setMsgAuditLibPath(this.properties.getMsgAuditLibPath());
        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));
}`

了解,我这边没有多个企业corpid,进一下钉钉交流2群:32206329,晚点调试下,晚点回复一下

@lifuz
Copy link
Author

lifuz commented Aug 10, 2022

好的,感谢大佬

@0katekate0
Copy link

好的,感谢大佬

等待回复

@0katekate0
Copy link

好的,感谢大佬

等待下个版本发布即可

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants