Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 26, 2026

问题

会话存档相关API(getPermitUserListgetGroupChatcheckSingleAgree)使用应用secret获取的access token,而企业微信要求这些API必须使用会话存档专用secret获取独立的access token,导致返回权限错误。

变更

配置层

  • WxCpConfigStorage: 新增会话存档access token管理方法(获取、更新、过期检查、锁)
  • WxCpDefaultConfigImpl: 实现会话存档access token存储和生命周期管理
  • WxCpRedisConfigImpl: 添加存根实现

服务层

  • WxCpService: 新增 getMsgAuditAccessToken(boolean forceRefresh) 方法
  • 所有实现类(WxCpServiceImplWxCpServiceApacheHttpClientImplWxCpServiceHttpComponentsImplWxCpServiceOkHttpImplWxCpServiceJoddHttpImpl):实现使用会话存档secret获取专用access token,采用双重检查锁定避免并发重复刷新

业务层

  • WxCpMsgAuditServiceImpl: 修改 getPermitUserListgetGroupChatcheckSingleAgree 方法,使用会话存档专用access token

使用示例

WxCpDefaultConfigImpl config = new WxCpDefaultConfigImpl();
config.setCorpId("your-corp-id");
config.setCorpSecret("your-app-secret");
config.setMsgAuditSecret("your-msgaudit-secret");  // 配置会话存档secret

// 会话存档API将自动使用专用access token
List<String> userIds = msgAuditService.getPermitUserList(null);

技术细节

各HTTP客户端实现采用相应的线程安全机制:

  • Apache HttpClient: 使用 HttpGet + ApacheBasicResponseHandler
  • OkHttp: 使用 try-with-resources 确保 Response 正确关闭
  • Jodd Http: 使用 HttpRequest + open().bodyText()

所有实现均在secret未配置时抛出明确的 WxErrorException("会话存档secret未配置")

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • developer.work.weixin.qq.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>weixin-java-cp 4.8.0版本中会话存档开发的bug</issue_title>
<issue_description>模块weixin-java-cp
版本4.8.0
虽然WxCpConfigStorage类中区分了应用secret和会话secret,但是获取开启会话存档的员工集时并没有使用会话secret,还是使用了应用secret,导致请求返回没有权限的问题
方法如图:

Image 配置如图: Image debug位置如图

Image</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 26, 2026 14:53
- 在WxCpServiceApacheHttpClientImpl中实现getMsgAuditAccessToken方法
- 在WxCpServiceHttpComponentsImpl中实现getMsgAuditAccessToken方法
- 在WxCpServiceOkHttpImpl中实现getMsgAuditAccessToken方法,使用try-with-resources正确关闭Response
- 在WxCpServiceJoddHttpImpl中实现getMsgAuditAccessToken方法

所有实现遵循以下设计:
- 使用Lock机制和双重检查确保线程安全
- 使用会话存档secret(msgAuditSecret)获取access token
- 将token存储到updateMsgAuditAccessToken()
- 当msgAuditSecret未配置时抛出WxErrorException
- 保持各实现类原有的HTTP客户端使用风格和代理支持

新增单元测试WxCpServiceGetMsgAuditAccessTokenTest验证实现正确性,
包括正常场景和异常场景(secret未配置或为空)的测试。
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix session archive bug in weixin-java-cp 4.8.0 修复会话存档API使用错误secret导致权限异常的问题 Jan 26, 2026
Copilot AI requested a review from binarywang January 26, 2026 15:01
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 this pull request may close these issues.

weixin-java-cp 4.8.0版本中会话存档开发的bug

2 participants