Commit da42f986 by weiss

1

1 parent b9ab75f2
...@@ -82,10 +82,10 @@ public class FeiShuEventController { ...@@ -82,10 +82,10 @@ public class FeiShuEventController {
@PostMapping("/event") @PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception { public JSONObject event(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s); JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s); log.info("接收到事件,密文:{}", s);
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey()); FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey());
JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt"))); JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt")));
System.out.println(encryptJsonObject); log.info("接收到事件,明文:{}", encryptJsonObject);
if (encryptJsonObject.containsKey("challenge")) { if (encryptJsonObject.containsKey("challenge")) {
return encryptJsonObject; return encryptJsonObject;
} }
...@@ -94,9 +94,8 @@ public class FeiShuEventController { ...@@ -94,9 +94,8 @@ public class FeiShuEventController {
return null; return null;
} }
if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) { if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageReceiveV1(feiShuEventDTO); log.info("处理单聊事件:{}",feiShuEventDTO);
} else if ("im.message.message_read_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) { feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
// feiShuEventService.imMessageMessageReadV1(feiShuEventDTO);
} }
return null; return null;
} }
......
package com.pipihelper.project.feishu.service; package com.pipihelper.project.feishu.service;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.dto.FeiShuConfig; import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.FeiShuEventDTO; import com.pipihelper.project.feishu.dto.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO; import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventReceiveMessageDTO; import com.pipihelper.project.feishu.dto.FeiShuEventReceiveMessageDTO;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.tx.dto.TxConfig; import com.pipihelper.project.tx.dto.TxConfig;
import com.pipihelper.project.tx.service.TxApiService; import com.pipihelper.project.tx.service.TxApiService;
import com.tencentcloudapi.tbp.v20190627.models.Group;
import com.tencentcloudapi.tbp.v20190627.models.TextProcessResponse;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.regex.Pattern;
/** /**
* @Description: TODO * @Description: TODO
...@@ -41,22 +48,37 @@ public class FeiShuEventService { ...@@ -41,22 +48,37 @@ public class FeiShuEventService {
@Async @Async
public void imMessageReceiveV1(FeiShuEventDTO feiShuEventDTO){ public void imMessageReceiveV1(FeiShuEventDTO feiShuEventDTO){
FeiShuEventHeaderDTO feiShuEventHeaderDTO = feiShuEventDTO.getHeader();
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class); FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender(); FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage(); FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
//单独处理群消息 if(message.getChat_type().equals("p2p")) {
if (message.getChat_id().equals(feiShuConfig.getChatId()) robotTalk(feiShuEventDTO);
|| message.getChat_id().equals(feiShuConfig.getChatId())) { //判断是否为指定群消息
return;
} }
else { }
//如果是单聊
if(message.getChat_type().equals("p2p")) { public void robotTalk(FeiShuEventDTO feiShuEventDTO){
// robotTalk(feiShuEventDTO); FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setReceiveId(sender.getSender_id().getOpen_id());
if(message.getMessage_type().equals("text")){
JSONObject jsonObjectText = JSON.parseObject(message.getContent());
String inputText = jsonObjectText.getString("text");
String uuid = IdUtil.randomUUID();
TextProcessResponse textProcessResponse = txApiService.txTextProcessRequest(uuid, inputText);
for (Group group : textProcessResponse.getResponseMessage().getGroupList()) {
JSONObject content = new JSONObject();
content.put("text", group.getContent());
feiShuMsgDTO.setContent(content.toString());
feiShuMsgDTO.setMsgType("text");
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
}
} }
} }
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!