Commit 0e865884 by weiss

1

1 parent 237e9dba
......@@ -463,7 +463,7 @@ public class FeiShuApiService {
*
* @param feiShuMsgDTO
*/
public void sendMsg(FeiShuMsgDTO feiShuMsgDTO, String receiveIdType) {
public JSONObject sendMsg(FeiShuMsgDTO feiShuMsgDTO, String receiveIdType) {
String api = "/im/v1/messages?receive_id_type={receiveIdType}";
RestTemplate restTemplate = new RestTemplate();
try {
......@@ -474,10 +474,14 @@ public class FeiShuApiService {
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
log.info(requestEntity.toString());
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class, receiveIdType);
// ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, receiveIdType);
log.info("单发消息成功, req:{}, resp: {}", feiShuMsgDTO, responseEntity);
if (responseEntity.getBody().getJSONObject("data") == null) {
return null;
}
log.info("消息发送成功,接收人: {}", feiShuMsgDTO.getReceiveId());
return responseEntity.getBody();
} catch (Exception e) {
log.error("单发消息失败", e);
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
}
}
......
......@@ -31,6 +31,12 @@ public class MassageMsgCardSerivce {
@Autowired
private FeiShuApiService feiShuApiService;
public String genMassageMsgCardForSingle(){
String fileName = String.format("/templates/massage-singel-msg-card.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName));
return msgCardContent;
}
public String genMassageMsgCardForCompany(List<List<String>> pushUser){
try {
......
package com.pipihelper.project.feishu.service.massage;
import com.alibaba.fastjson.JSONObject;
import com.pipihelper.project.feishu.bo.PushPainBO;
import com.pipihelper.project.feishu.dto.FeiShuConfig;
import com.pipihelper.project.feishu.dto.msg.FeiShuMsgDTO;
import com.pipihelper.project.feishu.entity.Pain;
import com.pipihelper.project.feishu.service.FeiShuApiService;
import com.pipihelper.project.feishu.service.PainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -30,12 +33,27 @@ public class MassageService {
@Autowired
private FeiShuConfig feiShuConfig;
@Autowired
private PainService painService;
public void sendMassageMsgCardToPiPiChat(List<PushPainBO> pushPainBOList){
List<List<String>> pushUser = new ArrayList<>();
for(PushPainBO pushPainBO:pushPainBOList){
List<String> user = new ArrayList<>();
//给单个用户发送
String singleContent = massageMsgCardSerivce.genMassageMsgCardForSingle();
log.info("给单个用户发送按摩消息:{}",singleContent);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(singleContent);
feiShuMsgDTO.setReceiveId(pushPainBO.getOpenId());
log.info(feiShuMsgDTO.toString());
JSONObject sendMsgResponse = feiShuApiService.sendMsg(feiShuMsgDTO, "open_id");
String messageId = sendMsgResponse.getJSONObject("data").getString("message_id");
//更新按摩记录表中的messageId
Pain pain = painService.findByOpenId(pushPainBO.getOpenId());
pain.setMessageId(messageId);
painService.update(pain);
//构建给大群发送的名单
user.add(pushPainBO.getIndex().toString());
user.add(pushPainBO.getName());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!