Skip to content

HR助手getEmployeeFieldInfo,getAll参数问题,没有此参数,请求报错错误代码:40058, 错误信息:不合法的参数;传递参数不符合系统要求,需要参照具体API接口说明,微信原始报文:{"errcode":40058,"errmsg":"invalid Request Parameter#3925

Open
softboy99 wants to merge 2 commits intobinarywang:developfrom
softboy99:develop

Conversation

@softboy99
Copy link

HR助手getEmployeeFieldInfo,getAll参数问题,没有此参数,请求报错错误代码:40058, 错误信息:不合法的参数;传递参数不符合系统要求,需要参照具体API接口说明,微信原始报文:{"errcode":40058,"errmsg":"invalid Request Parameter

softboy99 and others added 2 commits March 11, 2026 09:34
merge latest from fork source
…参数不符合系统要求,需要参照具体API接口说明,微信原始报文:{"errcode":40058,"errmsg":"invalid Request Parameter
@binarywang
Copy link
Owner

auggie review

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

该 PR 试图修复/调整企业微信「人事助手」接口 getEmployeeFieldInfo 的入参处理方式,通过新增 getAll 参数与请求体字段来控制是否获取全部档案字段,并同步更新接口注释。

Changes:

  • WxCpHrService#getEmployeeFieldInfo 新增 (userid, boolean getAll, fields) 重载方法
  • WxCpHrServiceImpl#getEmployeeFieldInfo 请求体新增写入 get_all,并在 fields 为空时增加参数校验逻辑
  • 更新 WxCpHrService 中对 fields/getAll 的 Javadoc 描述

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java 新增重载实现、请求体写入 get_all、调整 fields 为空时的校验逻辑
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java 新增重载方法签名并更新参数文档

Comment on lines 52 to 54
jsonObject.addProperty("userid", userid);
jsonObject.addProperty("get_all", getAll);
if (fields != null && !fields.isEmpty()) {
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

这里无条件向请求体写入了 get_all 字段(即使为 false 也会发送)。从该接口的既有用法/测试(WxCpHrServiceImplTest#testGetEmployeeFieldInfo 传 fields=null)以及 PR 描述来看,接口并不支持该参数,发送后会触发 40058「invalid Request Parameter」。建议不要在请求体中包含 get_all,需要“获取全部字段”时直接省略 fields 字段即可。

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +58
}else{
if(!getAll)
throw new IllegalArgumentException("fields 不能为空");
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

当前逻辑在 fields 为空且 getAll 为 false 时直接抛出异常,这会改变该方法原有语义:测试用例 WxCpHrServiceImplTest#testGetEmployeeFieldInfo 依赖 fields=null 来获取全部字段。若接口本身支持不传 fields 返回全部字段,应允许 fields 为空并且不抛异常(仅在确实需要限制时才校验)。

Suggested change
}else{
if(!getAll)
throw new IllegalArgumentException("fields 不能为空");

Copilot uses AI. Check for mistakes.
Comment on lines 42 to +44
public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List<String> fields) throws WxErrorException {
return getEmployeeFieldInfo(userid,false,fields);
}
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

这里的格式与本文件其余部分不一致(逗号后缺少空格)。建议按既有风格调整为在逗号后留空格,避免 checkstyle/可读性问题。

Copilot uses AI. Check for mistakes.
Comment on lines +56 to +58
}else{
if(!getAll)
throw new IllegalArgumentException("fields 不能为空");
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

这里的 }else{ / if(!getAll) 缺少空格且 if 未使用花括号,风格与周围代码不一致,也容易被 checkstyle 拦截。建议补齐空格并为条件分支加上 {}

Suggested change
}else{
if(!getAll)
throw new IllegalArgumentException("fields 不能为空");
} else {
if (!getAll) {
throw new IllegalArgumentException("fields 不能为空");
}

Copilot uses AI. Check for mistakes.
Comment on lines 40 to 45
* @param userid 员工userid
* @param fields 指定字段key列表,不填则返回全部字段
* @param fields 指定字段key列表
* @return 员工档案数据响应 wx cp hr employee field data resp
* @throws WxErrorException the wx error exception
*/
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List<String> fields) throws WxErrorException;
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

该接口原注释曾表明 fields 可不填以返回全部字段;并且测试用例也以 fields=null 调用。这里把 fields 描述改成必填会造成文档与实际/既有用法不一致。建议在 Javadoc 中明确 fields 为空时的行为(例如:不填则返回全部字段)。

Copilot uses AI. Check for mistakes.
* @return 员工档案数据响应 wx cp hr employee field data resp
* @throws WxErrorException the wx error exception
*/
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException;
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

在公共 interface 中新增抽象方法会对外部自定义实现(例如业务方 mock / 代理实现 WxCpHrService)造成源/二进制兼容性破坏,需要他们同步实现新方法。若只是为了提供新重载,建议考虑使用 default 方法(Java 8+)在接口内提供默认实现,或通过新增请求对象/在实现类中扩展来避免破坏兼容性。

Suggested change
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException;
default WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll,
List<String> fields) throws WxErrorException {
// 为了保持接口的向后兼容性,默认实现忽略 getAll 参数,仅透传 fields。
// 需要根据 getAll 返回全部字段的实现类可以自行覆盖该方法。
return this.getEmployeeFieldInfo(userid, fields);
}

Copilot uses AI. Check for mistakes.
Comment on lines +48 to 63
* 获取员工档案数据.
* <p>
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/hr/get_staff_info?access_token=ACCESS_TOKEN
* 权限说明:
* 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。
*
* @param userid 员工userid
* @param getAll 是否获取全部字段
* @param fields 指定字段key列表
* @return 员工档案数据响应 wx cp hr employee field data resp
* @throws WxErrorException the wx error exception
*/
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException;

/**
Copy link

Copilot AI Mar 11, 2026

Choose a reason for hiding this comment

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

这里新增的 getAll 参数会让调用方以为该接口支持一个名为 get_all 的请求参数;但当前接口历史行为/注释是通过「不传 fields」来返回全部字段。若微信接口并不存在该参数(会触发 40058),建议不要把它暴露为公共 API,而是保留 fields 为空即取全量的调用方式。

Suggested change
* 获取员工档案数据.
* <p>
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/hr/get_staff_info?access_token=ACCESS_TOKEN
* 权限说明
* 需要配置人事助手的secret调用接口前需给对应成员赋予人事小助手应用的权限
*
* @param userid 员工userid
* @param getAll 是否获取全部字段
* @param fields 指定字段key列表
* @return 员工档案数据响应 wx cp hr employee field data resp
* @throws WxErrorException the wx error exception
*/
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException;
/**

Copilot uses AI. Check for mistakes.
@augmentcode
Copy link

augmentcode bot commented Mar 11, 2026

🤖 Augment PR Summary

Summary: Adds a getAll overload for HR assistant getEmployeeFieldInfo and includes get_all in the request payload.
Why: Aligns the request parameters with the upstream WeCom HR API to avoid 40058 invalid request parameter errors when fetching staff profile info.

🤖 Was this summary useful? React with 👍 or 👎

Copy link

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

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

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

* @return 员工档案数据响应 wx cp hr employee field data resp
* @throws WxErrorException the wx error exception
*/
WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List<String> fields) throws WxErrorException;
Copy link

Choose a reason for hiding this comment

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

Adding a new abstract method to the public WxCpHrService interface is a source/binary breaking change for any external custom implementations. Please double-check this is acceptable for the project’s compatibility guarantees.

Severity: medium

Fix This in Augment

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

jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields));
}else{
if(!getAll)
throw new IllegalArgumentException("fields 不能为空");
Copy link

Choose a reason for hiding this comment

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

With this validation, existing calls like getEmployeeFieldInfo(userid, null) will now throw IllegalArgumentException (and it also breaks WxCpHrServiceImplTest.testGetEmployeeFieldInfo). If the intent is to keep supporting “get all fields” when fields is omitted, this behavioral change likely needs to be revisited.

Severity: medium

Other Locations
  • weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java:43

Fix This in Augment

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

@binarywang
Copy link
Owner

@copilot open a new pull request to apply changes based on the comments in this thread

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.

3 participants