#1144 企业微信模块增加通过手机号获取userid的接口

This commit is contained in:
Binary Wang 2019-08-10 17:53:07 +08:00
parent 3a1fae639a
commit 7033b1d5d6
4 changed files with 40 additions and 0 deletions

View File

@ -137,6 +137,23 @@ public interface WxCpUserService {
*/
String openid2UserId(String openid) throws WxErrorException;
/**
* <pre>
*
* 通过手机号获取其所对应的userid
*
* 请求方式POSTHTTPS
* 请求地址https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=ACCESS_TOKEN
*
* 文档地址https://work.weixin.qq.com/api/doc#90001/90143/91693
* </pre>
*
* @param mobile 手机号码长度为5~32个字节
* @return userid mobile对应的成员userid
* @throws WxErrorException .
*/
String getUserId(String mobile) throws WxErrorException;
/**
* 获取外部联系人详情.
* <pre>
@ -147,6 +164,8 @@ public interface WxCpUserService {
* </pre>
*
* @param userId 外部联系人的userid
* @return 联系人详情
* @throws WxErrorException .
*/
WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException;

View File

@ -180,6 +180,16 @@ public class WxCpUserServiceImpl implements WxCpUserService {
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
}
@Override
public String getUserId(String mobile) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("mobile", mobile);
String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_ID);
String responseContent = this.mainService.post(url, jsonObject.toString());
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return tmpJsonElement.getAsJsonObject().get("userid").getAsString();
}
@Override
public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException {
String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId);

View File

@ -101,6 +101,7 @@ public final class WxCpApiPathConsts {
public static final String BATCH_INVITE = "/cgi-bin/batch/invite";
public static final String USER_CONVERT_TO_OPENID = "/cgi-bin/user/convert_to_openid";
public static final String USER_CONVERT_TO_USERID = "/cgi-bin/user/convert_to_userid";
public static final String GET_USER_ID = "/cgi-bin/user/getuserid";
public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=";
}

View File

@ -112,4 +112,14 @@ public class WxCpUserServiceImplTest {
}
@Test
public void testGetUserId() throws WxErrorException {
String result = this.wxCpService.getUserService().getUserId("xxx");
System.out.println(result);
assertNotNull(result);
}
@Test
public void testGetExternalContact() {
}
}