mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 10:38:42 +08:00 
			
		
		
		
	✨ #1144 企业微信模块增加通过手机号获取userid的接口
This commit is contained in:
		| @ -137,6 +137,23 @@ public interface WxCpUserService { | |||||||
|    */ |    */ | ||||||
|   String openid2UserId(String openid) throws WxErrorException; |   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> |    * <pre> | ||||||
| @ -147,6 +164,8 @@ public interface WxCpUserService { | |||||||
|    * </pre> |    * </pre> | ||||||
|    * |    * | ||||||
|    * @param userId 外部联系人的userid |    * @param userId 外部联系人的userid | ||||||
|  |    * @return 联系人详情 | ||||||
|  |    * @throws WxErrorException . | ||||||
|    */ |    */ | ||||||
|   WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException; |   WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException; | ||||||
|  |  | ||||||
|  | |||||||
| @ -180,6 +180,16 @@ public class WxCpUserServiceImpl implements WxCpUserService { | |||||||
|     return tmpJsonElement.getAsJsonObject().get("userid").getAsString(); |     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 |   @Override | ||||||
|   public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException { |   public WxCpUserExternalContactInfo getExternalContact(String userId) throws WxErrorException { | ||||||
|     String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId); |     String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId); | ||||||
|  | |||||||
| @ -101,6 +101,7 @@ public final class WxCpApiPathConsts { | |||||||
|     public static final String BATCH_INVITE = "/cgi-bin/batch/invite"; |     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_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 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="; |     public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid="; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  | |||||||
| @ -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() { | ||||||
|  |   } | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang