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

钉钉:支持链接消息

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