From cf1f091abf12ba2413e5cca6320984c7d675d159 Mon Sep 17 00:00:00 2001 From: keliang Date: Thu, 7 Mar 2024 23:07:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=89=B9=E9=87=8F=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E8=81=94=E7=B3=BB=E4=BA=BA=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entitiy/contact/GetBatchContact.java | 17 +++++++++ .../com/meteor/wechatbc/impl/HttpAPI.java | 10 ++++++ .../com/meteor/wechatbc/impl/HttpAPIImpl.java | 36 +++++++++++++++++++ .../java/com/meteor/wechatbc/util/URL.java | 1 + 4 files changed, 64 insertions(+) create mode 100644 src/main/java/com/meteor/wechatbc/entitiy/contact/GetBatchContact.java diff --git a/src/main/java/com/meteor/wechatbc/entitiy/contact/GetBatchContact.java b/src/main/java/com/meteor/wechatbc/entitiy/contact/GetBatchContact.java new file mode 100644 index 0000000..e507bba --- /dev/null +++ b/src/main/java/com/meteor/wechatbc/entitiy/contact/GetBatchContact.java @@ -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; + +} diff --git a/src/main/java/com/meteor/wechatbc/impl/HttpAPI.java b/src/main/java/com/meteor/wechatbc/impl/HttpAPI.java index f7e085c..18047c2 100644 --- a/src/main/java/com/meteor/wechatbc/impl/HttpAPI.java +++ b/src/main/java/com/meteor/wechatbc/impl/HttpAPI.java @@ -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 { @@ -33,6 +35,14 @@ public interface HttpAPI { */ JSONObject getContact(); + /** + * 批量获取联系人详情,人或群均可。获取群详情主要是获取群内联系人列表。获取人详情主要是获取群内的某个人的详细信息 + * + * @param queryContactList + * @return + */ + JSONObject batchGetContactDetail(List queryContactList); + /** * 发送消息 */ diff --git a/src/main/java/com/meteor/wechatbc/impl/HttpAPIImpl.java b/src/main/java/com/meteor/wechatbc/impl/HttpAPIImpl.java index e2ff976..a8330bc 100644 --- a/src/main/java/com/meteor/wechatbc/impl/HttpAPIImpl.java +++ b/src/main/java/com/meteor/wechatbc/impl/HttpAPIImpl.java @@ -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; @@ -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; /** @@ -168,6 +171,39 @@ public JSONObject getContact() { } + @Override + public JSONObject batchGetContactDetail(List 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(); diff --git a/src/main/java/com/meteor/wechatbc/util/URL.java b/src/main/java/com/meteor/wechatbc/util/URL.java index 35cc7e1..2fc95a2 100644 --- a/src/main/java/com/meteor/wechatbc/util/URL.java +++ b/src/main/java/com/meteor/wechatbc/util/URL.java @@ -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";