diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java index 0125db625e..b397a121a4 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java @@ -174,6 +174,23 @@ public interface WxCpUserService { */ String getUserId(String mobile) throws WxErrorException; + /** + *
+   *
+   * 通过邮箱获取其所对应的userid。
+   *
+   * 请求方式:POST(HTTPS)
+   * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/get_userid_by_email?access_token=ACCESS_TOKEN
+   *
+   * 文档地址:https://developer.work.weixin.qq.com/document/path/95895
+   * 
+ * + * @param email 手机号码。长度为5~32个字节 + * @return userid email对应的成员userid + * @throws WxErrorException . + */ + String getUserIdByEmail(String email,int emailType) throws WxErrorException; + /** * 获取外部联系人详情. *
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
index 407418d05f..f1556d4e31 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
@@ -203,6 +203,17 @@ public String getUserId(String mobile) throws WxErrorException {
     return tmpJson.get("userid").getAsString();
   }
 
+  @Override
+  public String getUserIdByEmail(String email, int emailType) throws WxErrorException {
+    JsonObject jsonObject = new JsonObject();
+    jsonObject.addProperty("email", email);
+    jsonObject.addProperty("email_type", emailType);
+    String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_USER_ID_BY_EMAIL);
+    String responseContent = this.mainService.post(url, jsonObject.toString());
+    JsonObject tmpJson = GsonParser.parse(responseContent);
+    return tmpJson.get("userid").getAsString();
+  }
+
   @Override
   public WxCpExternalContactInfo getExternalContact(String userId) throws WxErrorException {
     String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_EXTERNAL_CONTACT + userId);
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
index d03a52f31e..be9f4e0642 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
@@ -965,6 +965,10 @@ interface User {
      * The constant GET_USER_ID.
      */
     String GET_USER_ID = "/cgi-bin/user/getuserid";
+    /**
+     * The constant GET_USER_ID_BY_EMAIL.
+     */
+    String GET_USER_ID_BY_EMAIL = "/cgi-bin/user/get_userid_by_email";
     /**
      * The constant GET_EXTERNAL_CONTACT.
      */
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java
index 49b2c8e8d4..73282c16f7 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImplTest.java
@@ -178,6 +178,18 @@ public void testGetUserId() throws WxErrorException {
     assertNotNull(result);
   }
 
+  /**
+   * Test get user id by email.
+   *
+   * @throws WxErrorException the wx error exception
+   */
+  @Test
+  public void testGetUserIdByEmail() throws WxErrorException {
+    String result = this.wxCpService.getUserService().getUserIdByEmail("xxx",1);
+    System.out.println(result);
+    assertNotNull(result);
+  }
+
   /**
    * Test get external contact.
    */