Skip to content

Commit 59a1456

Browse files
authored
🆕 #2298【企业微信】增加服务商模式外部联系人unionid转换接口
1 parent 2a36ebf commit 59a1456

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpExternalContactService.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,29 @@ public interface WxCpExternalContactService {
159159
*/
160160
String convertToOpenid(String externalUserid) throws WxErrorException;
161161

162+
/**
163+
* 服务商为企业代开发微信小程序的场景,服务商可通过此接口,将微信客户的unionid转为external_userid。
164+
* <pre>
165+
*
166+
* 文档地址:https://work.weixin.qq.com/api/doc/90001/90143/93274
167+
*
168+
* 服务商代开发小程序指企业使用的小程序为企业主体的,非服务商主体的小程序。
169+
* 场景:企业客户在微信端从企业主体的小程序(非服务商应用)登录,同时企业在企业微信安装了服务商的第三方应用,服务商可以调用该接口将登录用户的unionid转换为服务商全局唯一的外部联系人id
170+
*
171+
* 权限说明:
172+
*
173+
* 仅认证企业可调用
174+
* unionid必须是企业主体下的unionid。即unionid的主体(为绑定了该小程序的微信开放平台账号主体)需与当前企业的主体一致。
175+
* unionid的主体(即微信开放平台账号主体)需认证
176+
* 该客户的跟进人必须在应用的可见范围之内
177+
* </pre>
178+
*
179+
* @param unionid 微信客户的unionid
180+
* @return 该企业的外部联系人ID
181+
* @throws WxErrorException .
182+
*/
183+
String unionidToExternalUserid(String unionid) throws WxErrorException;
184+
162185
/**
163186
* 批量获取客户详情.
164187
* <pre>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ public String convertToOpenid(@NotNull String externalUserId) throws WxErrorExce
137137
return tmpJson.get("openid").getAsString();
138138
}
139139

140+
@Override
141+
public String unionidToExternalUserid(@NotNull String unionid) throws WxErrorException {
142+
JsonObject json = new JsonObject();
143+
json.addProperty("unionid", unionid);
144+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(UNIONID_TO_EXTERNAL_USERID);
145+
String responseContent = this.mainService.post(url, json.toString());
146+
JsonObject tmpJson = GsonParser.parse(responseContent);
147+
return tmpJson.get("external_userid").getAsString();
148+
}
149+
140150
@Override
141151
public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
142152
String cursor,

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ interface ExternalContact {
181181
String GET_FOLLOW_USER_LIST = "/cgi-bin/externalcontact/get_follow_user_list";
182182
String GET_CONTACT_DETAIL = "/cgi-bin/externalcontact/get?external_userid=";
183183
String CONVERT_TO_OPENID = "/cgi-bin/externalcontact/convert_to_openid";
184+
String UNIONID_TO_EXTERNAL_USERID = "/cgi-bin/externalcontact/unionid_to_external_userid";
184185
String GET_CONTACT_DETAIL_BATCH = "/cgi-bin/externalcontact/batch/get_by_user?";
185186
String UPDATE_REMARK = "/cgi-bin/externalcontact/remark";
186187
String LIST_EXTERNAL_CONTACT = "/cgi-bin/externalcontact/list?userid=";

0 commit comments

Comments
 (0)