Parcourir la source

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

master
Binary Wang il y a 5 ans
Parent
révision
7033b1d5d6
4 fichiers modifiés avec 40 ajouts et 0 suppressions
  1. +19
    -0
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
  2. +10
    -0
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
  3. +1
    -0
      weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
  4. +10
    -0
      weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java

+ 19
- 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java Voir le fichier

@@ -137,6 +137,23 @@ public interface WxCpUserService {
*/
String openid2UserId(String openid) throws WxErrorException;

/**
* <pre>
*
* 通过手机号获取其所对应的userid。
*
* 请求方式:POST(HTTPS)
* 请求地址: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;



+ 10
- 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java Voir le fichier

@@ -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);


+ 1
- 0
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java Voir le fichier

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



+ 10
- 0
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java Voir le fichier

@@ -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() {
}
}

Chargement…
Annuler
Enregistrer