Skip to content

Commit

Permalink
企业微信服务商模式缺少外部联系人openid转换 binarywang#2147
Browse files Browse the repository at this point in the history
  • Loading branch information
pengg committed Jun 22, 2021
1 parent dc3f855 commit f23271e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ public interface WxCpExternalContactService {
*/
WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorException;

/**
* 企业和服务商可通过此接口,将微信外部联系人的userid转为微信openid,用于调用支付相关接口。暂不支持企业微信外部联系人(ExternalUserid为wo开头)的userid转openid。
* @param externalUserid 微信外部联系人的userid
* @return 该企业的外部联系人openid
* @throws WxErrorException .
*/
String convertToOpenid(String externalUserid) throws WxErrorException;

/**
* 批量获取客户详情.
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.util.BeanUtils;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.WxCpExternalContactService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
Expand Down Expand Up @@ -108,6 +109,16 @@ public WxCpExternalContactInfo getContactDetail(String userId) throws WxErrorExc
return WxCpExternalContactInfo.fromJson(responseContent);
}

@Override
public String convertToOpenid(@NotNull String externalUserId) throws WxErrorException {
JsonObject json = new JsonObject();
json.addProperty("external_userid", externalUserId);
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(CONVERT_TO_OPENID);
String responseContent = this.mainService.post(url, json.toString());
JsonObject tmpJson = GsonParser.parse(responseContent);
return tmpJson.get("openid").getAsString();
}

@Override
public WxCpExternalContactBatchInfo getContactDetailBatch(String userId,
String cursor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ interface ExternalContact {
String CLOSE_TEMP_CHAT = "/cgi-bin/externalcontact/close_temp_chat";
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 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=";
Expand Down

0 comments on commit f23271e

Please sign in to comment.