diff --git a/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md b/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md index a4d91fade..8d96901f2 100644 --- a/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md +++ b/spring-boot-starters/wx-java-pay-spring-boot-starter/README.md @@ -8,6 +8,7 @@ ``` 2. 添加配置(application.yml) +###### 1)V2版本 ```yml wx: pay: @@ -18,6 +19,17 @@ wx: subMchId: keyPath: ``` +###### 2)V3版本 +```yml +wx: + pay: + appId: xxxxxxxxxxx + mchId: 15xxxxxxxxx #商户id + apiV3Key: Dc1DBwSc094jACxxxxxxxxxxxxxxx #V3密钥 + certSerialNo: 62C6CEAA360BCxxxxxxxxxxxxxxx + privateKeyPath: classpath:cert/apiclient_key.pem #apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径 + privateCertPath: classpath:cert/apiclient_cert.pem #apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径 +``` diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java index 569f9172e..d5bd6702c 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java @@ -5,6 +5,7 @@ import me.chanjar.weixin.cp.bean.WxCpInviteResult; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult; import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo; +import me.chanjar.weixin.cp.bean.user.WxCpDeptUserResult; import java.util.ArrayList; import java.util.Date; @@ -224,9 +225,25 @@ public interface WxCpUserService { * userid转换为open_userid * 将自建应用或代开发应用获取的userid转换为第三方应用的userid * https://developer.work.weixin.qq.com/document/path/95603 + * * @param useridList * @return the WxCpUseridToOpenUseridResult * @throws WxErrorException */ WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList useridList) throws WxErrorException; + + /** + * 获取成员ID列表 + * 获取企业成员的userid与对应的部门ID列表,预计于2022年8月8号发布。若需要获取其他字段,参见「适配建议」。 + *

+ * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/list_id?access_token=ACCESS_TOKEN + * + * @param cursor + * @param limit + * @return + * @throws WxErrorException + */ + WxCpDeptUserResult getUserListId(String cursor, Integer limit) throws WxErrorException; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java index 219a07eb4..f7ff0f57b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java @@ -14,7 +14,7 @@ import me.chanjar.weixin.cp.bean.WxCpInviteResult; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult; import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo; -import me.chanjar.weixin.cp.constant.WxCpApiPathConsts; +import me.chanjar.weixin.cp.bean.user.WxCpDeptUserResult; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; import org.apache.commons.lang3.time.FastDateFormat; @@ -231,7 +231,7 @@ public class WxCpUserServiceImpl implements WxCpUserService { public WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList useridList) throws WxErrorException { JsonObject jsonObject = new JsonObject(); JsonArray jsonArray = new JsonArray(); - for(String userid:useridList){ + for (String userid : useridList) { jsonArray.add(userid); } jsonObject.add("userid_list", jsonArray); @@ -240,4 +240,19 @@ public class WxCpUserServiceImpl implements WxCpUserService { return WxCpUseridToOpenUseridResult.fromJson(responseContent); } + @Override + public WxCpDeptUserResult getUserListId(String cursor, Integer limit) throws WxErrorException { + String apiUrl = this.mainService.getWxCpConfigStorage().getApiUrl(USER_LIST_ID); + JsonObject jsonObject = new JsonObject(); + if (cursor != null) { + jsonObject.addProperty("cursor", cursor); + } + if (limit != null) { + jsonObject.addProperty("limit", limit); + } + String responseContent = this.mainService.post(apiUrl, jsonObject.toString()); + return WxCpDeptUserResult.fromJson(responseContent); + } + + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/user/WxCpDeptUserResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/user/WxCpDeptUserResult.java new file mode 100644 index 000000000..287476f83 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/user/WxCpDeptUserResult.java @@ -0,0 +1,58 @@ +package me.chanjar.weixin.cp.bean.user; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 获取成员ID列表返回参数 + * + * @author Wang_Wong + * @date 2022/08/09 + */ +@Data +public class WxCpDeptUserResult extends WxCpBaseResp { + private static final long serialVersionUID = 1420065684270213578L; + + @SerializedName("next_cursor") + private String nextCursor; + + @SerializedName("dept_user") + private List deptUser; + + @Getter + @Setter + public static class DeptUserList implements Serializable { + private static final long serialVersionUID = 1420065684270213578L; + + @SerializedName("userid") + private String userId; + + @SerializedName("department") + private Long department; + + public static DeptUserList fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, DeptUserList.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + public static WxCpDeptUserResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpDeptUserResult.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index cb0532083..c8ee12c1b 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -325,6 +325,8 @@ public interface WxCpApiPathConsts { String GET_JOIN_QR_CODE = "/cgi-bin/corp/get_join_qrcode?size_type="; String GET_ACTIVE_STAT = "/cgi-bin/user/get_active_stat"; String USERID_TO_OPEN_USERID = "/cgi-bin/batch/userid_to_openuserid"; + + String USER_LIST_ID = "/cgi-bin/user/list_id"; } interface ExternalContact { diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java index 7417f8055..d08dee498 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java @@ -72,6 +72,13 @@ public class WxCpDepartmentServiceImplTest { this.wxCpService.getDepartmentService().delete(this.depart.getId()); } + /** + * 获取子部门ID列表 + * https://developer.work.weixin.qq.com/document/path/95350 + * + * @param id + * @throws WxErrorException + */ @Test(dataProvider = "departIds") public void testSimpleList(Long id) throws WxErrorException { System.out.println("=================获取子部门ID列表"); diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java index 0fb494ff3..a09bf6f70 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java @@ -1,23 +1,26 @@ package me.chanjar.weixin.cp.api.impl; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.lang3.builder.ToStringStyle; -import org.testng.annotations.*; - import com.google.common.collect.Lists; import com.google.inject.Inject; +import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.ApiTestModule; import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.bean.Gender; import me.chanjar.weixin.cp.bean.WxCpInviteResult; import me.chanjar.weixin.cp.bean.WxCpUser; +import me.chanjar.weixin.cp.bean.user.WxCpDeptUserResult; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.testng.annotations.Guice; +import org.testng.annotations.Test; -import static org.testng.Assert.*; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import static org.testng.Assert.assertNotEquals; +import static org.testng.Assert.assertNotNull; /** *

@@ -26,6 +29,7 @@ import static org.testng.Assert.*;
  *
  * @author Binary Wang
  */
+@Slf4j
 @Guice(modules = ApiTestModule.class)
 public class WxCpUserServiceImplTest {
   @Inject
@@ -129,4 +133,20 @@ public class WxCpUserServiceImplTest {
     System.out.printf("active stat: %d", activeStat);
     assertNotNull(activeStat);
   }
+
+  /**
+   * 获取成员ID列表
+   * 获取企业成员的userid与对应的部门ID列表,预计于2022年8月8号发布。若需要获取其他字段,参见「适配建议」。
+   * 

+ * https://developer.work.weixin.qq.com/document/40856 + * + * @throws WxErrorException + */ + @Test + public void testGetUserListId() throws WxErrorException { + WxCpDeptUserResult result = this.wxCpService.getUserService().getUserListId(null, 10); + log.info("返回结果为:{}", result.toJson()); + assertNotNull(result); + } + } diff --git a/weixin-java-pay/src/test/resources/test-config.sample.xml b/weixin-java-pay/src/test/resources/test-config.sample.xml index 25ec4be05..9a299b8ac 100644 --- a/weixin-java-pay/src/test/resources/test-config.sample.xml +++ b/weixin-java-pay/src/test/resources/test-config.sample.xml @@ -1,21 +1,22 @@ 公众号appid 微信商户平台ID - 商户平台设置的API密钥 + 以下为官网文档所提供样例参数,仅供部分接口测试使用 + wxd930ea5d5a258f4f + 10000100 + 192006250b4c09247ec02edce69f6a2d +--> + + 商户平台设置的API密钥 商户平台的证书文件地址 - 某个openId - apiV3 秘钥值. apiV3 证书序列号值 - --> + apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径. + apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径. + + + 某个openId