feat(0): [java]-[wechat-ferry-mvn]-基础功能完善
This commit is contained in:
parent
478a10008e
commit
b43275d85d
@ -1,40 +0,0 @@
|
|||||||
package com.wechat.ferry.controller;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
|
|
||||||
import com.wechat.ferry.entity.TResponse;
|
|
||||||
import com.wechat.ferry.enums.ResponseCodeEnum;
|
|
||||||
import com.wechat.ferry.service.TestService;
|
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
|
||||||
import io.swagger.annotations.ApiOperation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 控制层-测试类
|
|
||||||
*
|
|
||||||
* @author chandler
|
|
||||||
* @date 2024-09-25 22:17
|
|
||||||
*/
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/test")
|
|
||||||
@Api(tags = "测试-接口")
|
|
||||||
public class TestController {
|
|
||||||
|
|
||||||
private TestService testService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setTestService(TestService testService) {
|
|
||||||
this.testService = testService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiOperation(value = "测试", notes = "login")
|
|
||||||
@PostMapping(value = "/login")
|
|
||||||
public TResponse<Object> login() {
|
|
||||||
Boolean flag = testService.isLogin();
|
|
||||||
return TResponse.ok(ResponseCodeEnum.SUCCESS, flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
44
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/controller/WeChatDllController.java
vendored
Normal file
44
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/controller/WeChatDllController.java
vendored
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package com.wechat.ferry.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.wechat.ferry.entity.TResponse;
|
||||||
|
import com.wechat.ferry.enums.ResponseCodeEnum;
|
||||||
|
import com.wechat.ferry.service.WeChatDllService;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制层-微信DLL处理
|
||||||
|
*
|
||||||
|
* @author chandler
|
||||||
|
* @date 2024-10-01 15:48
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/wechat/cgi/dll")
|
||||||
|
@Api(tags = "微信消息处理-接口")
|
||||||
|
public class WeChatDllController {
|
||||||
|
|
||||||
|
private WeChatDllService weChatDllService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public void setWeChatDllService(WeChatDllService weChatDllService) {
|
||||||
|
this.weChatDllService = weChatDllService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "测试", notes = "test")
|
||||||
|
@PostMapping(value = "/test")
|
||||||
|
public TResponse<Object> test(@RequestBody JSONObject jsonData) {
|
||||||
|
|
||||||
|
return TResponse.ok(ResponseCodeEnum.SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -6,7 +6,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
|
||||||
import com.wechat.ferry.entity.TResponse;
|
import com.wechat.ferry.entity.TResponse;
|
||||||
import com.wechat.ferry.enums.ResponseCodeEnum;
|
import com.wechat.ferry.enums.ResponseCodeEnum;
|
||||||
import com.wechat.ferry.service.WeChatMsgService;
|
import com.wechat.ferry.service.WeChatMsgService;
|
||||||
@ -36,8 +35,8 @@ public class WeChatMsgController {
|
|||||||
|
|
||||||
@ApiOperation(value = "接收微信消息", notes = "receiveMsg")
|
@ApiOperation(value = "接收微信消息", notes = "receiveMsg")
|
||||||
@PostMapping(value = "/receive")
|
@PostMapping(value = "/receive")
|
||||||
public TResponse<Object> receiveMsg(@RequestBody JSONObject jsonData) {
|
public TResponse<Object> receiveMsg(@RequestBody String jsonString) {
|
||||||
log.debug("jsonData:{}", jsonData);
|
weChatMsgService.receiveMsg(jsonString);
|
||||||
return TResponse.ok(ResponseCodeEnum.SUCCESS);
|
return TResponse.ok(ResponseCodeEnum.SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package com.wechat.ferry.entity.vo.response;
|
package com.wechat.ferry.entity.dto;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@ -10,7 +10,7 @@ import lombok.Data;
|
|||||||
* @date 2024-09-26 19:56
|
* @date 2024-09-26 19:56
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class WxMsgResp {
|
public class WxMsgDTO {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否自己发送的
|
* 是否自己发送的
|
32
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/enums/WeChatMsgTypeEnum.java
vendored
Normal file
32
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/enums/WeChatMsgTypeEnum.java
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package com.wechat.ferry.enums;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 枚举-消息类型
|
||||||
|
*
|
||||||
|
* @author chandler
|
||||||
|
* @date 2024/10/01 15:55
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@AllArgsConstructor
|
||||||
|
public enum WeChatMsgTypeEnum {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 0-未知
|
||||||
|
*/
|
||||||
|
UNKNOWN("0", "未知"),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 未匹配上
|
||||||
|
*/
|
||||||
|
UN_MATCH("", null),
|
||||||
|
|
||||||
|
// 结束
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
}
|
@ -10,6 +10,7 @@ import java.util.concurrent.BlockingQueue;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.sun.jna.Native;
|
import com.sun.jna.Native;
|
||||||
|
import com.wechat.ferry.entity.dto.WxMsgDTO;
|
||||||
import com.wechat.ferry.entity.po.Wcf;
|
import com.wechat.ferry.entity.po.Wcf;
|
||||||
import com.wechat.ferry.entity.po.Wcf.DbQuery;
|
import com.wechat.ferry.entity.po.Wcf.DbQuery;
|
||||||
import com.wechat.ferry.entity.po.Wcf.DbRow;
|
import com.wechat.ferry.entity.po.Wcf.DbRow;
|
||||||
@ -23,7 +24,6 @@ import com.wechat.ferry.entity.po.Wcf.RpcContact;
|
|||||||
import com.wechat.ferry.entity.po.Wcf.UserInfo;
|
import com.wechat.ferry.entity.po.Wcf.UserInfo;
|
||||||
import com.wechat.ferry.entity.po.Wcf.Verification;
|
import com.wechat.ferry.entity.po.Wcf.Verification;
|
||||||
import com.wechat.ferry.entity.po.Wcf.WxMsg;
|
import com.wechat.ferry.entity.po.Wcf.WxMsg;
|
||||||
import com.wechat.ferry.entity.vo.response.WxMsgResp;
|
|
||||||
import com.wechat.ferry.enums.SexEnum;
|
import com.wechat.ferry.enums.SexEnum;
|
||||||
import com.wechat.ferry.service.SDK;
|
import com.wechat.ferry.service.SDK;
|
||||||
import com.wechat.ferry.utils.HttpClientUtil;
|
import com.wechat.ferry.utils.HttpClientUtil;
|
||||||
@ -528,21 +528,21 @@ public class WeChatSocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void printWxMsg(WxMsg msg) {
|
public void printWxMsg(WxMsg msg) {
|
||||||
WxMsgResp wxMsgResp = new WxMsgResp();
|
WxMsgDTO dto = new WxMsgDTO();
|
||||||
wxMsgResp.setIsSelf(msg.getIsSelf());
|
dto.setIsSelf(msg.getIsSelf());
|
||||||
wxMsgResp.setIsGroup(msg.getIsGroup());
|
dto.setIsGroup(msg.getIsGroup());
|
||||||
wxMsgResp.setId(msg.getId());
|
dto.setId(msg.getId());
|
||||||
wxMsgResp.setType(msg.getType());
|
dto.setType(msg.getType());
|
||||||
wxMsgResp.setTs(msg.getTs());
|
dto.setTs(msg.getTs());
|
||||||
wxMsgResp.setRoomId(msg.getRoomid());
|
dto.setRoomId(msg.getRoomid());
|
||||||
wxMsgResp.setContent(msg.getContent());
|
dto.setContent(msg.getContent());
|
||||||
wxMsgResp.setSender(msg.getSender());
|
dto.setSender(msg.getSender());
|
||||||
wxMsgResp.setSign(msg.getSign());
|
dto.setSign(msg.getSign());
|
||||||
wxMsgResp.setThumb(msg.getThumb());
|
dto.setThumb(msg.getThumb());
|
||||||
wxMsgResp.setExtra(msg.getExtra());
|
dto.setExtra(msg.getExtra());
|
||||||
wxMsgResp.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
dto.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
||||||
|
|
||||||
String jsonString = JSONObject.toJSONString(wxMsgResp);
|
String jsonString = JSONObject.toJSONString(dto);
|
||||||
log.info("收到消息: {}", jsonString);
|
log.info("收到消息: {}", jsonString);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -561,21 +561,21 @@ public class WeChatSocketClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void forwardMsg(WxMsg msg, String url) {
|
public void forwardMsg(WxMsg msg, String url) {
|
||||||
WxMsgResp wxMsgResp = new WxMsgResp();
|
WxMsgDTO dto = new WxMsgDTO();
|
||||||
wxMsgResp.setIsSelf(msg.getIsSelf());
|
dto.setIsSelf(msg.getIsSelf());
|
||||||
wxMsgResp.setIsGroup(msg.getIsGroup());
|
dto.setIsGroup(msg.getIsGroup());
|
||||||
wxMsgResp.setId(msg.getId());
|
dto.setId(msg.getId());
|
||||||
wxMsgResp.setType(msg.getType());
|
dto.setType(msg.getType());
|
||||||
wxMsgResp.setTs(msg.getTs());
|
dto.setTs(msg.getTs());
|
||||||
wxMsgResp.setRoomId(msg.getRoomid());
|
dto.setRoomId(msg.getRoomid());
|
||||||
wxMsgResp.setContent(msg.getContent());
|
dto.setContent(msg.getContent());
|
||||||
wxMsgResp.setSender(msg.getSender());
|
dto.setSender(msg.getSender());
|
||||||
wxMsgResp.setSign(msg.getSign());
|
dto.setSign(msg.getSign());
|
||||||
wxMsgResp.setThumb(msg.getThumb());
|
dto.setThumb(msg.getThumb());
|
||||||
wxMsgResp.setExtra(msg.getExtra());
|
dto.setExtra(msg.getExtra());
|
||||||
wxMsgResp.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
dto.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
||||||
|
|
||||||
String jsonString = JSONObject.toJSONString(wxMsgResp);
|
String jsonString = JSONObject.toJSONString(dto);
|
||||||
try {
|
try {
|
||||||
String responseStr = HttpClientUtil.doPostJson(url, jsonString);
|
String responseStr = HttpClientUtil.doPostJson(url, jsonString);
|
||||||
if (!JSONObject.parseObject(responseStr).getString("code").equals("200")) {
|
if (!JSONObject.parseObject(responseStr).getString("code").equals("200")) {
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package com.wechat.ferry.service;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务接口-注册
|
|
||||||
*
|
|
||||||
* @author chandler
|
|
||||||
* @date 2024-09-29 20:58
|
|
||||||
*/
|
|
||||||
public interface TestService {
|
|
||||||
|
|
||||||
Boolean isLogin();
|
|
||||||
|
|
||||||
}
|
|
11
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/service/WeChatDllService.java
vendored
Normal file
11
clients/java/wechat-ferry-mvn/src/main/java/com/wechat/ferry/service/WeChatDllService.java
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.wechat.ferry.service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务接口-对接原本DLL的接口
|
||||||
|
*
|
||||||
|
* @author chandler
|
||||||
|
* @date 2024-10-01 15:57
|
||||||
|
*/
|
||||||
|
public interface WeChatDllService {
|
||||||
|
|
||||||
|
}
|
@ -11,7 +11,7 @@ public interface WeChatMsgService {
|
|||||||
/**
|
/**
|
||||||
* 接收消息
|
* 接收消息
|
||||||
*
|
*
|
||||||
* @param jsonString json转换后的字符串
|
* @param jsonString json数据
|
||||||
*
|
*
|
||||||
* @author chandler
|
* @author chandler
|
||||||
* @date 2024-10-01 14:33
|
* @date 2024-10-01 14:33
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
package com.wechat.ferry.service.impl;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import com.wechat.ferry.handle.WeChatSocketClient;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
import com.wechat.ferry.service.TestService;
|
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 业务实现层-注册
|
|
||||||
*
|
|
||||||
* @author chandler
|
|
||||||
* @date 2024-09-29 20:58
|
|
||||||
*/
|
|
||||||
@Slf4j
|
|
||||||
@Service
|
|
||||||
public class TestServiceImpl implements TestService {
|
|
||||||
|
|
||||||
@Resource
|
|
||||||
private WeChatSocketClient wechatSocketClient;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean isLogin() {
|
|
||||||
|
|
||||||
boolean flag = wechatSocketClient.isLogin();
|
|
||||||
log.info("flag:{}", flag);
|
|
||||||
List<String> list = wechatSocketClient.getDbNames();
|
|
||||||
log.info("list:{}", list);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.wechat.ferry.service.impl;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.wechat.ferry.service.WeChatDllService;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 业务实现层-对接原本DLL的接口
|
||||||
|
*
|
||||||
|
* @author chandler
|
||||||
|
* @date 2024-10-01 15:58
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class WeChatDllServiceImpl implements WeChatDllService {
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
package com.wechat.ferry.service.impl;
|
package com.wechat.ferry.service.impl;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.wechat.ferry.handle.WeChatSocketClient;
|
import com.alibaba.fastjson2.JSON;
|
||||||
|
import com.wechat.ferry.entity.dto.WxMsgDTO;
|
||||||
import com.wechat.ferry.service.WeChatMsgService;
|
import com.wechat.ferry.service.WeChatMsgService;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -18,16 +18,12 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
@Service
|
@Service
|
||||||
public class WeChatMsgServiceImpl implements WeChatMsgService {
|
public class WeChatMsgServiceImpl implements WeChatMsgService {
|
||||||
|
|
||||||
private WeChatSocketClient wechatSocketClient;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public void setWechatSocketClient(WeChatSocketClient wechatSocketClient) {
|
|
||||||
this.wechatSocketClient = wechatSocketClient;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveMsg(String jsonString) {
|
public void receiveMsg(String jsonString) {
|
||||||
log.debug("[收到消息]-[消息内容]-打印:{}", jsonString);
|
// 转为JSON对象
|
||||||
|
WxMsgDTO dto = JSON.parseObject(jsonString, WxMsgDTO.class);
|
||||||
|
// TODO 这里可以拓展自己需要的功能
|
||||||
|
log.debug("[收到消息]-[消息内容]-打印:{}", dto);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user