Commit d303d706 by weiss

1

1 parent 91d45789
...@@ -320,6 +320,27 @@ public class FeiShuApiService { ...@@ -320,6 +320,27 @@ public class FeiShuApiService {
} }
} }
//上传图片
public String uploadImage(String image_type,byte[] file) {
String api = "/im/v1/images";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + getTenantToken());
headers.setContentType(org.springframework.http.MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("image_type", image_type);
param.add("image", file);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(param, headers);
String url = feiShuConfig.getFeiShuOpenApiHost() + api;
try {
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, requestEntity, JSONObject.class);
return responseEntity.getBody().getJSONObject("data").getString("image_key");
} catch (Exception e) {
throw new ServiceException("飞书:" + api + "接口调用失败" + "\n" + e);
}
}
//获取应用有权限的所有部门 //获取应用有权限的所有部门
public JSONObject getDepartment() { public JSONObject getDepartment() {
String api = "/contact/v3/departments?fetch_child=true"; String api = "/contact/v3/departments?fetch_child=true";
...@@ -451,8 +472,9 @@ public class FeiShuApiService { ...@@ -451,8 +472,9 @@ public class FeiShuApiService {
headers.set("Content-Type", "application/json; charset=utf-8"); headers.set("Content-Type", "application/json; charset=utf-8");
HttpEntity<String> requestEntity = new HttpEntity<>(objectMapper.writeValueAsString(feiShuMsgDTO), headers); HttpEntity<String> requestEntity = new HttpEntity<>(objectMapper.writeValueAsString(feiShuMsgDTO), headers);
String url = feiShuConfig.getFeiShuOpenApiHost() + api; String url = feiShuConfig.getFeiShuOpenApiHost() + api;
log.info(requestEntity.toString());
ResponseEntity<String> responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, String.class, receiveIdType); 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); log.info("单发消息成功, req:{}, resp: {}", feiShuMsgDTO, responseEntity);
} catch (Exception e) { } catch (Exception e) {
log.error("单发消息失败", e); log.error("单发消息失败", e);
......
...@@ -38,7 +38,7 @@ public class MassageMsgCardSerivce { ...@@ -38,7 +38,7 @@ public class MassageMsgCardSerivce {
pushUser.add(0,title); pushUser.add(0,title);
byte[] bufferedImage = GraphicsGenerationUtil.bufferedImageToByte(pushUser); byte[] bufferedImage = GraphicsGenerationUtil.bufferedImageToByte(pushUser);
//将图片上传 //将图片上传
String imgKey = feiShuApiService.uploadFile("stream", "massageEmployee", null, bufferedImage); String imgKey = feiShuApiService.uploadImage("message", bufferedImage);
String fileName = String.format("/templates/massage-msg-card.json"); String fileName = String.format("/templates/massage-msg-card.json");
String msgCardContent = String.format(getInteractiveCardStr(fileName), imgKey); String msgCardContent = String.format(getInteractiveCardStr(fileName), imgKey);
return msgCardContent; return msgCardContent;
......
...@@ -45,11 +45,13 @@ public class MassageService { ...@@ -45,11 +45,13 @@ public class MassageService {
pushUser.add(user); pushUser.add(user);
} }
String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser); String content = massageMsgCardSerivce.genMassageMsgCardForCompany(pushUser);
log.info("给大群发送按摩消息:{}",content);
FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO(); FeiShuMsgDTO feiShuMsgDTO = new FeiShuMsgDTO();
feiShuMsgDTO.setMsgType("interactive"); feiShuMsgDTO.setMsgType("interactive");
feiShuMsgDTO.setContent(content); feiShuMsgDTO.setContent(content);
feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId()); feiShuMsgDTO.setReceiveId(feiShuConfig.getChatId());
feiShuApiService.sendMsg(feiShuMsgDTO, "open_id"); log.info(feiShuMsgDTO.toString());
feiShuApiService.sendMsg(feiShuMsgDTO, "chat_id");
} }
......
...@@ -59,7 +59,7 @@ public class GraphicsGenerationUtil { ...@@ -59,7 +59,7 @@ public class GraphicsGenerationUtil {
Font font = new Font("微软雅黑",Font.BOLD,fontTitileSize); Font font = new Font("微软雅黑",Font.BOLD,fontTitileSize);
graphics.setFont(font); graphics.setFont(font);
//写标题 //写标题
String title = "【指标完成进度】"; String title = "【按摩名单】";
graphics.drawString(title, startWidth, startHeight+rowheight-10); graphics.drawString(title, startWidth, startHeight+rowheight-10);
//写入内容 //写入内容
for(int n=0;n< data.size();n++){ for(int n=0;n< data.size();n++){
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
}, },
"type": "default", "type": "default",
"value": { "value": {
"key2": "massage-singel.wait" "key3": "massage-singel.wait"
} }
} }
], ],
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!