fix发送通知消息,通知场馆负责人
This commit is contained in:
@@ -19,4 +19,7 @@ public class Constants {
|
|||||||
public static final String LESSON_TICKET_LOCK_KEY = "LESSON_TICKET_LOCK_";
|
public static final String LESSON_TICKET_LOCK_KEY = "LESSON_TICKET_LOCK_";
|
||||||
|
|
||||||
// public static final String EXCEL_PATH = "/opt/excel/";
|
// public static final String EXCEL_PATH = "/opt/excel/";
|
||||||
|
|
||||||
|
public static final String VENUE_VIEW_URL = "https://api.hongyutiyu.top/getLessonOrder/";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ import com.sv.dto.api.wechat.OrderPaySignResponse;
|
|||||||
import com.sv.entity.*;
|
import com.sv.entity.*;
|
||||||
import com.sv.exception.api.ExceptionCodeTemplate;
|
import com.sv.exception.api.ExceptionCodeTemplate;
|
||||||
import com.sv.mapper.MemberLessonTicketMapper;
|
import com.sv.mapper.MemberLessonTicketMapper;
|
||||||
import com.sv.service.api.util.AsyncTaskUtil;
|
|
||||||
import com.sv.service.api.util.DateUtilCard;
|
import com.sv.service.api.util.DateUtilCard;
|
||||||
import com.sv.service.common.RedisLock;
|
import com.sv.service.common.RedisLock;
|
||||||
|
import com.sv.service.message.AsyncTaskUtil;
|
||||||
|
import com.sv.service.message.NotifyAdminMsgThread;
|
||||||
import com.ydd.framework.core.common.Pagination;
|
import com.ydd.framework.core.common.Pagination;
|
||||||
import com.ydd.framework.core.common.utils.ValidationUtils;
|
import com.ydd.framework.core.common.utils.ValidationUtils;
|
||||||
import com.ydd.framework.core.entity.enums.DeletedEnum;
|
import com.ydd.framework.core.entity.enums.DeletedEnum;
|
||||||
@@ -386,10 +387,24 @@ public class MemberLessonTicketService extends BaseServiceImpl {
|
|||||||
return orderSn;
|
return orderSn;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 发送消息给运动员*/
|
/* 发送消息给管理员*/
|
||||||
private void sendMessageToVenue(List<MemberLessonTicket> memberLessonTickets) {
|
private void sendMessageToVenue(List<MemberLessonTicket> memberLessonTickets) {
|
||||||
// TODO 需要发送通知
|
for (MemberLessonTicket ticket : memberLessonTickets) {
|
||||||
// AsyncTaskUtil.INSTANCE.submit();
|
Integer lessonId = ticket.getLessonId();
|
||||||
|
Integer venueId = ticket.getVenueId();
|
||||||
|
Venue venue = venueService.findById(venueId);
|
||||||
|
if (venue == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VenueLesson venueLesson = venueLessonService.findById(lessonId);
|
||||||
|
if (venueLesson == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String lessonTime = DateUtilCard.getStrFromDate(venueLesson.getDate()) + " " + venueLesson.getStartTime().toString() + "-" + venueLesson.getEndTime().toString();
|
||||||
|
String typeName = VenueTypeEnum.getByValue(venue.getType()).name;
|
||||||
|
String url = Constants.VENUE_VIEW_URL + venueId;
|
||||||
|
AsyncTaskUtil.INSTANCE.submit(new NotifyAdminMsgThread(venue.getName(),venueLesson.getName(),lessonTime,typeName,url));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
package com.sv.service.api.config;
|
|
||||||
|
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
|
|
||||||
public class NotifyAdminMsgThread extends Thread{
|
|
||||||
|
|
||||||
private String openId = "";
|
|
||||||
private String webHook = "";
|
|
||||||
private String dingSecret = "";
|
|
||||||
|
|
||||||
public String getOpenId() {
|
|
||||||
return openId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setOpenId(String openId) {
|
|
||||||
this.openId = openId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getWebHook() {
|
|
||||||
return webHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setWebHook(String webHook) {
|
|
||||||
this.webHook = webHook;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDingSecret() {
|
|
||||||
return dingSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setDingSecret(String dingSecret) {
|
|
||||||
this.dingSecret = dingSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
public NotifyAdminMsgThread(String openId, String webHook, String dingSecret) {
|
|
||||||
this.openId = openId;
|
|
||||||
this.webHook = webHook;
|
|
||||||
this.dingSecret = dingSecret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!StringUtils.isEmpty(openId)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package com.sv.service.api.util;
|
|
||||||
|
|
||||||
import com.sv.service.common.DingTalkMsg;
|
|
||||||
import com.sv.service.utils.HttpClientUtils;
|
|
||||||
import com.ydd.framework.core.common.utils.JsonUtils;
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import javax.crypto.Mac;
|
|
||||||
import javax.crypto.spec.SecretKeySpec;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
|
|
||||||
public class DingTalkSignUtils {
|
|
||||||
|
|
||||||
private static final String WEBHOOK = "https://oapi.dingtalk.com/robot/send?access_token=4d661fd412a3baa1712bd29ef01d86277fec495441430267df1bbe206337dbfa";
|
|
||||||
|
|
||||||
private static final String SECRET = "SEC5854845f8d47522d54ef85be26945e1cc78e25b4d0f87f6308cc35637fc58534";
|
|
||||||
|
|
||||||
private static final String TIME_LINK = "×tamp=";
|
|
||||||
|
|
||||||
private static final String SIGN_LINK = "&sign=";
|
|
||||||
|
|
||||||
private static String signUrl(String webhook) throws Exception {
|
|
||||||
Long timestamp = System.currentTimeMillis();
|
|
||||||
String stringToSign = timestamp + "\n" + SECRET;
|
|
||||||
Mac mac = Mac.getInstance("HmacSHA256");
|
|
||||||
mac.init(new SecretKeySpec(SECRET.getBytes("UTF-8"), "HmacSHA256"));
|
|
||||||
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
|
|
||||||
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8");
|
|
||||||
return webhook + TIME_LINK + timestamp + SIGN_LINK + sign;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendDingTalk() throws Exception {
|
|
||||||
DingTalkMsg msg3 = new DingTalkMsg();
|
|
||||||
msg3.sendSingleActionCard("预定提醒","您好!系统检测到有用户xiaoming刚刚在场馆**长宁运动馆**预定了时间段1-时间段2的**我的什么什么的**课程,请及时关注。","https://api.hongyutiyu.top/getLessonOrder/46");
|
|
||||||
String r3 = HttpClientUtils.doPostJson(signUrl(WEBHOOK), JsonUtils.encode(msg3));
|
|
||||||
System.out.println("发送消息=============" + r3);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
sendDingTalk();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -109,7 +109,7 @@ public class DingTalkMsg implements Serializable {
|
|||||||
ActionCard actionCard = new ActionCard();
|
ActionCard actionCard = new ActionCard();
|
||||||
actionCard.setTitle(title);
|
actionCard.setTitle(title);
|
||||||
actionCard.setText(content);
|
actionCard.setText(content);
|
||||||
actionCard.setSingleTitle("阅读全文");
|
actionCard.setSingleTitle("查看详情");
|
||||||
actionCard.setSingleURL(linkUrl);
|
actionCard.setSingleURL(linkUrl);
|
||||||
this.actionCard = actionCard;
|
this.actionCard = actionCard;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.sv.service.api.util;
|
package com.sv.service.message;
|
||||||
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.sv.service.message;
|
||||||
|
|
||||||
|
import com.sv.service.common.DingTalkMsg;
|
||||||
|
import com.sv.service.utils.HttpClientUtils;
|
||||||
|
import com.ydd.framework.core.common.utils.JsonUtils;
|
||||||
|
import org.apache.commons.codec.binary.Base64;
|
||||||
|
import javax.crypto.Mac;
|
||||||
|
import javax.crypto.spec.SecretKeySpec;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.text.MessageFormat;
|
||||||
|
|
||||||
|
public class DingTalkSignUtils {
|
||||||
|
|
||||||
|
private static final String TIME_LINK = "×tamp=";
|
||||||
|
|
||||||
|
private static final String SIGN_LINK = "&sign=";
|
||||||
|
|
||||||
|
private static String signUrl(String webhook,String secret) throws Exception {
|
||||||
|
Long timestamp = System.currentTimeMillis();
|
||||||
|
String stringToSign = timestamp + "\n" + secret;
|
||||||
|
Mac mac = Mac.getInstance("HmacSHA256");
|
||||||
|
mac.init(new SecretKeySpec(secret.getBytes("UTF-8"), "HmacSHA256"));
|
||||||
|
byte[] signData = mac.doFinal(stringToSign.getBytes("UTF-8"));
|
||||||
|
String sign = URLEncoder.encode(new String(Base64.encodeBase64(signData)), "UTF-8");
|
||||||
|
return webhook + TIME_LINK + timestamp + SIGN_LINK + sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendDingTalk(SendMsg sendMsg,String webhook,String secret) throws Exception {
|
||||||
|
DingTalkMsg msg3 = new DingTalkMsg();
|
||||||
|
String messageTemple = "您好!系统检测到有用户在 {0} 场馆预定了 {1} 的 {2} 课程,请及时关注!";
|
||||||
|
String format = MessageFormat.format(messageTemple, sendMsg.getVenueName(), sendMsg.getLessonTime(), sendMsg.getLessonName());
|
||||||
|
msg3.sendSingleActionCard("预定提醒",
|
||||||
|
format
|
||||||
|
,sendMsg.getViewUrl());
|
||||||
|
String r3 = HttpClientUtils.doPostJson(signUrl(webhook,secret), JsonUtils.encode(msg3));
|
||||||
|
System.out.println("发送消息=============" + r3);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,106 @@
|
|||||||
|
package com.sv.service.message;
|
||||||
|
|
||||||
|
import com.dw.ccm.wechat.base.utils.JsonUtils;
|
||||||
|
import com.sv.mapper.ConfigMapper;
|
||||||
|
import com.sv.service.utils.SpringUtils;
|
||||||
|
import com.ydd.oms.entity.sys.Config;
|
||||||
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class NotifyAdminMsgThread extends Thread{
|
||||||
|
|
||||||
|
private String venueName = "";
|
||||||
|
private String lessonName = "";
|
||||||
|
private String lessonTime = "";
|
||||||
|
private String venueType = "";
|
||||||
|
private String url = "";
|
||||||
|
|
||||||
|
public NotifyAdminMsgThread(String venueName, String lessonName, String lessonTime, String venueType, String url) {
|
||||||
|
this.venueName = venueName;
|
||||||
|
this.lessonName = lessonName;
|
||||||
|
this.lessonTime = lessonTime;
|
||||||
|
this.venueType = venueType;
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVenueName() {
|
||||||
|
return venueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVenueName(String venueName) {
|
||||||
|
this.venueName = venueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonName() {
|
||||||
|
return lessonName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonName(String lessonName) {
|
||||||
|
this.lessonName = lessonName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonTime() {
|
||||||
|
return lessonTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonTime(String lessonTime) {
|
||||||
|
this.lessonTime = lessonTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVenueType() {
|
||||||
|
return venueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVenueType(String venueType) {
|
||||||
|
this.venueType = venueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
|
ConfigMapper configMapper = SpringUtils.getBean(ConfigMapper.class);
|
||||||
|
List<Config> all = configMapper.findAll();
|
||||||
|
if (all == null || all.size() <= 0 ){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
String openId = null;
|
||||||
|
String webHook = null;
|
||||||
|
String dingSecret = null;
|
||||||
|
for (Config config : all) {
|
||||||
|
if ("WX_ADMIN".equals(config.getKey())) {
|
||||||
|
openId = config.getValue();
|
||||||
|
}
|
||||||
|
if ("DING_WEBHOOK".equals(config.getKey())) {
|
||||||
|
webHook = config.getValue();
|
||||||
|
}
|
||||||
|
if ("DING_SECRET".equals(config.getKey())) {
|
||||||
|
dingSecret = config.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SendMsg sendMsg = new SendMsg(venueName,lessonName,lessonTime,venueType,url);
|
||||||
|
if (!StringUtils.isEmpty(openId)) {
|
||||||
|
String[] split = openId.split(",");
|
||||||
|
for (String s : split) {
|
||||||
|
WeiXinSendUtils.sendCard(sendMsg,s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!StringUtils.isEmpty(webHook) && !StringUtils.isEmpty(dingSecret)) {
|
||||||
|
// 发送钉钉机器人消息
|
||||||
|
try {
|
||||||
|
DingTalkSignUtils.sendDingTalk(sendMsg,webHook,dingSecret);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("发送钉钉消息失败!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
57
service/src/main/java/com/sv/service/message/SendMsg.java
Normal file
57
service/src/main/java/com/sv/service/message/SendMsg.java
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package com.sv.service.message;
|
||||||
|
|
||||||
|
public class SendMsg {
|
||||||
|
private String venueName;
|
||||||
|
private String lessonName;
|
||||||
|
private String lessonTime;
|
||||||
|
private String venueType;
|
||||||
|
private String viewUrl;
|
||||||
|
|
||||||
|
public SendMsg(String venueName, String lessonName, String lessonTime, String venueType, String viewUrl) {
|
||||||
|
this.venueName = venueName;
|
||||||
|
this.lessonName = lessonName;
|
||||||
|
this.lessonTime = lessonTime;
|
||||||
|
this.venueType = venueType;
|
||||||
|
this.viewUrl = viewUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getViewUrl() {
|
||||||
|
return viewUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setViewUrl(String viewUrl) {
|
||||||
|
this.viewUrl = viewUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVenueName() {
|
||||||
|
return venueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVenueName(String venueName) {
|
||||||
|
this.venueName = venueName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonName() {
|
||||||
|
return lessonName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonName(String lessonName) {
|
||||||
|
this.lessonName = lessonName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLessonTime() {
|
||||||
|
return lessonTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLessonTime(String lessonTime) {
|
||||||
|
this.lessonTime = lessonTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVenueType() {
|
||||||
|
return venueType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVenueType(String venueType) {
|
||||||
|
this.venueType = venueType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package com.sv.service.api.util;
|
package com.sv.service.message;
|
||||||
|
|
||||||
import com.dw.ccm.wechat.base.WeChat;
|
import com.dw.ccm.wechat.base.WeChat;
|
||||||
import com.dw.ccm.wechat.base.WeChatHelper;
|
import com.dw.ccm.wechat.base.WeChatHelper;
|
||||||
@@ -11,27 +11,22 @@ import java.util.HashMap;
|
|||||||
|
|
||||||
public class WeiXinSendUtils {
|
public class WeiXinSendUtils {
|
||||||
|
|
||||||
public static void sendCard(String webhook){
|
public static void sendCard(SendMsg sendMsg,String openId){
|
||||||
AccessTokenResponse accessToken = WeChatHelper.getAccessToken("wx51d82eba3f5f4858", "d28320bcb885cc208b6fde2253d8663e");
|
AccessTokenResponse accessToken = WeChatHelper.getAccessToken("wx51d82eba3f5f4858", "d28320bcb885cc208b6fde2253d8663e");
|
||||||
String token = accessToken.getAccessToken();
|
String token = accessToken.getAccessToken();
|
||||||
if (!StringUtils.isEmpty(token)){
|
if (!StringUtils.isEmpty(token)){
|
||||||
WeChat weChat = WeChatHelper.getWeChat(token);
|
WeChat weChat = WeChatHelper.getWeChat(token);
|
||||||
TemplateMessage templateMessage = new TemplateMessage();
|
TemplateMessage templateMessage = new TemplateMessage();
|
||||||
templateMessage.setTemplateId("vPRolOW7D3jnXhT4uqN4FOcIIuHcsHuresbZjlPBg9Y");
|
templateMessage.setTemplateId("vPRolOW7D3jnXhT4uqN4FOcIIuHcsHuresbZjlPBg9Y");
|
||||||
templateMessage.setToUser("o81UzwYksMMqbNJgsOvyjhbk-7b0");
|
templateMessage.setToUser(openId);
|
||||||
templateMessage.setUrl("");
|
templateMessage.setUrl(sendMsg.getViewUrl());
|
||||||
HashMap<String, Attribute> attr = new HashMap<>();
|
HashMap<String, Attribute> attr = new HashMap<>();
|
||||||
attr.put("thing2",new Attribute("啦啦啦德玛西亚",""));
|
attr.put("thing2",new Attribute(sendMsg.getVenueName(),""));
|
||||||
attr.put("thing3",new Attribute("dadasd",""));
|
attr.put("thing3",new Attribute(sendMsg.getLessonName(),""));
|
||||||
attr.put("time5",new Attribute("2014年9月22日",""));
|
attr.put("time5",new Attribute(sendMsg.getLessonTime(),""));
|
||||||
attr.put("phrase7",new Attribute("你好",""));
|
attr.put("phrase7",new Attribute(sendMsg.getVenueType(),""));
|
||||||
templateMessage.setAttributes(attr);
|
templateMessage.setAttributes(attr);
|
||||||
weChat.sendTemplate(templateMessage);
|
weChat.sendTemplate(templateMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
sendCard("");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
34
service/src/main/java/com/sv/service/utils/SpringUtils.java
Normal file
34
service/src/main/java/com/sv/service/utils/SpringUtils.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package com.sv.service.utils;
|
||||||
|
|
||||||
|
import org.springframework.beans.BeansException;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class SpringUtils implements ApplicationContextAware {
|
||||||
|
|
||||||
|
private static ApplicationContext applicationContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 从静态变量applicationContext中取得Bean, 自动转型为所赋值对象的类型.
|
||||||
|
*/
|
||||||
|
public static<T> T getBean(Class<T> tClass) {
|
||||||
|
return getApplicationContext().getBean(tClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static<T> T getBean(String name,Class<T> tClass) {
|
||||||
|
return getApplicationContext().getBean(name,tClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
|
if (SpringUtils.applicationContext == null){
|
||||||
|
SpringUtils.applicationContext = applicationContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ApplicationContext getApplicationContext() {
|
||||||
|
return applicationContext;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user