Skip to content

Commit c1ed595

Browse files
committed
功能实现:
1、图片/视频解析下载(本地) 2、线程阻塞bug
1 parent e6a0888 commit c1ed595

File tree

6 files changed

+367
-28
lines changed

6 files changed

+367
-28
lines changed

clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/controller/WeChatDllController.java

Lines changed: 66 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.wechat.ferry.controller;
22

3+
import com.alibaba.fastjson2.JSONObject;
34
import java.util.List;
45

56
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,6 +15,7 @@
1415
import com.wechat.ferry.entity.vo.request.WxPpWcfDatabaseSqlReq;
1516
import com.wechat.ferry.entity.vo.request.WxPpWcfDatabaseTableReq;
1617
import com.wechat.ferry.entity.vo.request.WxPpWcfDeleteGroupMemberReq;
18+
import com.wechat.ferry.entity.vo.request.WxPpWcfDownloadAttachReq;
1719
import com.wechat.ferry.entity.vo.request.WxPpWcfGroupMemberReq;
1820
import com.wechat.ferry.entity.vo.request.WxPpWcfInviteGroupMemberReq;
1921
import com.wechat.ferry.entity.vo.request.WxPpWcfPassFriendApplyReq;
@@ -41,10 +43,12 @@
4143
import com.wechat.ferry.entity.vo.response.WxPpWcfSendXmlMsgResp;
4244
import com.wechat.ferry.enums.ResponseCodeEnum;
4345
import com.wechat.ferry.service.WeChatDllService;
46+
import com.wechat.ferry.utils.PathUtils;
4447

4548
import io.swagger.annotations.Api;
4649
import io.swagger.annotations.ApiOperation;
4750
import lombok.extern.slf4j.Slf4j;
51+
import org.springframework.util.StringUtils;
4852

4953
/**
5054
* 控制层-微信DLL处理
@@ -182,7 +186,6 @@ public TResponse<WxPpWcfSendPatOnePatMsgResp> patOnePat(@Validated @RequestBody
182186
// public TResponse<Object> queryVoiceMsg() {
183187
// return TResponse.ok(ResponseCodeEnum.SUCCESS, list);
184188
// }
185-
186189
@ApiOperation(value = "撤回消息", notes = "revokeMsg")
187190
@PostMapping(value = "/revokeMsg")
188191
public TResponse<Object> revokeMsg(@Validated @RequestBody WxPpWcfRevokeMsgReq request) {
@@ -207,7 +210,6 @@ public TResponse<Object> revokeMsg(@Validated @RequestBody WxPpWcfRevokeMsgReq r
207210
// return TResponse.ok(ResponseCodeEnum.SUCCESS, list);
208211
// }
209212
//
210-
211213
@ApiOperation(value = "通过好友申请", notes = "passFriendApply")
212214
@PostMapping(value = "/passFriendApply")
213215
public TResponse<Object> passFriendApply(@Validated @RequestBody WxPpWcfPassFriendApplyReq request) {
@@ -257,16 +259,67 @@ public TResponse<Object> receiveTransfer(@Validated @RequestBody WxPpWcfReceiveT
257259
return TResponse.ok(ResponseCodeEnum.SUCCESS);
258260
}
259261

260-
// @ApiOperation(value = "下载图片、视频、文件", notes = "queryMsgTypeList")
261-
// @PostMapping(value = "/list/msgType")
262-
// public TResponse<Object> queryMsgTypeList() {
263-
// return TResponse.ok(ResponseCodeEnum.SUCCESS, list);
264-
// }
265-
//
266-
// @ApiOperation(value = "解密图片", notes = "queryMsgTypeList")
267-
// @PostMapping(value = "/list/msgType")
268-
// public TResponse<Object> queryMsgTypeList() {
269-
// return TResponse.ok(ResponseCodeEnum.SUCCESS, list);
270-
// }
262+
/**
263+
* 下载视频 add by wmz 2025-05-01
264+
*
265+
* @param request
266+
* @return
267+
* @throws Exception
268+
*/
269+
@ApiOperation(value = "下载视频", notes = "download_video")
270+
@PostMapping(value = "/download/video")
271+
public TResponse<Object> downloadVideo(@Validated @RequestBody WxPpWcfDownloadAttachReq request) throws Exception {
272+
String path = weChatDllService.downloadVideo(request);
273+
if (path != null) {
274+
JSONObject pathJson = new JSONObject();
275+
pathJson.put("path", path);
276+
return TResponse.ok(ResponseCodeEnum.SUCCESS, pathJson);
277+
}
278+
return TResponse.ok(ResponseCodeEnum.FAILED);
279+
}
280+
281+
/**
282+
* 下载图片 add by wmz 2025-05-02
283+
*
284+
* @param request
285+
* @return
286+
* @throws Exception
287+
*/
288+
@ApiOperation(value = "下载图片", notes = "download_picture")
289+
@PostMapping(value = "/download/picture")
290+
public TResponse<Object> downloadPicture(@Validated @RequestBody WxPpWcfDownloadAttachReq request) throws Exception {
291+
//check parameter
292+
String dir = request.getDir();
293+
if (!StringUtils.hasText(dir)) {
294+
log.info("需要指定图片的路径dir");
295+
return TResponse.fail("需要指定图片的路径dir");
296+
}
297+
boolean res = PathUtils.createDir(dir);
298+
if (!res) {
299+
return TResponse.fail("图片路径创建失败" + dir);
300+
}
301+
302+
String path = weChatDllService.downloadPicture(request);
303+
if (path != null) {
304+
JSONObject pathJson = new JSONObject();
305+
pathJson.put("path", path);
306+
return TResponse.ok(ResponseCodeEnum.SUCCESS, pathJson);
307+
}
308+
return TResponse.ok(ResponseCodeEnum.FAILED);
309+
}
310+
311+
/**
312+
* 暂未实现 add by mz 2025-05-01
313+
*
314+
* @param request
315+
* @return
316+
* @throws Exception
317+
*/
318+
@ApiOperation(value = "登陆二维码", notes = "loginQR")
319+
@PostMapping(value = "/loginQR")
320+
public TResponse<Object> loginQR(@Validated @RequestBody WxPpWcfDownloadAttachReq request) throws Exception {
321+
String path = weChatDllService.loginQR();
322+
return TResponse.ok(ResponseCodeEnum.SUCCESS, path);
323+
}
271324

