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 {
174
174
*/
175
175
String getUserId (String mobile ) throws WxErrorException ;
176
176
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
+
177
194
/**
178
195
* 获取外部联系人详情.
179
196
* <pre>
Original file line number Diff line number Diff line change @@ -203,6 +203,17 @@ public String getUserId(String mobile) throws WxErrorException {
203
203
return tmpJson .get ("userid" ).getAsString ();
204
204
}
205
205
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
+
206
217
@ Override
207
218
public WxCpExternalContactInfo getExternalContact (String userId ) throws WxErrorException {
208
219
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 {
965
965
* The constant GET_USER_ID.
966
966
*/
967
967
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" ;
968
972
/**
969
973
* The constant GET_EXTERNAL_CONTACT.
970
974
*/
Original file line number Diff line number Diff line change @@ -178,6 +178,18 @@ public void testGetUserId() throws WxErrorException {
178
178
assertNotNull (result );
179
179
}
180
180
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
+
181
193
/**
182
194
* Test get external contact.
183
195
*/
You can’t perform that action at this time.
0 commit comments