提交 263a308e 编写于 作者: zhouweidong's avatar zhouweidong

钉钉:支持链接消息

上级 73ba757a
......@@ -6,17 +6,43 @@ import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Map;
/**
* 消息对象:title.content.url参数只适用于钉钉消息,
* 以传入的参数内容覆盖模板中的内容;
* 其余类型消息则以模板内容为准。
*/
@Data
public class Msg {
/**
* 模板标识
*/
@NotBlank(message="模板标识不能为空")
private String templateid;
/**
* 发送消息类型
*/
@NotNull(message="模板类型不能为空")
private int msgtypes;
/**
* 消息接收用户
*/
@NotBlank(message="用户标识不能为空")
private String userids;
/**
* 消息标题
*/
private String title;
/**
* 消息内容
*/
private String content;
/**
* 消息链接
*/
private String url;
/**
* 消息模板参数
*/
private Map templparams;
}
......@@ -138,24 +138,38 @@ public class NotifyCoreService {
/**
* 发送钉钉消息
* @param msg
* @param tid
* @param userId
*/
@SneakyThrows
private boolean sendDingTalkMsg(String tid,String userId){
String authUserId=getAuthUserId(userId,MsgType.dingtalk);
private boolean sendDingTalkMsg(Msg msg,String tid){
String authUserId=getAuthUserId(msg.getUserids(),MsgType.dingtalk);
MsgTemplate template=templateService.get(tid);
MsgOpenAccess openAccess =template.getOpenaccess();
DingTalkClient client = new DefaultDingTalkClient(dingTalkSendMsgApi);
OapiMessageCorpconversationAsyncsendV2Request req = new OapiMessageCorpconversationAsyncsendV2Request();
req.setAgentId(Long.parseLong(template.getTemplateId()));
req.setUseridList(authUserId);
OapiMessageCorpconversationAsyncsendV2Request.Msg obj1 = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
obj1.setMsgtype("text");
OapiMessageCorpconversationAsyncsendV2Request.Msg dingtalkMsg = new OapiMessageCorpconversationAsyncsendV2Request.Msg();
if((!StringUtils.isEmpty(template.getTemplateUrl())) || (!StringUtils.isEmpty(msg.getUrl())) ){
//链接消息
dingtalkMsg.setMsgtype("link");
dingtalkMsg.setLink(new OapiMessageCorpconversationAsyncsendV2Request.Link());
dingtalkMsg.getLink().setTitle(StringUtils.isEmpty(msg.getTitle())?template.getTemplateName():msg.getTitle());
dingtalkMsg.getLink().setText(StringUtils.isEmpty(msg.getContent())?template.getContent():msg.getContent());
dingtalkMsg.getLink().setMessageUrl(StringUtils.isEmpty(msg.getUrl())?template.getTemplateUrl():msg.getUrl());
dingtalkMsg.getLink().setPicUrl("test");
req.setMsg(dingtalkMsg);
}else{
//文本消息
dingtalkMsg.setMsgtype("text");
OapiMessageCorpconversationAsyncsendV2Request.Text obj2 = new OapiMessageCorpconversationAsyncsendV2Request.Text();
obj2.setContent(template.getContent());
obj1.setText(obj2);
req.setMsg(obj1);
obj2.setContent(StringUtils.isEmpty(msg.getContent())?template.getContent():msg.getContent());
dingtalkMsg.setText(obj2);
req.setMsg(dingtalkMsg);
}
OapiMessageCorpconversationAsyncsendV2Response rsp = client.execute(req, openAccess.getAccessToken());
getResult(rsp.getBody());
return true;
......@@ -430,7 +444,7 @@ public class NotifyCoreService {
sendAliEMail(msgTemplate.getTid(),userIds);
break;
case "dingtalk-msg":
sendDingTalkMsg(msgTemplate.getTid(),userIds);
sendDingTalkMsg(msg,msgTemplate.getTid());
break;
case "wechat-msg":
sendWeChatMsg(msgTemplate.getTid(),userIds,getWechatMsgTemplParams(templParams));
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册