feat: hiwork消息跳转&钉钉消息跳转

This commit is contained in:
2024-03-26 11:44:02 +08:00
parent 93846333e3
commit 71a8e74d4f
8 changed files with 63 additions and 12 deletions
@@ -6,7 +6,6 @@ import com.jero.modules.message.handle.ISendMsgHandle;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import java.util.List;
/**
* @Author: liao
@@ -22,9 +21,9 @@ public class DingDingSendMsgHandle implements ISendMsgHandle {
* @Description: Hiwork钉钉消息
**/
@Override
public void SendMsg(String esReceiver, String esTitle, String esContent, String openType, String openPage) {
public void SendMsg(String esReceiver, String esTitle, String esContent, String openType, String messageUrl) {
IHiworkMsgService hiworkMsgService = SpringContextUtils.getBean(IHiworkMsgService.class);
hiworkMsgService.sendDingDingMsg(Arrays.asList(esReceiver.split(",")), esTitle, esContent);
hiworkMsgService.sendDingDingMsg(Arrays.asList(esReceiver.split(",")), esTitle, esContent, messageUrl);
}
}
@@ -15,7 +15,7 @@ public class SystemSendMsgHandle implements ISendMsgHandle {
IHiworkMsgService hiworkMsgService = SpringContextUtils.getBean(IHiworkMsgService.class);
// TODO 先写死 01 消息类型(暂未确定)
String messageType = "01";
hiworkMsgService.sendSystemMsg(Arrays.asList(esReceiver.split(",")), messageType, esTitle, esContent);
hiworkMsgService.sendSystemMsg(Arrays.asList(esReceiver.split(",")), messageType, esTitle, esContent, openPage);
}
}
@@ -17,7 +17,7 @@ public interface IHiworkMsgService {
* title:消息标题
* content:文本内容
**/
void sendDingDingMsg(List<String> senderIdList, String title, String content);
void sendDingDingMsg(List<String> senderIdList, String title, String content, String messageUrl);
/**
* @Author: liao
@@ -29,5 +29,5 @@ public interface IHiworkMsgService {
* title:消息标题
* content:消息内容
**/
void sendSystemMsg(List<String> receiverIdList, String messageType, String title, String content);
void sendSystemMsg(List<String> receiverIdList, String messageType, String title, String content, String messageUrl);
}
@@ -1,5 +1,7 @@
package com.jero.modules.docking.hiwork.service.impl;
import cn.hutool.core.annotation.Link;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jero.common.exception.JeroBootException;
@@ -38,6 +40,7 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
private ISysUserService sysUserService;
private final static String TEXT = "text"; // 消息类型-文本
private final static String LINK = "link"; // 消息类型-文本
private final static String MSG_TYPE = "msgtype"; // 消息类型
private final static String CONTENT = "content"; // 消息内容
@@ -49,7 +52,7 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
* content:文本内容
**/
@Override
public void sendDingDingMsg(List<String> senderIdList, String title, String content) {
public void sendDingDingMsg(List<String> senderIdList, String title, String content, String messageUrl) {
HiworkDingDingMsg hiworkDingDingMsg = new HiworkDingDingMsg();
// 异步系统标识
hiworkDingDingMsg.setSysCode(HiworkPostUtil.getSysCode());
@@ -66,9 +69,14 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
// 消息体
JSONObject msgJsonObject = new JSONObject();
msgJsonObject.put(MSG_TYPE, TEXT);
JSONObject textJsonObject = new JSONObject();
textJsonObject.put(CONTENT, content);
if (StrUtil.isBlank(messageUrl)) {
msgJsonObject.put(MSG_TYPE, TEXT);
} else {
msgJsonObject.put(MSG_TYPE, LINK);
textJsonObject.put("messageUrl", messageUrl);
}
msgJsonObject.put(TEXT, textJsonObject);
hiworkDingDingMsg.setMsg(msgJsonObject);
@@ -88,7 +96,7 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
* content:消息内容
**/
@Override
public void sendSystemMsg(List<String> receiverIdList, String messageType, String title, String content) {
public void sendSystemMsg(List<String> receiverIdList, String messageType, String title, String content, String messageUrl) {
HiworkSystemMsg hiworkSystemMsg = new HiworkSystemMsg();
// 异步系统标识
@@ -122,9 +130,14 @@ public class HiworkMsgServiceImpl implements IHiworkMsgService {
// 消息体
JSONObject msgJsonObject = new JSONObject();
msgJsonObject.put(MSG_TYPE, TEXT);
JSONObject textJsonObject = new JSONObject();
textJsonObject.put(CONTENT, content);
if (StrUtil.isBlank(messageUrl)) {
msgJsonObject.put(MSG_TYPE, TEXT);
} else {
msgJsonObject.put(MSG_TYPE, LINK);
textJsonObject.put("messageUrl", messageUrl);
}
msgJsonObject.put(TEXT, textJsonObject);
hiworkSystemMsg.setMsg(msgJsonObject);
@@ -17,6 +17,10 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -35,6 +39,12 @@ public class SendMessageServiceImpl implements SendMessageAPI {
private ISysMessageTemplateService sysMessageTemplateService;
@Value("${hiwork.isSend}")
private Boolean isSend;
@Value("${hiwork.isHiworkDingDingSend}")
private Boolean isHiworkDingDingSend;
@Value("${hiwork.dingdingUrlPrefix}")
private String dingdingUrlPrefix;
@Value("${hiwork.hiworkUrlPrefix}")
private String hiworkUrlPrefix;
/**
* @Author: liao
@@ -103,8 +113,19 @@ public class SendMessageServiceImpl implements SendMessageAPI {
} else {
return;
}
if (isSend) {
sendMsgHandle.SendMsg(sendMessageDTO.getToUserId(), sysMessageTemplate.getTemplateName(), sysMessageTemplate.getTemplateContent(), finalOpenType, finalOpenPage);
if (isHiworkDingDingSend) {
String messageUrl = hiworkUrlPrefix + finalOpenPage;
if (sendMsgHandle instanceof DingDingSendMsgHandle) {
// 将tempUrl编码
String encodeUrl = null;
try {
encodeUrl = URLEncoder.encode(messageUrl, StandardCharsets.UTF_8.name());
} catch (UnsupportedEncodingException e) {
throw new JeroBootException("钉钉消息跳转url编码异常", e);
}
messageUrl = dingdingUrlPrefix + encodeUrl + "&pc_slide=true";
}
sendMsgHandle.SendMsg(sendMessageDTO.getToUserId(), sysMessageTemplate.getTemplateName(), sysMessageTemplate.getTemplateContent(), finalOpenType, messageUrl);
}
});
} catch (Exception e){
@@ -416,6 +416,12 @@ hiwork:
#hiwork单点登录
appkey: dingshfclphtivrd0r7k
appsecret: dqhom_17n6BC8pmLeaf5wNp4aV_4XSt_aYn-dNBo8z__-79NjVvZhDJ_M2REdxRc
# dingding和Hiwork是否发送消息
isHiworkDingDingSend: false
#hiwork消息跳转前缀
hiworkUrlPrefix: "http://srms-test.sinotruk.com"
#hiwork钉钉消息跳转前缀
dingdingUrlPrefix: "dingtalk://dingtalkclient/page/link?url="
# 汽车标准数字化平台ASMS
asms:
@@ -388,6 +388,12 @@ hiwork:
url: https://iam.sinotruk.com:7011/idp/oauth2/authorize?&state=123&client_id=SRMS&response_type=code&redirect_uri=
fontUrl: http://srms.sinotruk.com{url}?projectId={projectId}&taskName={taskName}&taskId={taskId}&processInstanceId={processInstanceId}&nodeId={nodeId}
fontAppUrl: http://222.175.158.138:8120/mobile{url}?projectId={projectId}&taskName={taskName}&taskId={taskId}&processInstanceId={processInstanceId}&nodeId={nodeId}
# dingding和Hiwork是否发送消息
isHiworkDingDingSend: false
#hiwork消息跳转前缀
hiworkUrlPrefix: "http://srms-test.sinotruk.com"
#hiwork钉钉消息跳转前缀
dingdingUrlPrefix: "dingtalk://dingtalkclient/page/link?url="
# 汽车标准数字化平台ASMS
asms:
@@ -388,6 +388,12 @@ hiwork:
url: https://iam-uat.sinotruk.com:7011/idp/oauth2/authorize?&state=123&client_id=SRMS&response_type=code&redirect_uri=
fontUrl: http://srms-test.sinotruk.com{url}?projectId={projectId}&taskName={taskName}&taskId={taskId}&processInstanceId={processInstanceId}&nodeId={nodeId}
fontAppUrl: http://222.175.158.140:8120/mobile{url}?projectId={projectId}&taskName={taskName}&taskId={taskId}&processInstanceId={processInstanceId}&nodeId={nodeId}
# dingding和Hiwork是否发送消息
isHiworkDingDingSend: true
#hiwork消息跳转前缀
hiworkUrlPrefix: "http://srms-test.sinotruk.com"
#hiwork钉钉消息跳转前缀
dingdingUrlPrefix: "dingtalk://dingtalkclient/page/link?url="
# 汽车标准数字化平台ASMS
asms: