Skip to content

Commit b91c0ee

Browse files
authored
Merge pull request #26 from dui7/master
feat:批量获取联系人详情
2 parents 007b7b2 + cf1f091 commit b91c0ee

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.meteor.wechatbc.entitiy.contact;
2+
3+
import com.alibaba.fastjson.annotation.JSONField;
4+
import lombok.Data;
5+
import lombok.ToString;
6+
7+
@Data
8+
@ToString
9+
public class GetBatchContact {
10+
11+
@JSONField(name="UserName")
12+
private String userName;
13+
14+
@JSONField(name="EncryChatRoomId")
15+
private String encryChatRoomId;
16+
17+
}

src/main/java/com/meteor/wechatbc/impl/HttpAPI.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package com.meteor.wechatbc.impl;
22

33
import com.alibaba.fastjson2.JSONObject;
4+
import com.meteor.wechatbc.entitiy.contact.GetBatchContact;
45
import com.meteor.wechatbc.entitiy.message.SentMessage;
56
import com.meteor.wechatbc.entitiy.synccheck.SyncCheckResponse;
67

78
import java.io.File;
9+
import java.util.List;
810

911
public interface HttpAPI {
1012

@@ -33,6 +35,14 @@ public interface HttpAPI {
3335
*/
3436
JSONObject getContact();
3537

38+
/**
39+
* 批量获取联系人详情,人或群均可。获取群详情主要是获取群内联系人列表。获取人详情主要是获取群内的某个人的详细信息
40+
*
41+
* @param queryContactList
42+
* @return
43+
*/
44+
JSONObject batchGetContactDetail(List<GetBatchContact> queryContactList);
45+
3646
/**
3747
* 发送消息
3848
*/

src/main/java/com/meteor/wechatbc/impl/HttpAPIImpl.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.alibaba.fastjson2.JSONReader;
66
import com.meteor.wechatbc.entitiy.SendMessage;
77
import com.meteor.wechatbc.entitiy.contact.Contact;
8+
import com.meteor.wechatbc.entitiy.contact.GetBatchContact;
89
import com.meteor.wechatbc.entitiy.message.SentMessage;
910
import com.meteor.wechatbc.entitiy.session.BaseRequest;
1011
import com.meteor.wechatbc.entitiy.synccheck.SyncCheckResponse;
@@ -26,6 +27,8 @@
2627
import java.io.ByteArrayInputStream;
2728
import java.io.File;
2829
import java.io.IOException;
30+
import java.util.ArrayList;
31+
import java.util.List;
2932
import java.util.concurrent.TimeUnit;
3033

3134
/**
@@ -168,6 +171,39 @@ public JSONObject getContact() {
168171
}
169172

170173

174+
@Override
175+
public JSONObject batchGetContactDetail(List<GetBatchContact> queryContactList) {
176+
if (queryContactList == null || queryContactList.isEmpty()) {
177+
queryContactList = new ArrayList<>();
178+
}
179+
180+
Integer count = queryContactList.size();
181+
Session session = weChatClient.getWeChatCore().getSession();
182+
BaseRequest baseRequest = session.getBaseRequest();
183+
HttpUrl httpUrl = URL.BASE_URL.newBuilder()
184+
.encodedPath(URL.BATCH_GET_CONTACT)
185+
.addQueryParameter("skey", baseRequest.getSkey())
186+
.addQueryParameter("pass_ticket", baseRequest.getPassTicket())
187+
.addQueryParameter("rr", String.valueOf(System.currentTimeMillis()))
188+
.addQueryParameter("type", "ex")
189+
.build();
190+
191+
JSONObject jsonObject = new JSONObject();
192+
jsonObject.put("Count", count);
193+
jsonObject.put("List", queryContactList);
194+
Request request = BASE_REQUEST.newBuilder().url(httpUrl)
195+
.post(RequestBody.create(mediaType, jsonObject.toString()))
196+
.build();
197+
try (
198+
Response response = okHttpClient.newCall(request).execute();
199+
) {
200+
String body = response.body().string();
201+
return JSON.parseObject(body);
202+
} catch (IOException e) {
203+
throw new RuntimeException(e);
204+
}
205+
}
206+
171207
@Override
172208
public SentMessage sendMessage(String toUserName, String content) {
173209
Session session = weChatClient.getWeChatCore().getSession();

src/main/java/com/meteor/wechatbc/util/URL.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class URL {
2424

2525
public final static String SEND_MESSAGE = "/cgi-bin/mmwebwx-bin/webwxsendmsg";
2626
public final static String GET_CONTACT = "/cgi-bin/mmwebwx-bin/webwxgetcontact";
27+
public final static String BATCH_GET_CONTACT = "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact";
2728

2829
public final static String LOGINJS = "https://login.wx.qq.com/jslogin";
2930
public final static String NEWLOGINPAGE = "https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage";

0 commit comments

Comments
 (0)