From e0588792956cc4595266b6cc7092e2c1fc635e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=B6=9B?= <2450572350@qq.com> Date: Thu, 1 Jun 2023 11:13:49 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=A4=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/example/wxhk/infe/Resp.java | 11 ++++ .../java/com/example/wxhk/infe/SendMsg.java | 3 -- .../wxhk/model/response/ContactList.java | 50 +++++++++++++++++++ .../wxhk/model/response/GroupMembers.java | 37 ++++++++++++++ .../com/example/wxhk/util/HttpSendUtil.java | 18 +++++-- .../example/wxhk/tcp/HttpAsyncUtilTest.java | 1 - .../example/wxhk/util/HttpSendUtilTest.java | 41 +++++++++++++++ 7 files changed, 154 insertions(+), 7 deletions(-) create mode 100644 java_client/src/main/java/com/example/wxhk/infe/Resp.java create mode 100644 java_client/src/main/java/com/example/wxhk/model/response/ContactList.java create mode 100644 java_client/src/main/java/com/example/wxhk/model/response/GroupMembers.java create mode 100644 java_client/src/test/java/com/example/wxhk/util/HttpSendUtilTest.java diff --git a/java_client/src/main/java/com/example/wxhk/infe/Resp.java b/java_client/src/main/java/com/example/wxhk/infe/Resp.java new file mode 100644 index 0000000..1c3fd04 --- /dev/null +++ b/java_client/src/main/java/com/example/wxhk/infe/Resp.java @@ -0,0 +1,11 @@ +package com.example.wxhk.infe; + +/** + * http 响应 + * @author wt + * @date 2023/06/01 + */ +public interface Resp extends java.io.Serializable{ + + +} diff --git a/java_client/src/main/java/com/example/wxhk/infe/SendMsg.java b/java_client/src/main/java/com/example/wxhk/infe/SendMsg.java index 8de6496..4050bd6 100644 --- a/java_client/src/main/java/com/example/wxhk/infe/SendMsg.java +++ b/java_client/src/main/java/com/example/wxhk/infe/SendMsg.java @@ -8,13 +8,10 @@ import io.vertx.core.json.JsonObject; * @author wt * @date 2023/06/01 */ -@FunctionalInterface public interface SendMsg extends java.io.Serializable{ default JsonObject toJson(){ return JsonObject.mapFrom(this); } - - T of(); } diff --git a/java_client/src/main/java/com/example/wxhk/model/response/ContactList.java b/java_client/src/main/java/com/example/wxhk/model/response/ContactList.java new file mode 100644 index 0000000..fcd1770 --- /dev/null +++ b/java_client/src/main/java/com/example/wxhk/model/response/ContactList.java @@ -0,0 +1,50 @@ +package com.example.wxhk.model.response; + +import com.example.wxhk.infe.Resp; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.util.List; + +/** + * 联系人列表 + * @author wt + * @date 2023/06/01 + */ +@Data +@Accessors(chain = true) +@JsonIgnoreProperties(ignoreUnknown = true) +public class ContactList implements Resp { + + /** + * code : 1 + * data : [{"customAccount":"","delFlag":0,"type":1,"userName":"朋友推荐消息","verifyFlag":0,"wxid":"fmessage"},{"customAccount":"tencent_cloud","delFlag":0,"type":3,"userName":"腾讯云助手","verifyFlag":24,"wxid":"gh_a73e2407e0f8"},{"customAccount":"","delFlag":0,"type":1,"userName":"语音记事本","verifyFlag":0,"wxid":"medianote"},{"customAccount":"","delFlag":0,"type":1,"userName":"漂流瓶","verifyFlag":0,"wxid":"floatbottle"},{"customAccount":"jys-wt","delFlag":0,"type":8651011,"userName":"时光似水戏流年","verifyFlag":0,"wxid":"wxid_gf1fogt5a0pq22"},{"customAccount":"wxzhifu","delFlag":0,"type":3,"userName":"微信支付","verifyFlag":24,"wxid":"gh_3dfda90e39d6"},{"customAccount":"dhkzfr","delFlag":0,"type":3,"userName":"阿芙(代发)","verifyFlag":0,"wxid":"wxid_kh16lri40gzj22"},{"customAccount":"","delFlag":0,"type":3,"userName":"文件传输助手","verifyFlag":0,"wxid":"filehelper"},{"customAccount":"","delFlag":0,"type":3,"userName":"fff","verifyFlag":0,"wxid":"24964676359@chatroom"},{"customAccount":"","delFlag":0,"type":2,"userName":"最美阿芙","verifyFlag":0,"wxid":"23793178249@chatroom"},{"customAccount":"afu943344","delFlag":0,"type":2,"userName":"A-阿芙4号-LOL永劫云顶出租-代发","verifyFlag":0,"wxid":"wxid_1gxthknqbmwv22"},{"customAccount":"","delFlag":0,"type":3,"userName":"微信收款助手","verifyFlag":24,"wxid":"gh_f0a92aa7146c"},{"customAccount":"","delFlag":0,"type":0,"userName":"","verifyFlag":0,"wxid":"25984984710827869@openim"}] + * result : OK + */ + + private Integer code; + private String result; + private List data; + + @Data + @Accessors(chain = true) + public static class DataBean implements Serializable { + /** + * customAccount : + * delFlag : 0 + * type : 1 + * userName : 朋友推荐消息 + * verifyFlag : 0 + * wxid : fmessage + */ + + private String customAccount; + private Integer delFlag; + private Integer type; + private String userName; + private Integer verifyFlag; + private String wxid; + } +} diff --git a/java_client/src/main/java/com/example/wxhk/model/response/GroupMembers.java b/java_client/src/main/java/com/example/wxhk/model/response/GroupMembers.java new file mode 100644 index 0000000..f13cf09 --- /dev/null +++ b/java_client/src/main/java/com/example/wxhk/model/response/GroupMembers.java @@ -0,0 +1,37 @@ +package com.example.wxhk.model.response; + +import com.example.wxhk.infe.Resp; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +@Data +@Accessors(chain = true) +@JsonIgnoreProperties(ignoreUnknown = true) +public class GroupMembers implements Resp { + + /** + * code : 1 + * data : {"admin":"wxid_gf1fogt5a0pq22","chatRoomId":"24964676359@chatroom","members":"wxid_gf1fogt5a0pq22^Gwxid_4yr8erik0uho22"} + * result : OK + */ + + private Integer code; + private DataBean data; + private String result; + + @Data + public static class DataBean implements Serializable { + /** + * admin : wxid_gf1fogt5a0pq22 + * chatRoomId : 24964676359@chatroom + * members : wxid_gf1fogt5a0pq22^Gwxid_4yr8erik0uho22 + */ + + private String admin; + private String chatRoomId; + private String members; + } +} diff --git a/java_client/src/main/java/com/example/wxhk/util/HttpSendUtil.java b/java_client/src/main/java/com/example/wxhk/util/HttpSendUtil.java index a599c60..d1eb918 100644 --- a/java_client/src/main/java/com/example/wxhk/util/HttpSendUtil.java +++ b/java_client/src/main/java/com/example/wxhk/util/HttpSendUtil.java @@ -2,6 +2,8 @@ package com.example.wxhk.util; import com.example.wxhk.model.PrivateChatMsg; import com.example.wxhk.model.request.*; +import com.example.wxhk.model.response.ContactList; +import com.example.wxhk.model.response.GroupMembers; import com.example.wxhk.tcp.vertx.ArrHandle; import com.example.wxhk.tcp.vertx.InitWeChat; import io.vertx.core.json.JsonObject; @@ -96,14 +98,24 @@ public class HttpSendUtil { return exec.getJsonObject("data").getString("wxid"); } - public static JsonObject 联系人列表(){ + public static ContactList 联系人列表(){ JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.联系人列表, new JsonObject()); - return exec.getJsonObject("data"); + return exec.mapTo(ContactList.class); } public static JsonObject 开启hook(OpenHook hook){ JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.开启hook,hook.toJson()); - return exec.getJsonObject("data"); + return exec; } + public static JsonObject 关闭hook(){ + JsonObject exec = HttpSyncUtil.exec(HttpAsyncUtil.Type.关闭hook,new JsonObject()); + return exec; + } + + public static GroupMembers 获取群成员(GetGroupMembers p){ + return HttpSyncUtil.exec(HttpAsyncUtil.Type.获取群成员, p.toJson()).mapTo(GroupMembers.class); + + } + @Deprecated public static com.example.wxhk.infe.SendMsg of(HttpAsyncUtil.Type type) { diff --git a/java_client/src/test/java/com/example/wxhk/tcp/HttpAsyncUtilTest.java b/java_client/src/test/java/com/example/wxhk/tcp/HttpAsyncUtilTest.java index a1c5f5e..23d1ba4 100644 --- a/java_client/src/test/java/com/example/wxhk/tcp/HttpAsyncUtilTest.java +++ b/java_client/src/test/java/com/example/wxhk/tcp/HttpAsyncUtilTest.java @@ -44,6 +44,5 @@ class HttpAsyncUtilTest { @Test void exec2() { - } } \ No newline at end of file diff --git a/java_client/src/test/java/com/example/wxhk/util/HttpSendUtilTest.java b/java_client/src/test/java/com/example/wxhk/util/HttpSendUtilTest.java new file mode 100644 index 0000000..1b384e0 --- /dev/null +++ b/java_client/src/test/java/com/example/wxhk/util/HttpSendUtilTest.java @@ -0,0 +1,41 @@ +package com.example.wxhk.util; + +import com.example.wxhk.model.request.GetGroupMembers; +import com.example.wxhk.model.response.ContactList; +import com.example.wxhk.model.response.GroupMembers; +import org.dromara.hutool.core.lang.Console; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +import java.util.List; + +@SpringBootTest +class HttpSendUtilTest { + + + @Test + void 获取当前登陆微信id() { + String s = HttpSendUtil.获取当前登陆微信id(); + } + + @Test + void 联系人列表() { + ContactList contactList = HttpSendUtil.联系人列表(); + + List data = contactList.getData(); + for (ContactList.DataBean datum : data) { + Console.log(datum.getWxid(),datum.getUserName()); + } + Console.log(contactList); + } + @Test + void 开启hook() { + + } + + @Test + void 获取群成员() { + GroupMembers 获取群成员 = HttpSendUtil.获取群成员(new GetGroupMembers().setChatRoomId("24964676359@chatroom")); + Console.log(获取群成员); + } +} \ No newline at end of file