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

钉钉、微信、阿里消息集成

上级 c2b17b89
......@@ -9,9 +9,6 @@ import java.util.Map;
@Data
public class Msg {
@NotBlank(message="系统标识不能为空")
private String system;
@NotBlank(message="模板标识不能为空")
private String templateid;
......
......@@ -76,10 +76,10 @@ public class NotifyCoreService {
* 平台消息类型代码表
*/
private static Map<Integer,String> msgTypes = new HashMap(){{
put(2,"email");
put(4,"sms");
put(32,"wechat");
put(64,"dingtalk");
put(2,"aliyun-email");
put(4,"aliyun-sms");
put(32,"wechat-msg");
put(64,"dingtalk-msg");
}};
@Autowired
......@@ -314,7 +314,7 @@ public class NotifyCoreService {
* @return
*/
public boolean createMsgTemplate(Template template){
String system=template.getSystem() ;
String system=template.getSystem().toLowerCase();
JSONArray templates = template.getTemplate();
for(int a=0;a<templates.size();a++){
List<MsgOpenAccess> openAccesses=new ArrayList<>();
......@@ -328,15 +328,15 @@ public class NotifyCoreService {
openAccess.setId(system+templateType);
openAccess.setName(templateType);
openAccess.setDisabled(0);
openAccess.setOpenType(templateType);
openAccess.setOpenType(templateType.contains("-")?templateType.substring(0,templateType.indexOf("-")):templateType);
openAccesses.add(openAccess);
}
//创建消息模板
MsgTemplate msgTemplate =JSONObject.toJavaObject(templates.getJSONObject(a),MsgTemplate.class);
msgTemplate.setAccessId(openAccess.getId());
msgTemplate.setOpenType(templateType);
msgTemplate.setOpenType(templateType.contains("-")?templateType.substring(0,templateType.indexOf("-")):templateType);
msgTemplate.setTemplateType(templateType);
msgTemplate.setTid(system+msgTemplate.getTid()+templateType);
msgTemplate.setTid(msgTemplate.getTid()+templateType);
msgTemplates.add(msgTemplate);
}
if(openAccesses.size()>0)
......@@ -353,27 +353,26 @@ public class NotifyCoreService {
* @return
*/
public boolean sendMsg(Msg msg){
String system = msg.getSystem();
String templateId =msg.getTemplateid();
String userIds=msg.getUserids();
Map templParams=msg.getTemplparams();
for(String msgType:getMsgType(msg.getMsgtypes())){
MsgTemplate msgTemplate=templateService.getById(system+templateId+msgType);
MsgTemplate msgTemplate=templateService.getById(templateId+msgType);
if(msgTemplate==null){
throw new BadRequestAlertException(String.format("发送消息失败,无法获取到[%s]对应的rt模板",templateId),"","");
}
else{
switch(msgType){
case "sms":
case "aliyun-sms":
sendAliSms(msgTemplate.getTid(),userIds,templParams);
break;
case "email":
case "aliyun-email":
sendAliEMail(msgTemplate.getTid(),userIds);
break;
case "dingtalk":
case "dingtalk-msg":
sendDingTalkMsg(msgTemplate.getTid(),userIds);
break;
case "wechat":
case "wechat-msg":
sendWeChatMsg(msgTemplate.getTid(),userIds,templParams);
break;
default:
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册