修复企业微信人事助手 getEmployeeFieldInfo 接口 userid 参数类型错误#3912
Conversation
Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
🤖 Augment PR Summary总结: 修复企业微信人事助手 🤖 Was this summary useful? React with 👍 or 👎 |
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java
Show resolved
Hide resolved
| } | ||
| JsonObject jsonObject = new JsonObject(); | ||
| jsonObject.add("userid", WxCpGsonBuilder.create().toJsonTree(userids)); | ||
| jsonObject.addProperty("userid", userid); |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 647109cc1e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
该 PR 修复企业微信人事助手 hr/get_staff_info 接口请求体中 userid 参数被错误序列化为数组的问题,从而解决微信返回 40058(期望 string)的错误,属于企业微信(weixin-java-cp)模块的 API 调用修复。
Changes:
- 将
WxCpHrService#getEmployeeFieldInfo入参从List<String> userids调整为String userid - 在
WxCpHrServiceImpl中改用JsonObject#addProperty,确保userid按字符串序列化,并移除原有的“最多 20 个”校验 - 更新对应测试用例以适配新方法签名
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java | 调整人事助手接口方法签名与注释,匹配微信 API 对 userid 的类型要求 |
| weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java | 修复请求体构造逻辑,保证 userid 以字符串写入 JSON |
| weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImplTest.java | 更新调用方式以匹配新签名 |
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java
Show resolved
Hide resolved
| if (userid == null || userid.trim().isEmpty()) { | ||
| throw new IllegalArgumentException("userid 不能为空"); | ||
| } | ||
| if (userids.size() > 20) { | ||
| throw new IllegalArgumentException("userid 每次最多传入20个"); | ||
| } | ||
| JsonObject jsonObject = new JsonObject(); | ||
| jsonObject.add("userid", WxCpGsonBuilder.create().toJsonTree(userids)); | ||
| jsonObject.addProperty("userid", userid); |
There was a problem hiding this comment.
这次 bug 的根因是请求体序列化(userid 被序列化成数组)。目前测试仅调用真实接口(依赖 test-config.xml),无法在单元层面断言请求 JSON 是否为 string。建议补充一个不依赖外网的单测:通过 Mockito mock WxCpService.post,捕获 body 并断言包含 "userid":"..."(而不是数组),从而防止回归。
根据官方文档(路径 99132)以及 Issue #3891 中微信 API 返回的错误信息,
当前修复(commit 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:
If you need me to access, download, or install something from one of these locations, you can either:
|
get_staff_infoAPI 要求userid为字符串类型,但代码错误地将其序列化为数组,导致微信返回错误码 40058。变更
WxCpHrService:getEmployeeFieldInfo方法签名由List<String> userids改为String useridWxCpHrServiceImpl:使用addProperty替换add,确保userid作为字符串序列化;移除错误的多值大小校验(size() > 20)WxCpHrServiceImplTest:更新测试适配新签名示例
修复前(请求体错误):
{"userid": ["ZhouYiJing"]}修复后(符合 API 规范):
{"userid": "ZhouYiJing"}Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.