Skip to content

Commit

Permalink
Merge pull request #26 from dui7/master
Browse files Browse the repository at this point in the history
feat:批量获取联系人详情
  • Loading branch information
meteorOSS authored Mar 7, 2024
2 parents 007b7b2 + cf1f091 commit b91c0ee
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.meteor.wechatbc.entitiy.contact;

import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class GetBatchContact {

@JSONField(name="UserName")
private String userName;

@JSONField(name="EncryChatRoomId")
private String encryChatRoomId;

}
10 changes: 10 additions & 0 deletions src/main/java/com/meteor/wechatbc/impl/HttpAPI.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.meteor.wechatbc.impl;

import com.alibaba.fastjson2.JSONObject;
import com.meteor.wechatbc.entitiy.contact.GetBatchContact;
import com.meteor.wechatbc.entitiy.message.SentMessage;
import com.meteor.wechatbc.entitiy.synccheck.SyncCheckResponse;

import java.io.File;
import java.util.List;

public interface HttpAPI {

Expand Down Expand Up @@ -33,6 +35,14 @@ public interface HttpAPI {
*/
JSONObject getContact();

/**
* 批量获取联系人详情,人或群均可。获取群详情主要是获取群内联系人列表。获取人详情主要是获取群内的某个人的详细信息
*
* @param queryContactList
* @return
*/
JSONObject batchGetContactDetail(List<GetBatchContact> queryContactList);

/**
* 发送消息
*/
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/com/meteor/wechatbc/impl/HttpAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.alibaba.fastjson2.JSONReader;
import com.meteor.wechatbc.entitiy.SendMessage;
import com.meteor.wechatbc.entitiy.contact.Contact;
import com.meteor.wechatbc.entitiy.contact.GetBatchContact;
import com.meteor.wechatbc.entitiy.message.SentMessage;
import com.meteor.wechatbc.entitiy.session.BaseRequest;
import com.meteor.wechatbc.entitiy.synccheck.SyncCheckResponse;
Expand All @@ -26,6 +27,8 @@
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
Expand Down Expand Up @@ -168,6 +171,39 @@ public JSONObject getContact() {
}


@Override
public JSONObject batchGetContactDetail(List<GetBatchContact> queryContactList) {
if (queryContactList == null || queryContactList.isEmpty()) {
queryContactList = new ArrayList<>();
}

Integer count = queryContactList.size();
Session session = weChatClient.getWeChatCore().getSession();
BaseRequest baseRequest = session.getBaseRequest();
HttpUrl httpUrl = URL.BASE_URL.newBuilder()
.encodedPath(URL.BATCH_GET_CONTACT)
.addQueryParameter("skey", baseRequest.getSkey())
.addQueryParameter("pass_ticket", baseRequest.getPassTicket())
.addQueryParameter("rr", String.valueOf(System.currentTimeMillis()))
.addQueryParameter("type", "ex")
.build();

JSONObject jsonObject = new JSONObject();
jsonObject.put("Count", count);
jsonObject.put("List", queryContactList);
Request request = BASE_REQUEST.newBuilder().url(httpUrl)
.post(RequestBody.create(mediaType, jsonObject.toString()))
.build();
try (
Response response = okHttpClient.newCall(request).execute();
) {
String body = response.body().string();
return JSON.parseObject(body);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

@Override
public SentMessage sendMessage(String toUserName, String content) {
Session session = weChatClient.getWeChatCore().getSession();
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/meteor/wechatbc/util/URL.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class URL {

public final static String SEND_MESSAGE = "/cgi-bin/mmwebwx-bin/webwxsendmsg";
public final static String GET_CONTACT = "/cgi-bin/mmwebwx-bin/webwxgetcontact";
public final static String BATCH_GET_CONTACT = "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact";

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

0 comments on commit b91c0ee

Please sign in to comment.