From 572f521210a346727bc1913e51db033df4cde238 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=BB=E5=BD=B1=E6=AE=8B=E9=A3=8E?= Date: Sat, 8 Oct 2022 11:22:11 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=81=E4=B8=9A=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E3=80=91=E6=96=B0=E5=A2=9E=E5=B0=86=E4=BB=A3=E5=BC=80=E5=8F=91?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E6=88=96=E7=AC=AC=E4=B8=89=E6=96=B9=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E8=8E=B7=E5=8F=96=E7=9A=84=E5=AF=86=E6=96=87open=5Fus?= =?UTF-8?q?erid=E8=BD=AC=E6=8D=A2=E4=B8=BA=E6=98=8E=E6=96=87userid?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/cp/api/WxCpUserService.java | 19 ++++++++ .../cp/api/impl/WxCpUserServiceImpl.java | 15 ++++++ .../cp/bean/WxCpOpenUseridToUserid.java | 40 ++++++++++++++++ .../cp/bean/WxCpOpenUseridToUseridResult.java | 47 +++++++++++++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 4 ++ 5 files changed, 125 insertions(+) create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUserid.java create mode 100644 weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUseridResult.java 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 4b75450ff6..0125db625e 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 @@ -2,6 +2,7 @@ import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.bean.WxCpInviteResult; +import me.chanjar.weixin.cp.bean.WxCpOpenUseridToUseridResult; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult; import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo; @@ -233,6 +234,24 @@ public interface WxCpUserService { */ WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList useridList) throws WxErrorException; + /** + * open_userid转换为userid + * 将代开发应用或第三方应用获取的密文open_userid转换为明文userid + *
+   * 文档地址:https://developer.work.weixin.qq.com/document/path/95884#userid%E8%BD%AC%E6%8D%A2
+   *
+   * 权限说明:
+   *
+   * 需要使用自建应用或基础应用的access_token
+   * 成员需要同时在access_token和source_agentid所对应应用的可见范围内
+   * 
+ * @param openUseridList open_userid列表,最多不超过1000个。必须是source_agentid对应的应用所获取 + * @param sourceAgentId 企业授权的代开发自建应用或第三方应用的agentid + * @return the WxCpOpenUseridToUseridResult + * @throws WxErrorException the wx error exception + */ + WxCpOpenUseridToUseridResult openUseridToUserid(List openUseridList, String sourceAgentId) throws WxErrorException; + /** * 获取成员ID列表 * 获取企业成员的userid与对应的部门ID列表,预计于2022年8月8号发布。若需要获取其他字段,参见「适配建议」。 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 f7ff0f57b8..407418d05f 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 @@ -11,6 +11,7 @@ import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpUserService; import me.chanjar.weixin.cp.bean.WxCpInviteResult; +import me.chanjar.weixin.cp.bean.WxCpOpenUseridToUseridResult; import me.chanjar.weixin.cp.bean.WxCpUser; import me.chanjar.weixin.cp.bean.WxCpUseridToOpenUseridResult; import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo; @@ -240,6 +241,20 @@ public WxCpUseridToOpenUseridResult useridToOpenUserid(ArrayList useridL return WxCpUseridToOpenUseridResult.fromJson(responseContent); } + @Override + public WxCpOpenUseridToUseridResult openUseridToUserid(List openUseridList, String sourceAgentId) throws WxErrorException { + JsonObject jsonObject = new JsonObject(); + JsonArray jsonArray = new JsonArray(); + for (String openUserid : openUseridList) { + jsonArray.add(openUserid); + } + jsonObject.add("open_userid_list", jsonArray); + jsonObject.addProperty("source_agentid", sourceAgentId); + String url = this.mainService.getWxCpConfigStorage().getApiUrl(OPEN_USERID_TO_USERID); + String responseContent = this.mainService.post(url, jsonObject.toString()); + return WxCpOpenUseridToUseridResult.fromJson(responseContent); + } + @Override public WxCpDeptUserResult getUserListId(String cursor, Integer limit) throws WxErrorException { String apiUrl = this.mainService.getWxCpConfigStorage().getApiUrl(USER_LIST_ID); diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUserid.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUserid.java new file mode 100644 index 0000000000..ec4d276e0a --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUserid.java @@ -0,0 +1,40 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * userid转换 + * 将代开发应用或第三方应用获取的密文open_userid转换为明文userid + * 中间对象 + * @author yiyingcanfeng + */ +@Data +public class WxCpOpenUseridToUserid implements Serializable { + private static final long serialVersionUID = 1714909184316350423L; + + @Override + public String toString() { + return WxCpGsonBuilder.create().toJson(this); + } + + /** + * From json wx cp open userid to userid result. + * + * @param json the json + * @return the wx cp open userid to userid result. + */ + public static WxCpOpenUseridToUserid fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpOpenUseridToUserid.class); + } + + @SerializedName("userid") + private String userid; + + @SerializedName("open_userid") + private String openUserid; + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUseridResult.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUseridResult.java new file mode 100644 index 0000000000..122c3a0dc6 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpOpenUseridToUseridResult.java @@ -0,0 +1,47 @@ +package me.chanjar.weixin.cp.bean; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * userid转换 + * 将代开发应用或第三方应用获取的密文open_userid转换为明文userid + * @author yiyingcanfeng + */ +@Data +public class WxCpOpenUseridToUseridResult implements Serializable { + private static final long serialVersionUID = 5179329535139861515L; + + @Override + public String toString() { + return WxCpGsonBuilder.create().toJson(this); + } + + /** + * From json wx cp open userid to userid result. + * + * @param json the json + * @return the wx cp open userid to userid result + */ + public static WxCpOpenUseridToUseridResult fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpOpenUseridToUseridResult.class); + } + + @SerializedName("errcode") + private Integer errCode; + + @SerializedName("errmsg") + private String errMsg; + + @SerializedName("userid_list") + private List useridList; + + @SerializedName("invalid_open_userid_list") + private List invalidOpenUseridList; + + +} 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 7751078459..c08b8b078a 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 @@ -931,6 +931,10 @@ interface User { * The constant USERID_TO_OPEN_USERID. */ String USERID_TO_OPEN_USERID = "/cgi-bin/batch/userid_to_openuserid"; + /** + * The constant OPEN_USERID_TO_USERID. + */ + String OPEN_USERID_TO_USERID = "/cgi-bin/batch/openuserid_to_userid"; /** * The constant USER_LIST_ID.