File tree Expand file tree Collapse file tree 4 files changed +44
-0
lines changed
main/java/me/chanjar/weixin/cp
test/java/me/chanjar/weixin/cp/api/impl Expand file tree Collapse file tree 4 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -174,6 +174,23 @@ public interface WxCpUserService {
174174 */
175175 String getUserId (String mobile ) throws WxErrorException ;
176176
177+ /**
178+ * <pre>
179+ *
180+ * 通过邮箱获取其所对应的userid。
181+ *
182+ * 请求方式:POST(HTTPS)
183+ * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/get_userid_by_email?access_token=ACCESS_TOKEN
184+ *
185+ * 文档地址:https://developer.work.weixin.qq.com/document/path/95895
186+ * </pre>
187+ *
188+ * @param email 手机号码。长度为5~32个字节
189+ * @return userid email对应的成员userid
190+ * @throws WxErrorException .
191+ */
192+ String getUserIdByEmail (String email ,int emailType ) throws WxErrorException ;
193+
177194 /**
178195 * 获取外部联系人详情.
179196 * <pre>
Original file line number Diff line number Diff line change @@ -203,6 +203,17 @@ public String getUserId(String mobile) throws WxErrorException {
203203 return tmpJson .get ("userid" ).getAsString ();
204204 }
205205
206+ @ Override
207+ public String getUserIdByEmail (String email , int emailType ) throws WxErrorException {
208+ JsonObject jsonObject = new JsonObject ();
209+ jsonObject .addProperty ("email" , email );
210+ jsonObject .addProperty ("email_type" , emailType );
211+ String url = this .mainService .getWxCpConfigStorage ().getApiUrl (GET_USER_ID_BY_EMAIL );
212+ String responseContent = this .mainService .post (url , jsonObject .toString ());
213+ JsonObject tmpJson = GsonParser .parse (responseContent );
214+ return tmpJson .get ("userid" ).getAsString ();
215+ }
216+
206217 @ Override
207218 public WxCpExternalContactInfo getExternalContact (String userId ) throws WxErrorException {
208219 String url = this .mainService .getWxCpConfigStorage ().getApiUrl (GET_EXTERNAL_CONTACT + userId );
Original file line number Diff line number Diff line change @@ -965,6 +965,10 @@ interface User {
965965 * The constant GET_USER_ID.
966966 */
967967 String GET_USER_ID = "/cgi-bin/user/getuserid" ;
968+ /**
969+ * The constant GET_USER_ID_BY_EMAIL.
970+ */
971+ String GET_USER_ID_BY_EMAIL = "/cgi-bin/user/get_userid_by_email" ;
968972 /**
969973 * The constant GET_EXTERNAL_CONTACT.
970974 */
Original file line number Diff line number Diff line change @@ -178,6 +178,18 @@ public void testGetUserId() throws WxErrorException {
178178 assertNotNull (result );
179179 }
180180
181+ /**
182+ * Test get user id by email.
183+ *
184+ * @throws WxErrorException the wx error exception
185+ */
186+ @ Test
187+ public void testGetUserIdByEmail () throws WxErrorException {
188+ String result = this .wxCpService .getUserService ().getUserIdByEmail ("xxx" ,1 );
189+ System .out .println (result );
190+ assertNotNull (result );
191+ }
192+
181193 /**
182194 * Test get external contact.
183195 */
You can’t perform that action at this time.
0 commit comments