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=";