272325
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.wechat.ferry.entity.vo.request;
2+
3+
import io.swagger.annotations.ApiModel;
4+
import io.swagger.annotations.ApiModelProperty;
5+
import lombok.Data;
6+
7+
import javax.validation.constraints.NotBlank;
8+
9+
/**
10+
* 请求入参-下载附件信息
11+
*
12+
* @author wmz
13+
* @date 2025-05-01
14+
*/
15+
@Data
16+
@ApiModel(value = "wxPpWcfDownloadAttachReq", description = "个微WCF下载附件请求入参")
17+
public class WxPpWcfDownloadAttachReq {
18+
19+
/**
20+
* 消息接收人
21+
* 消息接收人,私聊为 wxid(wxid_xxxxxxxxxxxxxx)
22+
* 群聊为 roomid(xxxxxxxxxx@chatroom)
23+
*/
24+
@NotBlank(message = "消息id不能为空")
25+
@ApiModelProperty(value = "消息id")
26+
private Long id;
27+
28+
/**
29+
* 文件的extra
30+
*/
31+
@ApiModelProperty(value = "extra")
32+
private String extra;
33+
34+
/**
35+
* 缩略图thumb
36+
*/
37+
// @NotBlank(message = "thumb不能为空")
38+
@ApiModelProperty(value = "缩略图thumb")
39+
private String thumb;
40+
41+
/**
42+
* dir (str): 存放图片的目录。下载图片需要。暂不支持视频
43+
*/
44+
@ApiModelProperty(value = "图片存放路径dir")
45+
private String dir;
46+
47+
}

clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/handle/WeChatSocketClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,11 @@ public void connectRPC(String url, SDK INSTANCE) {
120120

121121
public Response sendCmd(Request req) {
122122
try {
123-
// 设置超时时间 20s
124-
cmdSocket.setSendTimeout(20000);
123+
// 设置超时时间 5s --> 参考Python版本
124+
// 防止无响应的时候线程一直阻塞--ReceiveTimeout
125+
// modify by wmz 2025-05-03
126+
cmdSocket.setSendTimeout(5000);
127+
cmdSocket.setReceiveTimeout(5000);
125128
ByteBuffer bb = ByteBuffer.wrap(req.toByteArray());
126129
cmdSocket.send(bb);
127130
ByteBuffer ret = ByteBuffer.allocate(BUFFER_SIZE);
@@ -176,6 +179,7 @@ public List<DbRow> querySql(String db, String sql) {
176179
* @param dstPath 解密的图片路径
177180
* @return 是否成功
178181
*/
182+
@Deprecated
179183
public boolean decryptImage(String srcPath, String dstPath) {
180184
int ret = -1;
181185
DecPath build = DecPath.newBuilder().setSrc(srcPath).setDst(dstPath).build();

clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/service/WeChatDllService.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.wechat.ferry.entity.vo.request.WxPpWcfDatabaseSqlReq;
77
import com.wechat.ferry.entity.vo.request.WxPpWcfDatabaseTableReq;
88
import com.wechat.ferry.entity.vo.request.WxPpWcfDeleteGroupMemberReq;
9+
import com.wechat.ferry.entity.vo.request.WxPpWcfDownloadAttachReq;
910
import com.wechat.ferry.entity.vo.request.WxPpWcfGroupMemberReq;
1011
import com.wechat.ferry.entity.vo.request.WxPpWcfInviteGroupMemberReq;
1112
import com.wechat.ferry.entity.vo.request.WxPpWcfPassFriendApplyReq;
@@ -244,6 +245,41 @@ public interface WeChatDllService {
244245
* @date 2024-10-02 20:59
245246
*/
246247
List<WxPpWcfGroupMemberResp> queryGroupMemberList(WxPpWcfGroupMemberReq request);
248+
249+
/**
250+
* 下载视频文件
251+
*
252+
* @param request 请求入参
253+
* @return 文件路径
254+
*
255+
* @author wmz
256+
* @throws java.lang.Exception
257+
* @date 2025-05-02
258+
*/
259+
String downloadVideo(WxPpWcfDownloadAttachReq request) throws Exception;
260+
261+
/**
262+
* 下载图片
263+
*
264+
* @param request 请求入参
265+
* @return 文件路径
266+
*
267+
* @author wmz
268+
* @throws java.lang.Exception
269+
* @date 2025-05-02
270+
*/
271+
String downloadPicture(WxPpWcfDownloadAttachReq request) throws Exception;
272+
273+
/**
274+
* 获取登录二维码
275+
*
276+
* @return 文件路径
277+
*
278+
* @author wmz
279+
* @throws java.lang.Exception
280+
* @date 2025-05-02
281+
*/
282+
String loginQR() throws Exception;
247283

248284
/**
249285
* 邀请群成员

0 commit comments

Comments
 (0)