feat: [java]-[mvn]-代码注释补充

This commit is contained in:
chandler 2025-03-12 18:12:39 +08:00
parent 295b83729e
commit 91a4126e88
3 changed files with 33 additions and 31 deletions

View File

@ -88,6 +88,7 @@
<artifactId>protobuf-java</artifactId> <artifactId>protobuf-java</artifactId>
<version>3.22.2</version> <version>3.22.2</version>
</dependency> </dependency>
<!-- JNA主要用于在 Java 程序中方便地调用本地Native代码如 C/C++ 的动态链接库DLL或共享库SO -->
<dependency> <dependency>
<groupId>net.java.dev.jna</groupId> <groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId> <artifactId>jna</artifactId>

View File

@ -75,6 +75,7 @@ public class WeChatSocketClient {
private BlockingQueue<WxMsg> msgQ; private BlockingQueue<WxMsg> msgQ;
private final String host; private final String host;
private final Integer port; private final Integer port;
public WeChatSocketClient(Integer port, String dllPath) { public WeChatSocketClient(Integer port, String dllPath) {
@ -120,7 +121,7 @@ public class WeChatSocketClient {
public Response sendCmd(Request req) { public Response sendCmd(Request req) {
try { try {
// 设置超时时间 20s // 设置发送 20 秒超时
cmdSocket.setSendTimeout(20000); cmdSocket.setSendTimeout(20000);
ByteBuffer bb = ByteBuffer.wrap(req.toByteArray()); ByteBuffer bb = ByteBuffer.wrap(req.toByteArray());
cmdSocket.send(bb); cmdSocket.send(bb);
@ -138,6 +139,33 @@ public class WeChatSocketClient {
} }
} }
private void listenMsg(String url) {
try {
msgSocket = new Pair1Socket();
msgSocket.dial(url);
// 设置接收 5 秒超时
msgSocket.setReceiveTimeout(5000);
} catch (Exception e) {
log.error("创建消息 RPC 失败", e);
return;
}
ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
while (isReceivingMsg) {
try {
long size = msgSocket.receive(bb, true);
WxMsg wxMsg = Response.parseFrom(Arrays.copyOfRange(bb.array(), 0, (int)size)).getWxmsg();
msgQ.put(wxMsg);
} catch (Exception e) {
// 多半是超时忽略吧
}
}
try {
msgSocket.close();
} catch (Exception e) {
log.error("关闭连接失败", e);
}
}
/** /**
* 当前微信客户端是否登录微信号 * 当前微信客户端是否登录微信号
* *
@ -217,33 +245,6 @@ public class WeChatSocketClient {
return false; return false;
} }
private void listenMsg(String url) {
try {
msgSocket = new Pair1Socket();
msgSocket.dial(url);
// 设置 2 秒超时
msgSocket.setReceiveTimeout(2000);
} catch (Exception e) {
log.error("创建消息 RPC 失败", e);
return;
}
ByteBuffer bb = ByteBuffer.allocate(BUFFER_SIZE);
while (isReceivingMsg) {
try {
long size = msgSocket.receive(bb, true);
WxMsg wxMsg = Response.parseFrom(Arrays.copyOfRange(bb.array(), 0, (int)size)).getWxmsg();
msgQ.put(wxMsg);
} catch (Exception e) {
// 多半是超时忽略吧
}
}
try {
msgSocket.close();
} catch (Exception e) {
log.error("关闭连接失败", e);
}
}
public void enableRecvMsg(int qSize) { public void enableRecvMsg(int qSize) {
if (isReceivingMsg) { if (isReceivingMsg) {
return; return;

View File

@ -94,9 +94,9 @@ message WxMsg
string content = 7; // string content = 7; //
string sender = 8; // string sender = 8; //
string sign = 9; // Sign string sign = 9; // Sign
string thumb = 10; // string thumb = 10; //
string extra = 11; // string extra = 11; //
string xml = 12; // xml string xml = 12; // xml
} }
message TextMsg message TextMsg