File tree Expand file tree Collapse file tree 4 files changed +40
-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 +40
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,23 @@ public interface WxCpUserService {
137
137
*/
138
138
String openid2UserId (String openid ) throws WxErrorException ;
139
139
140
+ /**
141
+ * <pre>
142
+ *
143
+ * 通过手机号获取其所对应的userid。
144
+ *
145
+ * 请求方式:POST(HTTPS)
146
+ * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserid?access_token=ACCESS_TOKEN
147
+ *
148
+ * 文档地址:https://work.weixin.qq.com/api/doc#90001/90143/91693
149
+ * </pre>
150
+ *
151
+ * @param mobile 手机号码。长度为5~32个字节
152
+ * @return userid mobile对应的成员userid
153
+ * @throws WxErrorException .
154
+ */
155
+ String getUserId (String mobile ) throws WxErrorException ;
156
+
140
157
/**
141
158
* 获取外部联系人详情.
142
159
* <pre>
@@ -147,6 +164,8 @@ public interface WxCpUserService {
147
164
* </pre>
148
165
*
149
166
* @param userId 外部联系人的userid
167
+ * @return 联系人详情
168
+ * @throws WxErrorException .
150
169
*/
151
170
WxCpUserExternalContactInfo getExternalContact (String userId ) throws WxErrorException ;
152
171
Original file line number Diff line number Diff line change @@ -180,6 +180,16 @@ public String openid2UserId(String openid) throws WxErrorException {
180
180
return tmpJsonElement .getAsJsonObject ().get ("userid" ).getAsString ();
181
181
}
182
182
183
+ @ Override
184
+ public String getUserId (String mobile ) throws WxErrorException {
185
+ JsonObject jsonObject = new JsonObject ();
186
+ jsonObject .addProperty ("mobile" , mobile );
187
+ String url = this .mainService .getWxCpConfigStorage ().getApiUrl (GET_USER_ID );
188
+ String responseContent = this .mainService .post (url , jsonObject .toString ());
189
+ JsonElement tmpJsonElement = new JsonParser ().parse (responseContent );
190
+ return tmpJsonElement .getAsJsonObject ().get ("userid" ).getAsString ();
191
+ }
192
+
183
193
@ Override
184
194
public WxCpUserExternalContactInfo getExternalContact (String userId ) throws WxErrorException {
185
195
String url = this .mainService .getWxCpConfigStorage ().getApiUrl (GET_EXTERNAL_CONTACT + userId );
Original file line number Diff line number Diff line change @@ -101,6 +101,7 @@ public static class User {
101
101
public static final String BATCH_INVITE = "/cgi-bin/batch/invite" ;
102
102
public static final String USER_CONVERT_TO_OPENID = "/cgi-bin/user/convert_to_openid" ;
103
103
public static final String USER_CONVERT_TO_USERID = "/cgi-bin/user/convert_to_userid" ;
104
+ public static final String GET_USER_ID = "/cgi-bin/user/getuserid" ;
104
105
public static final String GET_EXTERNAL_CONTACT = "/cgi-bin/crm/get_external_contact?external_userid=" ;
105
106
}
106
107
Original file line number Diff line number Diff line change @@ -112,4 +112,14 @@ public void testOpenid2UserId() throws Exception {
112
112
}
113
113
114
114
115
+ @ Test
116
+ public void testGetUserId () throws WxErrorException {
117
+ String result = this .wxCpService .getUserService ().getUserId ("xxx" );
118
+ System .out .println (result );
119
+ assertNotNull (result );
120
+ }
121
+
122
+ @ Test
123
+ public void testGetExternalContact () {
124
+ }
115
125
}
You can’t perform that action at this time.
0 commit comments