diff --git a/go_client/main.go b/go_client/main.go new file mode 100644 index 0000000..6859a43 --- /dev/null +++ b/go_client/main.go @@ -0,0 +1,11 @@ +package main + +import ( + "go_client/tcpserver" + "log" +) + +func main() { + log.SetFlags(log.LstdFlags | log.Lshortfile) + tcpserver.Listen(19099) +} diff --git a/go_client/tcpserver/tcpserver.go b/go_client/tcpserver/tcpserver.go new file mode 100644 index 0000000..edee43b --- /dev/null +++ b/go_client/tcpserver/tcpserver.go @@ -0,0 +1,44 @@ +package tcpserver + +import ( + "bufio" + "log" + "net" + "strconv" +) + +func Listen(port int) { + p := strconv.Itoa(port) + adress := "127.0.0.1:" + p + ln, err := net.Listen("tcp", adress) + if err != nil { + log.Fatal(err) + } + defer ln.Close() + log.Println("tcp server started") + for { + conn, err := ln.Accept() + if err != nil { + log.Println(err) + continue + } + go handle(conn) + } +} + +func handle(conn net.Conn) { + defer func() { + if err := recover(); err != nil { + log.Println("发生了未处理的异常", err) + } + }() + defer conn.Close() + scanner := bufio.NewScanner(conn) + for scanner.Scan() { + line := scanner.Bytes() + log.Println("收到消息:", string(line)) + } + if err := scanner.Err(); err != nil { + log.Println("错误:", err) + } +} diff --git a/java_client/pom.xml b/java_client/pom.xml index 3a98e6f..8dc9d58 100644 --- a/java_client/pom.xml +++ b/java_client/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.0 + 3.2.2 com.example @@ -14,7 +14,8 @@ wxhk wxhk - 17 + 21 + 4.5.3 @@ -39,7 +40,7 @@ io.netty netty-all - 4.1.92.Final + 4.1.105.Final com.squareup.okhttp3 @@ -50,22 +51,22 @@ io.vertx vertx-core - 4.4.2 + ${vertx-web-client.version} io.vertx vertx-web - 4.4.2 + ${vertx-web-client.version} io.vertx vertx-web-client - 4.4.2 + ${vertx-web-client.version} io.vertx vertx-mysql-client - 4.4.2 + ${vertx-web-client.version} org.springframework.boot diff --git a/java_client/src/main/java/com/example/wxhk/model/PrivateChatMsg.java b/java_client/src/main/java/com/example/wxhk/model/PrivateChatMsg.java index 25424b7..efbf324 100644 --- a/java_client/src/main/java/com/example/wxhk/model/PrivateChatMsg.java +++ b/java_client/src/main/java/com/example/wxhk/model/PrivateChatMsg.java @@ -42,6 +42,11 @@ public class PrivateChatMsg implements Serializable { private String signature; private String time; private Integer timestamp; + + /** + * 对用户,如果是文件助手是filehelper + */ + private String toUser; /** * 类型 */ diff --git a/java_client/src/main/java/com/example/wxhk/model/request/OpenHook.java b/java_client/src/main/java/com/example/wxhk/model/request/OpenHook.java index 12929d0..62513a2 100644 --- a/java_client/src/main/java/com/example/wxhk/model/request/OpenHook.java +++ b/java_client/src/main/java/com/example/wxhk/model/request/OpenHook.java @@ -15,4 +15,17 @@ import lombok.experimental.Accessors; public class OpenHook implements SendMsg { String port; String ip; + /** + * 0/1 :1.启用http 0.不启用http + */ + boolean enableHttp; + /** + * 超时时间,单位ms + */ + String timeout; + + /** + * http的请求地址,enableHttp=1时,不能为空 + */ + String url; } diff --git a/java_client/src/main/java/com/example/wxhk/msg/WxMsgHandle.java b/java_client/src/main/java/com/example/wxhk/msg/WxMsgHandle.java index dbfc8aa..f6cf126 100644 --- a/java_client/src/main/java/com/example/wxhk/msg/WxMsgHandle.java +++ b/java_client/src/main/java/com/example/wxhk/msg/WxMsgHandle.java @@ -18,6 +18,7 @@ import org.w3c.dom.NodeList; import java.math.BigDecimal; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -50,7 +51,12 @@ public class WxMsgHandle { @PostConstruct public void init() { add(chatMsg -> { - wxSmgServer.私聊(chatMsg); + if(Objects.equals(chatMsg.getToUser(), FILEHELPER)){ + wxSmgServer.文件助手(chatMsg); + }else{ + wxSmgServer.私聊(chatMsg); + } + return null; }, WxMsgType.私聊信息); add(chatMsg -> { @@ -174,8 +180,8 @@ public class WxMsgHandle { if (monery.startsWith("¥")) { String substring = monery.substring(1); BigDecimal decimal = new BigDecimal(substring); - log.info("收款:{},付款人:{},付款备注:{}", decimal.stripTrailingZeros().toPlainString(), chatMsg.getFromUser(), remark); - wxSmgServer.收款之后(new PayoutInformation(chatMsg.getFromUser(), decimal, remark)); + log.info("收款:{},付款人:{},付款备注:{}", decimal.stripTrailingZeros().toPlainString(), receiver_username, remark); + wxSmgServer.收款之后(new PayoutInformation(receiver_username, decimal, remark)); return false; }; diff --git a/java_client/src/main/java/com/example/wxhk/server/impl/WxSmgServerImpl.java b/java_client/src/main/java/com/example/wxhk/server/impl/WxSmgServerImpl.java index 3bfebd9..b1c7cc3 100644 --- a/java_client/src/main/java/com/example/wxhk/server/impl/WxSmgServerImpl.java +++ b/java_client/src/main/java/com/example/wxhk/server/impl/WxSmgServerImpl.java @@ -32,12 +32,14 @@ public class WxSmgServerImpl implements com.example.wxhk.server.WxSmgServer { public void 私聊(PrivateChatMsg chatMsg) { if (Objects.equals(chatMsg.getIsSendMsg(), 1) && Objects.equals(chatMsg.getIsSendByPhone(), 1)) { log.info("手机端对:{}发出:{}", chatMsg.getFromUser(), chatMsg.getContent()); + }else{ + log.info("收到私聊{}",chatMsg); } } @Override public void 文件助手(PrivateChatMsg chatMsg) { - + log.info("文件助手:{}",chatMsg); } @Override diff --git a/java_client/src/main/java/com/example/wxhk/tcp/vertx/VertxTcp.java b/java_client/src/main/java/com/example/wxhk/tcp/vertx/VertxTcp.java index 069f603..5ba952b 100644 --- a/java_client/src/main/java/com/example/wxhk/tcp/vertx/VertxTcp.java +++ b/java_client/src/main/java/com/example/wxhk/tcp/vertx/VertxTcp.java @@ -2,7 +2,8 @@ package com.example.wxhk.tcp.vertx; import com.example.wxhk.WxhkApplication; import com.example.wxhk.constant.WxMsgType; -import com.example.wxhk.util.HttpAsyncUtil; +import com.example.wxhk.model.request.OpenHook; +import com.example.wxhk.util.HttpSendUtil; import io.vertx.core.AbstractVerticle; import io.vertx.core.DeploymentOptions; import io.vertx.core.Future; @@ -75,7 +76,10 @@ public class VertxTcp extends AbstractVerticle implements CommandLineRunner { listen.onComplete(event -> { boolean succeeded = event.succeeded(); if (succeeded) { - HttpAsyncUtil.exec(HttpAsyncUtil.Type.开启hook, new JsonObject().put("port", InitWeChat.getVertxPort().toString()).put("ip", "127.0.0.1")); + HttpSendUtil.开启hook(new OpenHook().setPort(InitWeChat.getVertxPort().toString()).setIp("127.0.0.1") + .setEnableHttp(false) + .setTimeout("5000")); + // HttpAsyncUtil.exec(HttpAsyncUtil.Type.开启hook, new JsonObject().put("port", InitWeChat.getVertxPort().toString()).put("ip", "127.0.0.1")); startPromise.complete(); } else { startPromise.fail(event.cause()); diff --git a/java_client/src/main/java/com/example/wxhk/util/HttpAsyncUtil.java b/java_client/src/main/java/com/example/wxhk/util/HttpAsyncUtil.java index db408bf..0264a6a 100644 --- a/java_client/src/main/java/com/example/wxhk/util/HttpAsyncUtil.java +++ b/java_client/src/main/java/com/example/wxhk/util/HttpAsyncUtil.java @@ -24,7 +24,7 @@ public class HttpAsyncUtil { protected static final Log log = Log.get(); public static Future> exec(Type type, JsonObject object) { - return client.post(InitWeChat.wxPort, "localhost", "/api/?type=" + type.getType()) + return client.post(InitWeChat.wxPort, "localhost", "/api/" + type.getType()) .sendJsonObject(object) .onSuccess(event -> { @@ -36,7 +36,7 @@ public class HttpAsyncUtil { } public static Future> exec(Type type, JsonObject object, Handler>> handler) { - return client.post(InitWeChat.wxPort, "localhost", "/api/?type=" + type.getType()) + return client.post(InitWeChat.wxPort, "localhost", "/api/" + type.getType()) .sendJsonObject(object) .onComplete(handler) ; @@ -45,22 +45,31 @@ public class HttpAsyncUtil { } public enum Type { - 检查微信登陆("0"), - 获取登录信息("1"), - 发送文本("2"), - 发送at文本("3"), + 检查微信登陆("checkLogin"), + 获取登录信息("userInfo"), + 发送文本("sendTextMsg"), + 转发消息("forwardMsg"), + 发送at文本("sendAtText"), 发送图片("5"), - 发送文件("6"), - 开启hook("9"), - 关闭hook("10"), + 发送文件("sendFileMsg"), + 开启hook("hookSyncMsg"), + 关闭hook("unhookSyncMsg"), 添加好友("20"), 通过好友申请("23"), - 获取群成员("25"), - 获取群成员昵称("26"), - 删除群成员("27"), + 获取群成员("getMemberFromChatRoom"), + 获取群成员基础信息("getContactProfile"), + 获取群详情("getChatRoomDetailInfo"), + 添加群成员("addMemberToChatRoom"), + 修改群昵称("modifyNickname"), + 删除群成员("delMemberFromChatRoom"), + 置顶群消息("topMsg"), + 取消置顶群消息("removeTopMsg"), + 邀请入群("InviteMemberToChatRoom"), 确认收款("45"), - 联系人列表("46"), + 联系人列表("getContactList"), 查询微信信息("55"), + 下载附件("downloadAttach"), + 解码("decodeImage"), ; diff --git a/java_client/src/main/java/com/example/wxhk/util/HttpSyncUtil.java b/java_client/src/main/java/com/example/wxhk/util/HttpSyncUtil.java index 21686ac..c8e248e 100644 --- a/java_client/src/main/java/com/example/wxhk/util/HttpSyncUtil.java +++ b/java_client/src/main/java/com/example/wxhk/util/HttpSyncUtil.java @@ -27,7 +27,7 @@ public class HttpSyncUtil { } public static JsonObject exec(HttpAsyncUtil.Type type, JsonObject obj) { - String post = engine.send(Request.of("http://localhost:" + InitWeChat.wxPort + "/api/?type=" + type.getType()).method(Method.POST).body(obj.encode())).bodyStr(); + String post = engine.send(Request.of("http://localhost:" + InitWeChat.wxPort + "/api/" + type.getType()).method(Method.POST).body(obj.encode())).bodyStr(); if (log.isDebugEnabled()) { log.debug("type:{},{}", type.getType(), post); } diff --git a/java_client/src/main/resources/application.properties b/java_client/src/main/resources/application.properties index 199c37a..194f2f7 100644 --- a/java_client/src/main/resources/application.properties +++ b/java_client/src/main/resources/application.properties @@ -1,4 +1,4 @@ -wx.path=D:\\Program Files (x86)\\Tencent\\WeChat\\[3.9.2.23]\\WeChat.exe +wx.path=D:\\Program Files (x86)\\Tencent\\WeChat\\WeChat.exe wx.port=19088 spring.profiles.active=local vertx.port=8080 \ No newline at end of file diff --git a/java_client/src/main/resources/exec/c.exe b/java_client/src/main/resources/exec/c.exe index 68787d2..617f596 100644 Binary files a/java_client/src/main/resources/exec/c.exe and b/java_client/src/main/resources/exec/c.exe differ diff --git a/java_client/src/main/resources/exec/wxhelper.dll b/java_client/src/main/resources/exec/wxhelper.dll index 168a32b..c8f9251 100644 Binary files a/java_client/src/main/resources/exec/wxhelper.dll and b/java_client/src/main/resources/exec/wxhelper.dll differ 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 index 442acae..a9c7875 100644 --- a/java_client/src/test/java/com/example/wxhk/util/HttpSendUtilTest.java +++ b/java_client/src/test/java/com/example/wxhk/util/HttpSendUtilTest.java @@ -7,6 +7,8 @@ import org.dromara.hutool.core.lang.Console; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import java.time.Duration; +import java.time.LocalDateTime; import java.util.List; @SpringBootTest @@ -41,5 +43,7 @@ class HttpSendUtilTest { void 获取群成员() { GroupMembers 获取群成员 = HttpSendUtil.获取群成员(new GetGroupMembers().setChatRoomId("24964676359@chatroom")); Console.log(获取群成员); + + Duration between = Duration.between(LocalDateTime.now(), LocalDateTime.now()); } } \ No newline at end of file diff --git a/nodejs_client/tcp_server.js b/nodejs_client/tcp_server.js new file mode 100644 index 0000000..ccb4902 --- /dev/null +++ b/nodejs_client/tcp_server.js @@ -0,0 +1,26 @@ +const net = require('net') + +const server = net.createServer(socket => { + console.log('New client connected') + + let data = Buffer.from('') + + socket.on('data', data => { + data = Buffer.concat([data, chunk]) + console.log(`Received data: ${data}`) + }) + + socket.on('end', () => { + const decodedData = data.toString('utf8') + console.log(`Received data: ${decodedData}`) + }) + + socket.on('close', () => { + console.log('Client disconnected') + }) +}) + +const port = 19099 +server.listen(port, () => { + console.log(`Server listening on port ${port}`) +})