Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public interface WxCpHrService {
* 权限说明:
* 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。
*
* @param userids 员工userid列表,不超过20个
* @param fields 指定字段key列表,不填则返回全部字段
* @param userid 员工userid
* @param fields 指定字段key列表,不填则返回全部字段
* @return 员工档案数据响应 wx cp hr employee field data resp
* @throws WxErrorException the wx error exception
*/
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(List<String> userids, List<String> fields) throws WxErrorException;
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List<String> fields) throws WxErrorException;

/**
* 更新员工档案数据.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,12 @@ public WxCpHrEmployeeFieldInfoResp getFieldInfo(List<String> fields) throws WxEr
}

@Override
public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(List<String> userids, List<String> fields) throws WxErrorException {
if (userids == null || userids.isEmpty()) {
public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List<String> fields) throws WxErrorException {
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);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

前面用 userid.trim().isEmpty() 做了校验,但这里仍把原始 userid(可能带前后空格)写入请求体,可能出现“校验通过但微信侧仍判不合法”的情况;建议统一使用校验后的值或显式拒绝带空白的 userid

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Comment on lines +43 to +47
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这次 bug 的根因是请求体序列化(userid 被序列化成数组)。目前测试仅调用真实接口(依赖 test-config.xml),无法在单元层面断言请求 JSON 是否为 string。建议补充一个不依赖外网的单测:通过 Mockito mock WxCpService.post,捕获 body 并断言包含 "userid":"..."(而不是数组),从而防止回归。

Copilot uses AI. Check for mistakes.
if (fields != null && !fields.isEmpty()) {
jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testGetFieldInfoWithFilter() throws WxErrorException {
public void testGetEmployeeFieldInfo() throws WxErrorException {
WxCpHrService hrService = this.wxCpService.getHrService();
WxCpHrEmployeeFieldDataResp resp = hrService.getEmployeeFieldInfo(
Collections.singletonList(this.configStorage.getUserId()), null);
this.configStorage.getUserId(), null);
assertThat(resp).isNotNull();
assertThat(resp.getEmployeeFieldList()).isNotNull();
log.info("获取员工档案数据: {}", resp);
Expand Down