From 4ddad91b41a92856b3c70cce9db5cec350bd90e1 Mon Sep 17 00:00:00 2001 From: WangJiuJun Date: Wed, 11 Mar 2026 09:49:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20getEmployeeFieldInfo?= =?UTF-8?q?=20getAll=E5=8F=82=E6=95=B0=E9=97=AE=E9=A2=98=EF=BC=8C=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=AD=A4=E5=8F=82=E6=95=B0=E6=97=B6=EF=BC=8C=E6=8A=A5?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E4=BB=A3=E7=A0=81=EF=BC=9A40058,=20=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E4=BF=A1=E6=81=AF=EF=BC=9A=E4=B8=8D=E5=90=88=E6=B3=95?= =?UTF-8?q?=E7=9A=84=E5=8F=82=E6=95=B0=EF=BC=9B=E4=BC=A0=E9=80=92=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E4=B8=8D=E7=AC=A6=E5=90=88=E7=B3=BB=E7=BB=9F=E8=A6=81?= =?UTF-8?q?=E6=B1=82=EF=BC=8C=E9=9C=80=E8=A6=81=E5=8F=82=E7=85=A7=E5=85=B7?= =?UTF-8?q?=E4=BD=93API=E6=8E=A5=E5=8F=A3=E8=AF=B4=E6=98=8E=EF=BC=8C?= =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E5=8E=9F=E5=A7=8B=E6=8A=A5=E6=96=87=EF=BC=9A?= =?UTF-8?q?{"errcode":40058,"errmsg":"invalid=20Request=20Parameter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chanjar/weixin/cp/api/WxCpHrService.java | 18 +++++++++++++++++- .../weixin/cp/api/impl/WxCpHrServiceImpl.java | 9 +++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java index cdf39871a..aa2540f9d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java @@ -38,12 +38,28 @@ public interface WxCpHrService { * 需要配置人事助手的secret,调用接口前需给对应成员赋予人事小助手应用的权限。 * * @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 fields) throws WxErrorException; + /** + * 获取员工档案数据. + *

+ * 请求方式: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 fields) throws WxErrorException; + /** * 更新员工档案数据. *

diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java index 9daf20d86..ba016f1aa 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java @@ -40,13 +40,22 @@ public WxCpHrEmployeeFieldInfoResp getFieldInfo(List fields) throws WxEr @Override public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, List fields) throws WxErrorException { + return getEmployeeFieldInfo(userid,false,fields); + } + + @Override + public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List fields) throws WxErrorException { if (userid == null || userid.trim().isEmpty()) { throw new IllegalArgumentException("userid 不能为空"); } JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("userid", userid); + jsonObject.addProperty("get_all", getAll); if (fields != null && !fields.isEmpty()) { jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields)); + }else{ + if(!getAll) + throw new IllegalArgumentException("fields 不能为空"); } String response = this.cpService.post( this.cpService.getWxCpConfigStorage().getApiUrl(GET_EMPLOYEE_FIELD_INFO), From 5313f17fe0a5d19d0881ebd6ac903bfad6648dc7 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Mar 2026 20:28:26 +0800 Subject: [PATCH 2/5] Update weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../main/java/me/chanjar/weixin/cp/api/WxCpHrService.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java index aa2540f9d..4e4cbb9ef 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java @@ -58,7 +58,12 @@ public interface WxCpHrService { * @return 员工档案数据响应 wx cp hr employee field data resp * @throws WxErrorException the wx error exception */ - WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, List fields) throws WxErrorException; + default WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, + List fields) throws WxErrorException { + // 为了保持接口的向后兼容性,默认实现忽略 getAll 参数,仅透传 fields。 + // 需要根据 getAll 返回全部字段的实现类可以自行覆盖该方法。 + return this.getEmployeeFieldInfo(userid, fields); + } /** * 更新员工档案数据. From 3da4e37ca4b70b2ab8a27ee96312d8cb3d628287 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Mar 2026 20:28:39 +0800 Subject: [PATCH 3/5] Update weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java index ba016f1aa..21e8993d8 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpHrServiceImpl.java @@ -53,9 +53,6 @@ public WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean g jsonObject.addProperty("get_all", getAll); if (fields != null && !fields.isEmpty()) { jsonObject.add("fields", WxCpGsonBuilder.create().toJsonTree(fields)); - }else{ - if(!getAll) - throw new IllegalArgumentException("fields 不能为空"); } String response = this.cpService.post( this.cpService.getWxCpConfigStorage().getApiUrl(GET_EMPLOYEE_FIELD_INFO), From a553c9b815a259255e97d8c3b7ffaa8c079afd43 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 12 Mar 2026 20:29:01 +0800 Subject: [PATCH 4/5] Update weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .../me/chanjar/weixin/cp/api/WxCpHrService.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java index 4e4cbb9ef..ae3e47ebc 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpHrService.java @@ -50,22 +50,6 @@ public interface WxCpHrService { * 请求方式: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 - */ - default WxCpHrEmployeeFieldDataResp getEmployeeFieldInfo(String userid, boolean getAll, - List fields) throws WxErrorException { - // 为了保持接口的向后兼容性,默认实现忽略 getAll 参数,仅透传 fields。 - // 需要根据 getAll 返回全部字段的实现类可以自行覆盖该方法。 - return this.getEmployeeFieldInfo(userid, fields); - } - - /** * 更新员工档案数据. *

* 请求方式:POST(HTTPS) From d69067ca438edba3ada32ddd62112a984438b737 Mon Sep 17 00:00:00 2001 From: WangJiuJun Date: Thu, 7 May 2026 14:26:33 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=20java21=E4=B8=8B?= =?UTF-8?q?=E4=B8=80guice=E5=92=8Ccglib=E5=8F=8D=E5=B0=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9B=E4=BF=AE=E5=A4=8DgetFieldInfo=E5=92=8CGetEmp?= =?UTF-8?q?loyeeFieldInfo=E8=AF=B7=E6=B1=82=E6=88=90=E5=8A=9F=E5=90=8E?= =?UTF-8?q?=E7=9A=84=E5=8F=8D=E5=BA=8F=E5=88=97=E5=8C=96=E9=97=AE=E9=A2=98?= =?UTF-8?q?=EF=BC=9BUpdateEmployeeFieldInfo=E6=9A=82=E6=97=B6=E6=9C=AA?= =?UTF-8?q?=E7=94=A8=E5=88=B0=EF=BC=8C=E6=9C=AA=E5=81=9A=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-cp/pom.xml | 9 ++ .../cp/bean/hr/WxCpHrEmployeeFieldData.java | 104 ++++++++++++++-- .../bean/hr/WxCpHrEmployeeFieldDataResp.java | 24 +++- .../cp/bean/hr/WxCpHrEmployeeFieldInfo.java | 114 +++++++++++++---- .../bean/hr/WxCpHrEmployeeFieldInfoResp.java | 53 +++++++- .../cp/api/impl/WxCpHrServiceImplTest.java | 117 ++++++++++++++++-- weixin-java-cp/src/test/resources/testng.xml | 1 + 7 files changed, 376 insertions(+), 46 deletions(-) diff --git a/weixin-java-cp/pom.xml b/weixin-java-cp/pom.xml index e109b1c60..1a4529e6a 100644 --- a/weixin-java-cp/pom.xml +++ b/weixin-java-cp/pom.xml @@ -126,6 +126,15 @@ src/test/resources/testng.xml + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.io=ALL-UNNAMED + --add-opens java.base/java.security=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.management/javax.management=ALL-UNNAMED + --add-opens java.naming/javax.naming=ALL-UNNAMED + diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldData.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldData.java index 971e5958d..bb4d3a60a 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldData.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldData.java @@ -5,10 +5,9 @@ import lombok.NoArgsConstructor; import java.io.Serializable; -import java.util.List; /** - * 人事助手-员工档案数据(单个员工). + * 人事助手-员工档案数据(单个字段). * * @author leejoker created on 2024-01-01 */ @@ -18,19 +17,98 @@ public class WxCpHrEmployeeFieldData implements Serializable { private static final long serialVersionUID = 4593693598671765396L; /** - * 员工userid. + * 字段ID. */ + @SerializedName("fieldid") + private Integer fieldId; + + /** + * 子字段索引. + */ + @SerializedName("sub_idx") + private Integer subIdx; + + /** + * 结果状态,1表示成功. + */ + @SerializedName("result") + private Integer result; + + /** + * 值类型:1-字符串,2-uint64,3-uint32,4-int64,5-mobile. + */ + @SerializedName("value_type") + private Integer valueType; + + /** + * 字符串值(value_type=1时使用). + */ + @SerializedName("value_string") + private String valueString; + + /** + * 无符号32位整数值(value_type=3时使用). + */ + @SerializedName("value_uint32") + private Long valueUint32; + + /** + * 有符号64位整数值(value_type=4时使用). + */ + @SerializedName("value_int64") + private Long valueInt64; + + /** + * 无符号64位整数值(value_type=2时使用). + */ + @SerializedName("value_uint64") + private Long valueUint64; + + /** + * 手机号值(value_type=5时使用). + */ + @SerializedName("value_mobile") + private MobileValue valueMobile; + + /** + * 手机号值. + */ + @Data + @NoArgsConstructor + public static class MobileValue implements Serializable { + private static final long serialVersionUID = 1L; + + /** + * 国家代码. + */ + @SerializedName("value_country_code") + private String valueCountryCode; + + /** + * 手机号. + */ + @SerializedName("value_mobile") + private String valueMobile; + } + + /** + * 员工userid(兼容旧版本,实际API不返回此字段). + * @deprecated 此字段在API响应中不存在 + */ + @Deprecated @SerializedName("userid") private String userid; /** - * 字段数据列表. + * 字段数据列表(兼容旧版本,实际API不返回此字段). + * @deprecated 此字段在API响应中不存在 */ + @Deprecated @SerializedName("field_list") - private List fieldList; + private java.util.List fieldList; /** - * 字段数据项. + * 字段数据项(用于更新员工档案). */ @Data @NoArgsConstructor @@ -38,15 +116,21 @@ public static class FieldItem implements Serializable { private static final long serialVersionUID = 1L; /** - * 字段key. + * 字段ID. */ - @SerializedName("field_key") - private String fieldKey; + @SerializedName("fieldid") + private Integer fieldId; /** - * 字段值. + * 字段值对象(推荐使用,支持多种类型). */ @SerializedName("field_value") private WxCpHrEmployeeFieldValue fieldValue; + + /** + * 字符串值(简化用法,适用于文本类型字段). + */ + @SerializedName("value_string") + private String valueString; } } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldDataResp.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldDataResp.java index 07e286c2e..f8e763c29 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldDataResp.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldDataResp.java @@ -21,10 +21,28 @@ public class WxCpHrEmployeeFieldDataResp extends WxCpBaseResp { private static final long serialVersionUID = 6593693598671765396L; /** - * 员工档案数据列表. + * 字段数据列表(API实际返回field_info). */ - @SerializedName("employee_field_list") - private List employeeFieldList; + @SerializedName("field_info") + private List fieldInfoList; + + /** + * 员工档案数据列表(兼容旧版本方法名). + * @deprecated 请使用 getFieldInfoList() + */ + @Deprecated + public List getEmployeeFieldList() { + return this.fieldInfoList; + } + + /** + * 员工档案数据列表(兼容旧版本方法名). + * @deprecated 请使用 setFieldInfoList() + */ + @Deprecated + public void setEmployeeFieldList(List employeeFieldList) { + this.fieldInfoList = employeeFieldList; + } /** * From json wx cp hr employee field data resp. diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldInfo.java index e355d8cc6..3db3f2057 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldInfo.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/hr/WxCpHrEmployeeFieldInfo.java @@ -18,30 +18,43 @@ public class WxCpHrEmployeeFieldInfo implements Serializable { private static final long serialVersionUID = 2593693598671765396L; /** - * 字段key. + * 字段ID. */ - @SerializedName("field_key") - private String fieldKey; - - /** - * 字段英文名称. - */ - @SerializedName("field_en_name") - private String fieldEnName; + @SerializedName("fieldid") + private Integer fieldId; /** - * 字段中文名称. + * 字段名称. */ - @SerializedName("field_zh_name") - private String fieldZhName; + @SerializedName("field_name") + private String fieldName; /** * 字段类型. - * 具体取值参见 {@link WxCpHrFieldType} + * 1: 文本 + * 2: 单选/多选 + * 3: 日期 */ @SerializedName("field_type") private Integer fieldType; + /** + * 是否必填. + */ + @SerializedName("is_must") + private Boolean isMust; + + /** + * 值类型. + * 1: 字符串 + * 2: uint64 + * 3: uint32 + * 4: int64 + * 5: mobile + */ + @SerializedName("value_type") + private Integer valueType; + /** * 获取字段类型枚举. * @@ -52,22 +65,79 @@ public WxCpHrFieldType getFieldTypeEnum() { } /** - * 是否系统字段. - * 0: 否 - * 1: 是 + * 选项列表(单选/多选字段专用). + */ + @SerializedName("option_list") + private List