短信对接
This commit is contained in:
@@ -31,79 +31,103 @@ import java.util.List;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class MsgApi {
|
public class MsgApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* token -redis - name
|
||||||
|
*/
|
||||||
|
private static final String msgTokenName = "msg_token";
|
||||||
|
|
||||||
private static final String APPID = "1197951921244139520";
|
private static final String APP_KEY = "10c51794-45b8-4de5-ba6f-b1ed843c20f3";
|
||||||
private static final String ACCESS_TOKEN = "54743e1fb7786457edf04cc7274d98d5";
|
private static final String APP_SECRET = "4acbf17e-4b17-4c47-b4bb-1576a066250a";
|
||||||
private static final String SCHOOL_CODE = "10295";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送消息api
|
* 发送消息api
|
||||||
*/
|
*/
|
||||||
private static final String MSG_API = "https://gateway.jiangnan.edu.cn/mp_message_pocket_web-mp-restful-message-send/ProxyService/message_pocket_web-mp-restful-message-sendProxyService";
|
private static final String MSG_API = "https://xxdb.hmc.edu.cn/msgInfo/pushMsgInfo";
|
||||||
|
|
||||||
|
private static final String TOKEN_API = "https://xxdb.hmc.edu.cn/accessSystem/getAccessToken";
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private RedisService redisService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息发送,url可不必填写
|
* @param channels 推送渠道 (INNER:站内消息; SMS:短信; Mail:邮件; WeChat:微信; DingTalk:钉钉;同时推送多个渠道用英文逗号分隔 )
|
||||||
*
|
* @param loginNames
|
||||||
* @param content (必填)消息内容
|
* @param mtype 消息类型; 0: 图文 1: 文字 2: 外链
|
||||||
* @param urlDesc Url链接的描述
|
* @param title 标题
|
||||||
* @param pcUrl pc端点击消息时的链接url
|
* @param content 内容
|
||||||
* @param mobileUrl 手机端点击消息时的链接url
|
* @param imageUrl 图片URL
|
||||||
* @param sendType (必填)0.PC门户通知和移动校园同时发送(通常为此种方式) 1.只发送PC门户 2.只发送移动校园 3.邮件 4.短信 5.微信企业号 6.钉钉企业内部应用工作通知 7.微信服务号 8.Welink
|
* @author zhf
|
||||||
* @param receivers (必填)收件人集合 包含三个字段(userId为必填,其余两个字段根据sengType填写): userId:收件人的userId(职工号或学号)、mobile:手机号、email:邮箱地址
|
* @description
|
||||||
*/
|
*/
|
||||||
public void sendMsg(String content, String urlDesc, String pcUrl, String mobileUrl, String sendType, List<NutMap> receivers) {
|
public void sendMsg(List<String> channels, String loginNames, Integer mtype, String title, String content, String imageUrl,String link) {
|
||||||
try {
|
try {
|
||||||
// if (!Globals.MyConfig.getBoolean("SendMsg")) {
|
if (!Globals.MyConfig.getBoolean("SendMsg")) {
|
||||||
// log.info("发送失败,消息暂未开启!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
log.info("发送失败,消息暂未开启!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (Globals.isEnv(Env.dev)) {
|
if (Globals.isEnv(Env.dev)) {
|
||||||
// log.info("开发模式不允许发送短信!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
log.info("开发模式不允许发送短信!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (StrUtil.isBlank(content) || StrUtil.isBlank(sendType) || Lang.isEmpty(receivers)) {
|
if (StrUtil.isBlank(title)||StrUtil.isBlank(content) ||Lang.isEmpty(channels) || Lang.isEmpty(loginNames)) {
|
||||||
// log.info("发送失败,缺少需要参数请检查!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
log.info("发送失败,缺少需要参数请检查!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
|
||||||
// return;
|
return;
|
||||||
// }
|
}
|
||||||
// NutMap nutMap = receivers.stream().findFirst().orElse(null);
|
|
||||||
// assert nutMap != null;
|
String msgToken = getMsgToken();
|
||||||
// //获取签名
|
NutMap map = new NutMap();
|
||||||
// String sign = SecureUtil.md5(ACCESS_TOKEN + SCHOOL_CODE + nutMap.getString("userId"));
|
map.put("channel", String.join(",", channels));
|
||||||
//
|
//推送范围(1:普通模式;2:全体教师;3:全体学生;4:全体人员)
|
||||||
// NutMap dataMap = new NutMap();
|
map.put("objScope", 1);
|
||||||
// dataMap.setv("schoolCode", SCHOOL_CODE);
|
map.put("objIds", loginNames);
|
||||||
// dataMap.setv("sign", sign);
|
map.put("mtype", mtype);
|
||||||
// dataMap.setv("content", content);
|
map.put("sendStatus", 1);
|
||||||
// dataMap.setv("sendType", sendType);
|
map.put("title", title);
|
||||||
// dataMap.setv("receiverType", 1);
|
map.put("content", content);
|
||||||
// dataMap.setv("urlDesc", Strings.isNotBlank(urlDesc) ? urlDesc : "");
|
map.put("imageUrl", imageUrl);
|
||||||
// dataMap.setv("pcUrl", Strings.isNotBlank(pcUrl) ? pcUrl : "");
|
map.put("link", link);
|
||||||
// dataMap.setv("mobileUrl", Strings.isNotBlank(mobileUrl) ? mobileUrl : "");
|
|
||||||
// dataMap.setv("receivers", receivers);
|
/*HttpRequest request = HttpUtil.createPost(MSG_API)
|
||||||
//
|
.header("token", msgToken)
|
||||||
// log.info(Json.toJson(dataMap));
|
.body(Json.toJson(map));
|
||||||
//
|
JSONObject jsonObject = JSON.parseObject(request.execute().body());
|
||||||
// HttpRequest request = HttpUtil.createPost(MSG_API)
|
int status = jsonObject.getInteger("code");
|
||||||
// .header("appId", APPID)
|
|
||||||
// .header("accessToken", ACCESS_TOKEN)
|
if (status == 200) {
|
||||||
// .body(Json.toJson(dataMap));
|
log.info("发送成功>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
||||||
//
|
} else {
|
||||||
// JSONObject jsonObject = JSON.parseObject(request.execute().body());
|
log.info("发送失败>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
||||||
// int status = jsonObject.getInteger("status");
|
throw new RuntimeException("Message sending failed with status code: " + status + ", Message: " + jsonObject.getString("message"));
|
||||||
//
|
}*/
|
||||||
// if (status == 200) {
|
|
||||||
// log.info("发送成功>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
||||||
// } else {
|
|
||||||
// log.info("发送失败>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
|
|
||||||
// throw new RuntimeException("Message sending failed with status code: " + status + ", Message: " + jsonObject.getString("msg"));
|
|
||||||
// }
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String getMsgToken() {
|
||||||
|
String token = redisService.get(msgTokenName);
|
||||||
|
if (StrUtil.isBlank(token)) {
|
||||||
|
String body = HttpRequest.post(TOKEN_API + "?appKey=" + APP_KEY + "&appSecret=" + APP_SECRET).execute().body();
|
||||||
|
NutMap map = Json.fromJson(NutMap.class, body);
|
||||||
|
if (map.getInt("code") == 200) {
|
||||||
|
NutMap data = Json.fromJson(NutMap.class, map.getString("data"));
|
||||||
|
token = data.getString("accessToken");
|
||||||
|
redisService.setex(msgTokenName, 3600, token);
|
||||||
|
} else {
|
||||||
|
token = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,9 +169,9 @@ public class LxyHdTjController {
|
|||||||
List<Lxy_bm> grxxes = lxyGrxxService.dao().query(Lxy_bm.class, Cnd.where("hdid", "=", hdid).and("bmzt", "=", 5));
|
List<Lxy_bm> grxxes = lxyGrxxService.dao().query(Lxy_bm.class, Cnd.where("hdid", "=", hdid).and("bmzt", "=", 5));
|
||||||
List<String> loginnames = grxxes.stream().map(Lxy_bm::getLoginname).collect(Collectors.toList());
|
List<String> loginnames = grxxes.stream().map(Lxy_bm::getLoginname).collect(Collectors.toList());
|
||||||
loginnames.forEach(loginname -> {
|
loginnames.forEach(loginname -> {
|
||||||
msgApi.sendMsg(content, "", "", "", "4", new ArrayList<>() {{
|
/* msgApi.sendMsg(content, "", "", "", "4", new ArrayList<>() {{
|
||||||
add(NutMap.NEW().addv("userId", loginname));
|
add(NutMap.NEW().addv("userId", loginname));
|
||||||
}});
|
}});*/
|
||||||
});
|
});
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -125,19 +125,19 @@ public class MsgNotifyServiceImpl extends ViServiceImpl<MsgNotify> implements Ms
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (sendTypes.contains("0")) {
|
if (sendTypes.contains("0")) {
|
||||||
msgApi.sendMsg(content, null, null, null, "0", receivers);
|
// msgApi.sendMsg(content, null, null, null, "0", receivers);
|
||||||
}
|
}
|
||||||
if (sendTypes.contains("1")) {
|
if (sendTypes.contains("1")) {
|
||||||
msgApi.sendMsg(content, null, null, null, "1", receivers);
|
// msgApi.sendMsg(content, null, null, null, "1", receivers);
|
||||||
}
|
}
|
||||||
if (sendTypes.contains("2")) {
|
if (sendTypes.contains("2")) {
|
||||||
msgApi.sendMsg(content, null, null, null, "2", receivers);
|
// msgApi.sendMsg(content, null, null, null, "2", receivers);
|
||||||
}
|
}
|
||||||
if (sendTypes.contains("4")) {
|
if (sendTypes.contains("4")) {
|
||||||
msgApi.sendMsg(content, null, null, null, "4", receivers);
|
// msgApi.sendMsg(content, null, null, null, "4", receivers);
|
||||||
}
|
}
|
||||||
if (sendTypes.contains("5")) {
|
if (sendTypes.contains("5")) {
|
||||||
msgApi.sendMsg(content, null, null, null, "5", receivers);
|
// msgApi.sendMsg(content, null, null, null, "5", receivers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.start();
|
}.start();
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import io.v.nutz.base.dao.CndPlus;
|
|||||||
import io.v.nutz.base.query.PageForm;
|
import io.v.nutz.base.query.PageForm;
|
||||||
import io.v.nutz.sys.models.Sys_home_activity;
|
import io.v.nutz.sys.models.Sys_home_activity;
|
||||||
import io.v.nutz.task.services.TaskPlatformService;
|
import io.v.nutz.task.services.TaskPlatformService;
|
||||||
|
import io.v.nutz.web.commons.base.Globals;
|
||||||
import io.v.nutz.zhgh.data.model.MatchConditionStructure;
|
import io.v.nutz.zhgh.data.model.MatchConditionStructure;
|
||||||
import io.v.nutz.zhgh.data.service.MatchConditionStructureService;
|
import io.v.nutz.zhgh.data.service.MatchConditionStructureService;
|
||||||
import io.v.nutz.zhgh.mobileHome.service.MobileHomeService;
|
import io.v.nutz.zhgh.mobileHome.service.MobileHomeService;
|
||||||
@@ -42,10 +43,7 @@ import org.nutz.mvc.annotation.Ok;
|
|||||||
import org.nutz.mvc.annotation.Param;
|
import org.nutz.mvc.annotation.Param;
|
||||||
import org.nutz.trans.Trans;
|
import org.nutz.trans.Trans;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,7 +261,7 @@ public class WelfareProjectMangeController {
|
|||||||
projectService.dao().delete(MatchConditionStructure.class, project.getConditionStructureId());
|
projectService.dao().delete(MatchConditionStructure.class, project.getConditionStructureId());
|
||||||
}
|
}
|
||||||
projectService.dao().clear(WelfareProjectSubject.class, Cnd.where("projectId", "=", id));
|
projectService.dao().clear(WelfareProjectSubject.class, Cnd.where("projectId", "=", id));
|
||||||
if(ObjectUtil.isNotEmpty(welfareProjectSubject)){
|
if (ObjectUtil.isNotEmpty(welfareProjectSubject)) {
|
||||||
projectService.dao().clear(WelfareProjectSubjectOption.class, Cnd.where("subjectId", "=", welfareProjectSubject.getId()));
|
projectService.dao().clear(WelfareProjectSubjectOption.class, Cnd.where("subjectId", "=", welfareProjectSubject.getId()));
|
||||||
}
|
}
|
||||||
projectService.dao().clear(WelfareUserSelection.class, Cnd.where("welfareId", "=", id));
|
projectService.dao().clear(WelfareUserSelection.class, Cnd.where("welfareId", "=", id));
|
||||||
@@ -301,7 +299,7 @@ public class WelfareProjectMangeController {
|
|||||||
public Object sendMsgToNotWelfareUsers(String projectId, String sendMsgValue) {
|
public Object sendMsgToNotWelfareUsers(String projectId, String sendMsgValue) {
|
||||||
Sql sql = Sqls.create("""
|
Sql sql = Sqls.create("""
|
||||||
SELECT
|
SELECT
|
||||||
u.loginname as userId
|
u.loginname
|
||||||
FROM
|
FROM
|
||||||
welfare_list wl
|
welfare_list wl
|
||||||
left join sys_user u on u.id = wl.userId
|
left join sys_user u on u.id = wl.userId
|
||||||
@@ -318,7 +316,13 @@ public class WelfareProjectMangeController {
|
|||||||
""");
|
""");
|
||||||
sql.setParam("projectId", projectId);
|
sql.setParam("projectId", projectId);
|
||||||
List<NutMap> userList = listService.listMap(sql);
|
List<NutMap> userList = listService.listMap(sql);
|
||||||
msgApi.sendMsg(sendMsgValue, "福利选择链接", "", "https://zhgh.jiangnan.edu.cn/mobile/welfare/list/receive?projectId=4fa233704ddb41bc8e34e966efeda0a4", "4", userList);
|
Set<String> loginNameList = userList.stream().map(user -> user.getString("loginname")).collect(Collectors.toSet());
|
||||||
|
String loginNames = loginNameList.stream().collect(Collectors.joining(","));
|
||||||
|
|
||||||
|
WelfareProject project = dao.fetch(WelfareProject.class, projectId);
|
||||||
|
String link = Globals.AppDomain + "/mobile/welfare/list/receive?projectId=%s".formatted(projectId);
|
||||||
|
String imageUrl = Globals.AppDomain + "/file_server/fileStreamPreview?id=" + project.getCover();
|
||||||
|
msgApi.sendMsg(List.of("DingTalk"), loginNames, 0, "职工福利", sendMsgValue, imageUrl, link);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -464,9 +464,9 @@ public class RxdjShController {
|
|||||||
sql.setParam("year", year);
|
sql.setParam("year", year);
|
||||||
List<Record> list = baseService.list(sql);
|
List<Record> list = baseService.list(sql);
|
||||||
for (Record r : list) {
|
for (Record r : list) {
|
||||||
msgApi.sendMsg(content, "", "", "", "4", new ArrayList<>() {{
|
/* msgApi.sendMsg(content, "", "", "", "4", new ArrayList<>() {{
|
||||||
add(NutMap.NEW().addv("userId", r.getString("loginname")));
|
add(NutMap.NEW().addv("userId", r.getString("loginname")));
|
||||||
}});
|
}});*/
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -458,16 +458,16 @@ layout("/layouts/platform.html"){
|
|||||||
>
|
>
|
||||||
<el-form :model="formData" label-width="80px" ref="sendForm">
|
<el-form :model="formData" label-width="80px" ref="sendForm">
|
||||||
|
|
||||||
<el-form-item
|
<!-- <el-form-item
|
||||||
:rules="[{required: true, message: '请选择发送方式', trigger: ['blur', 'change']}]"
|
:rules="[{required: true, message: '请选择发送方式', trigger: ['blur', 'change']}]"
|
||||||
label="发送方式"
|
label="发送方式"
|
||||||
prop="sendTypes">
|
prop="sendTypes">
|
||||||
<el-checkbox-group size="medium" v-model="formData.sendTypes">
|
<el-checkbox-group size="medium" v-model="formData.sendTypes">
|
||||||
<el-checkbox border label="1">短信发送</el-checkbox>
|
<el-checkbox border label="SMS">短信发送</el-checkbox>
|
||||||
<el-checkbox border label="4">微信发送</el-checkbox>
|
<el-checkbox border label="WeChat">微信发送</el-checkbox>
|
||||||
</el-checkbox-group>
|
</el-checkbox-group>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
-->
|
||||||
<el-form-item
|
<el-form-item
|
||||||
:rules="[{required: true, message: '请选择发送内容', trigger: ['blur', 'change']}]"
|
:rules="[{required: true, message: '请选择发送内容', trigger: ['blur', 'change']}]"
|
||||||
label="发送内容"
|
label="发送内容"
|
||||||
|
|||||||
Reference in New Issue
Block a user