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.RestController;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.wechat.ferry.entity.TResponse;
|
||||
import com.wechat.ferry.enums.ResponseCodeEnum;
|
||||
import com.wechat.ferry.service.WeChatMsgService;
|
||||
@ -36,8 +35,8 @@ public class WeChatMsgController {
|
||||
|
||||
@ApiOperation(value = "接收微信消息", notes = "receiveMsg")
|
||||
@PostMapping(value = "/receive")
|
||||
public TResponse<Object> receiveMsg(@RequestBody JSONObject jsonData) {
|
||||
log.debug("jsonData:{}", jsonData);
|
||||
public TResponse<Object> receiveMsg(@RequestBody String jsonString) {
|
||||
weChatMsgService.receiveMsg(jsonString);
|
||||
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 lombok.Data;
|
||||
@ -10,7 +10,7 @@ import lombok.Data;
|
||||
* @date 2024-09-26 19:56
|
||||
*/
|
||||
@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.sun.jna.Native;
|
||||
import com.wechat.ferry.entity.dto.WxMsgDTO;
|
||||
import com.wechat.ferry.entity.po.Wcf;
|
||||
import com.wechat.ferry.entity.po.Wcf.DbQuery;
|
||||
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.Verification;
|
||||
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.service.SDK;
|
||||
import com.wechat.ferry.utils.HttpClientUtil;
|
||||
@ -528,21 +528,21 @@ public class WeChatSocketClient {
|
||||
}
|
||||
|
||||
public void printWxMsg(WxMsg msg) {
|
||||
WxMsgResp wxMsgResp = new WxMsgResp();
|
||||
wxMsgResp.setIsSelf(msg.getIsSelf());
|
||||
wxMsgResp.setIsGroup(msg.getIsGroup());
|
||||
wxMsgResp.setId(msg.getId());
|
||||
wxMsgResp.setType(msg.getType());
|
||||
wxMsgResp.setTs(msg.getTs());
|
||||
wxMsgResp.setRoomId(msg.getRoomid());
|
||||
wxMsgResp.setContent(msg.getContent());
|
||||
wxMsgResp.setSender(msg.getSender());
|
||||
wxMsgResp.setSign(msg.getSign());
|
||||
wxMsgResp.setThumb(msg.getThumb());
|
||||
wxMsgResp.setExtra(msg.getExtra());
|
||||
wxMsgResp.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
||||
WxMsgDTO dto = new WxMsgDTO();
|
||||
dto.setIsSelf(msg.getIsSelf());
|
||||
dto.setIsGroup(msg.getIsGroup());
|
||||
dto.setId(msg.getId());
|
||||
dto.setType(msg.getType());
|
||||
dto.setTs(msg.getTs());
|
||||
dto.setRoomId(msg.getRoomid());
|
||||
dto.setContent(msg.getContent());
|
||||
dto.setSender(msg.getSender());
|
||||
dto.setSign(msg.getSign());
|
||||
dto.setThumb(msg.getThumb());
|
||||
dto.setExtra(msg.getExtra());
|
||||
dto.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
||||
|
||||
String jsonString = JSONObject.toJSONString(wxMsgResp);
|
||||
String jsonString = JSONObject.toJSONString(dto);
|
||||
log.info("收到消息: {}", jsonString);
|
||||
}
|
||||
|
||||
@ -561,21 +561,21 @@ public class WeChatSocketClient {
|
||||
}
|
||||
|
||||
public void forwardMsg(WxMsg msg, String url) {
|
||||
WxMsgResp wxMsgResp = new WxMsgResp();
|
||||
wxMsgResp.setIsSelf(msg.getIsSelf());
|
||||
wxMsgResp.setIsGroup(msg.getIsGroup());
|
||||
wxMsgResp.setId(msg.getId());
|
||||
wxMsgResp.setType(msg.getType());
|
||||
wxMsgResp.setTs(msg.getTs());
|
||||
wxMsgResp.setRoomId(msg.getRoomid());
|
||||
wxMsgResp.setContent(msg.getContent());
|
||||
wxMsgResp.setSender(msg.getSender());
|
||||
wxMsgResp.setSign(msg.getSign());
|
||||
wxMsgResp.setThumb(msg.getThumb());
|
||||
wxMsgResp.setExtra(msg.getExtra());
|
||||
wxMsgResp.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
||||
WxMsgDTO dto = new WxMsgDTO();
|
||||
dto.setIsSelf(msg.getIsSelf());
|
||||
dto.setIsGroup(msg.getIsGroup());
|
||||
dto.setId(msg.getId());
|
||||
dto.setType(msg.getType());
|
||||
dto.setTs(msg.getTs());
|
||||
dto.setRoomId(msg.getRoomid());
|
||||
dto.setContent(msg.getContent());
|
||||
dto.setSender(msg.getSender());
|
||||
dto.setSign(msg.getSign());
|
||||
dto.setThumb(msg.getThumb());
|
||||
dto.setExtra(msg.getExtra());
|
||||
dto.setXml(msg.getXml().replace("\n", "").replace("\t", ""));
|
||||
|
||||
String jsonString = JSONObject.toJSONString(wxMsgResp);
|
||||
String jsonString = JSONObject.toJSONString(dto);
|
||||
try {
|
||||
String responseStr = HttpClientUtil.doPostJson(url, jsonString);
|
||||
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
|
||||
* @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;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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 lombok.extern.slf4j.Slf4j;
|
||||
@ -18,16 +18,12 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
public class WeChatMsgServiceImpl implements WeChatMsgService {
|
||||
|
||||
private WeChatSocketClient wechatSocketClient;
|
||||
|
||||
@Autowired
|
||||
public void setWechatSocketClient(WeChatSocketClient wechatSocketClient) {
|
||||
this.wechatSocketClient = wechatSocketClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
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