mirror of
https://github.com/ttttupup/wxhelper.git
synced 2024-11-05 18:09:24 +08:00
commit
ffa3ea49d9
11
go_client/main.go
Normal file
11
go_client/main.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go_client/tcpserver"
|
||||||
|
"log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
tcpserver.Listen(19099)
|
||||||
|
}
|
44
go_client/tcpserver/tcpserver.go
Normal file
44
go_client/tcpserver/tcpserver.go
Normal file
@ -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)
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.2</version>
|
||||||
<relativePath/> <!-- lookup parent from repository -->
|
<relativePath/> <!-- lookup parent from repository -->
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.example</groupId>
|
<groupId>com.example</groupId>
|
||||||
@ -14,7 +14,8 @@
|
|||||||
<name>wxhk</name>
|
<name>wxhk</name>
|
||||||
<description>wxhk</description>
|
<description>wxhk</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>17</java.version>
|
<java.version>21</java.version>
|
||||||
|
<vertx-web-client.version>4.5.3</vertx-web-client.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
@ -39,7 +40,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-all</artifactId>
|
<artifactId>netty-all</artifactId>
|
||||||
<version>4.1.92.Final</version>
|
<version>4.1.105.Final</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup.okhttp3</groupId>
|
<groupId>com.squareup.okhttp3</groupId>
|
||||||
@ -50,22 +51,22 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-core</artifactId>
|
<artifactId>vertx-core</artifactId>
|
||||||
<version>4.4.2</version>
|
<version>${vertx-web-client.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-web</artifactId>
|
<artifactId>vertx-web</artifactId>
|
||||||
<version>4.4.2</version>
|
<version>${vertx-web-client.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-web-client</artifactId>
|
<artifactId>vertx-web-client</artifactId>
|
||||||
<version>4.4.2</version>
|
<version>${vertx-web-client.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.vertx</groupId>
|
<groupId>io.vertx</groupId>
|
||||||
<artifactId>vertx-mysql-client</artifactId>
|
<artifactId>vertx-mysql-client</artifactId>
|
||||||
<version>4.4.2</version>
|
<version>${vertx-web-client.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -42,6 +42,11 @@ public class PrivateChatMsg implements Serializable {
|
|||||||
private String signature;
|
private String signature;
|
||||||
private String time;
|
private String time;
|
||||||
private Integer timestamp;
|
private Integer timestamp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对用户,如果是文件助手是filehelper
|
||||||
|
*/
|
||||||
|
private String toUser;
|
||||||
/**
|
/**
|
||||||
* 类型
|
* 类型
|
||||||
*/
|
*/
|
||||||
|
@ -15,4 +15,17 @@ import lombok.experimental.Accessors;
|
|||||||
public class OpenHook implements SendMsg<OpenHook> {
|
public class OpenHook implements SendMsg<OpenHook> {
|
||||||
String port;
|
String port;
|
||||||
String ip;
|
String ip;
|
||||||
|
/**
|
||||||
|
* 0/1 :1.启用http 0.不启用http
|
||||||
|
*/
|
||||||
|
boolean enableHttp;
|
||||||
|
/**
|
||||||
|
* 超时时间,单位ms
|
||||||
|
*/
|
||||||
|
String timeout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http的请求地址,enableHttp=1时,不能为空
|
||||||
|
*/
|
||||||
|
String url;
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import org.w3c.dom.NodeList;
|
|||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
@ -50,7 +51,12 @@ public class WxMsgHandle {
|
|||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
add(chatMsg -> {
|
add(chatMsg -> {
|
||||||
wxSmgServer.私聊(chatMsg);
|
if(Objects.equals(chatMsg.getToUser(), FILEHELPER)){
|
||||||
|
wxSmgServer.文件助手(chatMsg);
|
||||||
|
}else{
|
||||||
|
wxSmgServer.私聊(chatMsg);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}, WxMsgType.私聊信息);
|
}, WxMsgType.私聊信息);
|
||||||
add(chatMsg -> {
|
add(chatMsg -> {
|
||||||
@ -174,8 +180,8 @@ public class WxMsgHandle {
|
|||||||
if (monery.startsWith("¥")) {
|
if (monery.startsWith("¥")) {
|
||||||
String substring = monery.substring(1);
|
String substring = monery.substring(1);
|
||||||
BigDecimal decimal = new BigDecimal(substring);
|
BigDecimal decimal = new BigDecimal(substring);
|
||||||
log.info("收款:{},付款人:{},付款备注:{}", decimal.stripTrailingZeros().toPlainString(), chatMsg.getFromUser(), remark);
|
log.info("收款:{},付款人:{},付款备注:{}", decimal.stripTrailingZeros().toPlainString(), receiver_username, remark);
|
||||||
wxSmgServer.收款之后(new PayoutInformation(chatMsg.getFromUser(), decimal, remark));
|
wxSmgServer.收款之后(new PayoutInformation(receiver_username, decimal, remark));
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,12 +32,14 @@ public class WxSmgServerImpl implements com.example.wxhk.server.WxSmgServer {
|
|||||||
public void 私聊(PrivateChatMsg chatMsg) {
|
public void 私聊(PrivateChatMsg chatMsg) {
|
||||||
if (Objects.equals(chatMsg.getIsSendMsg(), 1) && Objects.equals(chatMsg.getIsSendByPhone(), 1)) {
|
if (Objects.equals(chatMsg.getIsSendMsg(), 1) && Objects.equals(chatMsg.getIsSendByPhone(), 1)) {
|
||||||
log.info("手机端对:{}发出:{}", chatMsg.getFromUser(), chatMsg.getContent());
|
log.info("手机端对:{}发出:{}", chatMsg.getFromUser(), chatMsg.getContent());
|
||||||
|
}else{
|
||||||
|
log.info("收到私聊{}",chatMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void 文件助手(PrivateChatMsg chatMsg) {
|
public void 文件助手(PrivateChatMsg chatMsg) {
|
||||||
|
log.info("文件助手:{}",chatMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -2,7 +2,8 @@ package com.example.wxhk.tcp.vertx;
|
|||||||
|
|
||||||
import com.example.wxhk.WxhkApplication;
|
import com.example.wxhk.WxhkApplication;
|
||||||
import com.example.wxhk.constant.WxMsgType;
|
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.AbstractVerticle;
|
||||||
import io.vertx.core.DeploymentOptions;
|
import io.vertx.core.DeploymentOptions;
|
||||||
import io.vertx.core.Future;
|
import io.vertx.core.Future;
|
||||||
@ -75,7 +76,10 @@ public class VertxTcp extends AbstractVerticle implements CommandLineRunner {
|
|||||||
listen.onComplete(event -> {
|
listen.onComplete(event -> {
|
||||||
boolean succeeded = event.succeeded();
|
boolean succeeded = event.succeeded();
|
||||||
if (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();
|
startPromise.complete();
|
||||||
} else {
|
} else {
|
||||||
startPromise.fail(event.cause());
|
startPromise.fail(event.cause());
|
||||||
|
@ -24,7 +24,7 @@ public class HttpAsyncUtil {
|
|||||||
protected static final Log log = Log.get();
|
protected static final Log log = Log.get();
|
||||||
|
|
||||||
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object) {
|
public static Future<HttpResponse<Buffer>> 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)
|
.sendJsonObject(object)
|
||||||
.onSuccess(event ->
|
.onSuccess(event ->
|
||||||
{
|
{
|
||||||
@ -36,7 +36,7 @@ public class HttpAsyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object, Handler<AsyncResult<HttpResponse<Buffer>>> handler) {
|
public static Future<HttpResponse<Buffer>> exec(Type type, JsonObject object, Handler<AsyncResult<HttpResponse<Buffer>>> handler) {
|
||||||
return client.post(InitWeChat.wxPort, "localhost", "/api/?type=" + type.getType())
|
return client.post(InitWeChat.wxPort, "localhost", "/api/" + type.getType())
|
||||||
.sendJsonObject(object)
|
.sendJsonObject(object)
|
||||||
.onComplete(handler)
|
.onComplete(handler)
|
||||||
;
|
;
|
||||||
@ -45,22 +45,31 @@ public class HttpAsyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum Type {
|
public enum Type {
|
||||||
检查微信登陆("0"),
|
检查微信登陆("checkLogin"),
|
||||||
获取登录信息("1"),
|
获取登录信息("userInfo"),
|
||||||
发送文本("2"),
|
发送文本("sendTextMsg"),
|
||||||
发送at文本("3"),
|
转发消息("forwardMsg"),
|
||||||
|
发送at文本("sendAtText"),
|
||||||
发送图片("5"),
|
发送图片("5"),
|
||||||
发送文件("6"),
|
发送文件("sendFileMsg"),
|
||||||
开启hook("9"),
|
开启hook("hookSyncMsg"),
|
||||||
关闭hook("10"),
|
关闭hook("unhookSyncMsg"),
|
||||||
添加好友("20"),
|
添加好友("20"),
|
||||||
通过好友申请("23"),
|
通过好友申请("23"),
|
||||||
获取群成员("25"),
|
获取群成员("getMemberFromChatRoom"),
|
||||||
获取群成员昵称("26"),
|
获取群成员基础信息("getContactProfile"),
|
||||||
删除群成员("27"),
|
获取群详情("getChatRoomDetailInfo"),
|
||||||
|
添加群成员("addMemberToChatRoom"),
|
||||||
|
修改群昵称("modifyNickname"),
|
||||||
|
删除群成员("delMemberFromChatRoom"),
|
||||||
|
置顶群消息("topMsg"),
|
||||||
|
取消置顶群消息("removeTopMsg"),
|
||||||
|
邀请入群("InviteMemberToChatRoom"),
|
||||||
确认收款("45"),
|
确认收款("45"),
|
||||||
联系人列表("46"),
|
联系人列表("getContactList"),
|
||||||
查询微信信息("55"),
|
查询微信信息("55"),
|
||||||
|
下载附件("downloadAttach"),
|
||||||
|
解码("decodeImage"),
|
||||||
|
|
||||||
|
|
||||||
;
|
;
|
||||||
|
@ -27,7 +27,7 @@ public class HttpSyncUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject exec(HttpAsyncUtil.Type type, JsonObject obj) {
|
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()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("type:{},{}", type.getType(), post);
|
log.debug("type:{},{}", type.getType(), post);
|
||||||
}
|
}
|
||||||
|
@ -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
|
wx.port=19088
|
||||||
spring.profiles.active=local
|
spring.profiles.active=local
|
||||||
vertx.port=8080
|
vertx.port=8080
|
Binary file not shown.
Binary file not shown.
@ -7,6 +7,8 @@ import org.dromara.hutool.core.lang.Console;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ -41,5 +43,7 @@ class HttpSendUtilTest {
|
|||||||
void 获取群成员() {
|
void 获取群成员() {
|
||||||
GroupMembers 获取群成员 = HttpSendUtil.获取群成员(new GetGroupMembers().setChatRoomId("24964676359@chatroom"));
|
GroupMembers 获取群成员 = HttpSendUtil.获取群成员(new GetGroupMembers().setChatRoomId("24964676359@chatroom"));
|
||||||
Console.log(获取群成员);
|
Console.log(获取群成员);
|
||||||
|
|
||||||
|
Duration between = Duration.between(LocalDateTime.now(), LocalDateTime.now());
|
||||||
}
|
}
|
||||||
}
|
}
|
26
nodejs_client/tcp_server.js
Normal file
26
nodejs_client/tcp_server.js
Normal file
@ -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}`)
|
||||||
|
})
|
Loading…
Reference in New Issue
Block a user