Commit 379026c8 by zhaolianjie

Merge remote-tracking branch 'origin/master'

2 parents d9c90e33 496df8f8
......@@ -82,10 +82,10 @@ public class FeiShuEventController {
@PostMapping("/event")
public JSONObject event(@RequestBody String s) throws Exception {
JSONObject reqJsonObject = JSON.parseObject(s);
System.out.println(s);
log.info("接收到事件,密文:{}", s);
FeiShuEventDataDecrypter d = new FeiShuEventDataDecrypter(feiShuConfig.getEncryptKey());
JSONObject encryptJsonObject = JSON.parseObject(d.decrypt(reqJsonObject.getString("encrypt")));
System.out.println(encryptJsonObject);
log.info("接收到事件,明文:{}", encryptJsonObject);
if (encryptJsonObject.containsKey("challenge")) {
return encryptJsonObject;
}
......@@ -94,9 +94,8 @@ public class FeiShuEventController {
return null;
}
if ("im.message.receive_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
} else if ("im.message.message_read_v1".equalsIgnoreCase(feiShuEventDTO.getHeader().getEvent_type())) {
// feiShuEventService.imMessageMessageReadV1(feiShuEventDTO);
log.info("处理单聊事件:{}",feiShuEventDTO);
feiShuEventService.imMessageReceiveV1(feiShuEventDTO);
}
return null;
}
......
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.FeiShuEventDTO;
import com.pipihelper.project.feishu.dto.FeiShuEventHeaderDTO;
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.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.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.regex.Pattern;
/**
* @Description: TODO
......@@ -41,22 +48,37 @@ public class FeiShuEventService {
@Async
public void imMessageReceiveV1(FeiShuEventDTO feiShuEventDTO){
FeiShuEventHeaderDTO feiShuEventHeaderDTO = feiShuEventDTO.getHeader();
FeiShuEventReceiveMessageDTO feiShuEventReceiveMessageDTO = feiShuEventDTO.getEvent().toJavaObject(FeiShuEventReceiveMessageDTO.class);
FeiShuEventReceiveMessageDTO.Sender sender= feiShuEventReceiveMessageDTO.getSender();
FeiShuEventReceiveMessageDTO.Message message= feiShuEventReceiveMessageDTO.getMessage();
//单独处理群消息
if (message.getChat_id().equals(feiShuConfig.getChatId())
|| message.getChat_id().equals(feiShuConfig.getChatId())) { //判断是否为指定群消息
return;
if(message.getChat_type().equals("p2p")) {
robotTalk(feiShuEventDTO);
}
else {
//如果是单聊
if(message.getChat_type().equals("p2p")) {
// robotTalk(feiShuEventDTO);
}
public void robotTalk(FeiShuEventDTO 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!