From 5913bddbe3fd5a0cba080989b22faa3e1f539082 Mon Sep 17 00:00:00 2001 From: ArBing Date: Fri, 3 Sep 2021 17:42:14 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E3=80=90=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E3=80=91=E5=A2=9E=E5=8A=A0=E6=9C=8D=E5=8A=A1=E5=95=86?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E5=A4=96=E9=83=A8=E8=81=94=E7=B3=BB=E4=BA=BA?= =?UTF-8?q?unionid=E8=BD=AC=E6=8D=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cp/api/WxCpExternalContactService.java | 23 +++++++++++++++++++ .../impl/WxCpExternalContactServiceImpl.java | 10 ++++++++ .../weixin/cp/constant/WxCpApiPathConsts.java | 1 + 3 files changed, 34 insertions(+) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java index 0f06a9adba..c7507d656d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java @@ -159,6 +159,29 @@ public interface WxCpExternalContactService { */ String convertToOpenid(String externalUserid) throws WxErrorException; + /** + * 服务商为企业代开发微信小程序的场景,服务商可通过此接口,将微信客户的unionid转为external_userid。 + *
+   *
+   * 文档地址:https://work.weixin.qq.com/api/doc/90001/90143/93274
+   *
+   * 服务商代开发小程序指企业使用的小程序为企业主体的,非服务商主体的小程序。
+   * 场景:企业客户在微信端从企业主体的小程序(非服务商应用)登录,同时企业在企业微信安装了服务商的第三方应用,服务商可以调用该接口将登录用户的unionid转换为服务商全局唯一的外部联系人id
+   *
+   * 权限说明:
+   *
+   * 仅认证企业可调用
+   * unionid必须是企业主体下的unionid。即unionid的主体(为绑定了该小程序的微信开放平台账号主体)需与当前企业的主体一致。
+   * unionid的主体(即微信开放平台账号主体)需认证
+   * 该客户的跟进人必须在应用的可见范围之内
+   * 
+ * + * @param unionid 微信客户的unionid + * @return 该企业的外部联系人ID + * @throws WxErrorException . + */ + String unionidToExternalUserid(String unionid) throws WxErrorException; + /** * 批量获取客户详情. *
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
index 60c7c068ba..29d70a2595 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java
@@ -137,6 +137,16 @@ public String convertToOpenid(@NotNull String externalUserId) throws WxErrorExce
     return tmpJson.get("openid").getAsString();
   }
 
+  @Override
+  public String unionidToExternalUserid(@NotNull String unionid) throws WxErrorException {
+    JsonObject json = new JsonObject();
+    json.addProperty("unionid", unionid);
+    final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UNIONID_TO_EXTERNAL_USERID);
+    String responseContent = this.mainService.post(url, json.toString());
+    JsonObject tmpJson = GsonParser.parse(responseContent);
+    return tmpJson.get("external_userid").getAsString();
+  }
+
   @Override
   public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
                                                             String cursor,
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 98bd7425c5..1a184e9a54 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
@@ -181,6 +181,7 @@ interface ExternalContact {
     String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list";
     String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid=";
     String CONVERT_TO_OPENID = "/cgi-bin/externalcontact/convert_to_openid";
+    String UNIONID_TO_EXTERNAL_USERID = "/cgi-bin/externalcontact/unionid_to_external_userid";
     String GET_CONTACT_DETAIL_BATCH = "/cgi-bin/externalcontact/batch/get_by_user?";
     String UPDATE_REMARK = "/cgi-bin/externalcontact/remark";
     String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid=";