This commit is contained in:
Paidax
2025-02-20 13:56:04 +08:00
parent 409ff2e0bb
commit bce946e651
189 changed files with 9732 additions and 4037 deletions
+46 -46
View File
@@ -47,57 +47,57 @@ public class MsgApi {
/**
* @param channels 推送渠道 (INNER:站内消息; SMS:短信; Mail:邮件; WeChat:微信; DingTalk:钉钉;同时推送多个渠道用英文逗号分隔 )
* @param loginNameStr 字符串,多个工号用英文逗号分隔 ","
* @param mtype 消息类型; 0: 图文 1: 文字 2: 外链
* @param title 标题
* @param content 内容
* @param imageUrl 图片URL
* @param channels 推送渠道 (INNER:站内消息; SMS:短信; Mail:邮件; WeChat:微信; DingTalk:钉钉;同时推送多个渠道用英文逗号分隔 )
* @param loginNameStr 字符串,多个工号用英文逗号分隔 ","
* @param mtype 消息类型; 0: 图文 1: 文字 2: 外链
* @param title 标题
* @param content 内容
* @param imageUrl 图片URL
* @author zhf
* @description
*/
public void sendMsg(List<String> channels, String loginNameStr, Integer mtype, String title, String content, String imageUrl,String link) {
try {
if (!Globals.MyConfig.getBoolean("SendMsg")) {
log.info("发送失败,消息暂未开启!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return;
}
if (Globals.isEnv(Env.dev)) {
log.info("开发模式不允许发送短信!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return;
}
if (StrUtil.isBlank(title)||StrUtil.isBlank(content) ||Lang.isEmpty(channels) || Lang.isEmpty(loginNameStr)) {
log.info("发送失败,缺少需要参数请检查!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
return;
}
String msgToken = getMsgToken();
NutMap map = new NutMap();
map.put("channel", String.join(",", channels));
//推送范围(1:普通模式;2:全体教师;3:全体学生;4:全体人员)
map.put("objScope", 1);
map.put("objIds", loginNameStr);
map.put("mtype", mtype);
map.put("sendStatus", 1);
map.put("title", title);
map.put("content", content);
map.put("imageUrl", imageUrl);
map.put("link", link);
HttpRequest request = HttpUtil.createPost(MSG_API)
.header("token", msgToken)
.body(Json.toJson(map));
JSONObject jsonObject = JSON.parseObject(request.execute().body());
int status = jsonObject.getInteger("code");
if (status == 200) {
log.info("发送成功>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
} else {
log.info("发送失败>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
throw new RuntimeException("Message sending failed with status code: " + status + ", Message: " + jsonObject.getString("message"));
}
// if (!Globals.MyConfig.getBoolean("SendMsg")) {
// log.info("发送失败,消息暂未开启!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// return;
// }
//
// if (Globals.isEnv(Env.dev)) {
// log.info("开发模式不允许发送短信!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// return;
// }
//
// if (StrUtil.isBlank(title)||StrUtil.isBlank(content) ||Lang.isEmpty(channels) || Lang.isEmpty(loginNameStr)) {
// log.info("发送失败,缺少需要参数请检查!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
// return;
// }
//
// String msgToken = getMsgToken();
// NutMap map = new NutMap();
// map.put("channel", String.join(",", channels));
// //推送范围(1:普通模式;2:全体教师;3:全体学生;4:全体人员)
// map.put("objScope", 1);
// map.put("objIds", loginNameStr);
// map.put("mtype", mtype);
// map.put("sendStatus", 1);
// map.put("title", title);
// map.put("content", content);
// map.put("imageUrl", imageUrl);
// map.put("link", link);
//
// HttpRequest request = HttpUtil.createPost(MSG_API)
// .header("token", msgToken)
// .body(Json.toJson(map));
// JSONObject jsonObject = JSON.parseObject(request.execute().body());
// int status = jsonObject.getInteger("code");
//
// if (status == 200) {
// log.info("发送成功>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
// } else {
// log.info("发送失败>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
// throw new RuntimeException("Message sending failed with status code: " + status + ", Message: " + jsonObject.getString("message"));
// }
} catch (Exception e) {
e.printStackTrace();
}