fix发送通知消息,通知场馆负责人

This commit is contained in:
2023-07-19 00:37:07 +08:00
parent 66baa6ab23
commit 571d4512db
7 changed files with 608 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ import com.sv.dto.api.wechat.OrderPaySignResponse;
import com.sv.entity.*;
import com.sv.exception.api.ExceptionCodeTemplate;
import com.sv.mapper.MemberLessonTicketMapper;
import com.sv.service.api.util.AsyncTaskUtil;
import com.sv.service.api.util.DateUtilCard;
import com.sv.service.common.RedisLock;
import com.ydd.framework.core.common.Pagination;
@@ -28,6 +29,7 @@ import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
@@ -364,7 +366,7 @@ public class MemberLessonTicketService extends BaseServiceImpl {
// 3.创建用户预约的场馆课程票号
orderSn = orderService.createSn(); //预约课程支付订单号
createMemberLessonTicket(memberId, tickets, lessonTicketOrderDTO.getLessonId(), orderSn, MemberLessonTicketTypeEnum.MEMBER_CARD.value, platformId, lessonTicketOrderDTO.getMemberCardId());
List<MemberLessonTicket> memberLessonTicket = createMemberLessonTicket(memberId, tickets, lessonTicketOrderDTO.getLessonId(), orderSn, MemberLessonTicketTypeEnum.MEMBER_CARD.value, platformId, lessonTicketOrderDTO.getMemberCardId());
// 4.创建订单记录
// 订单总价格
@@ -377,25 +379,31 @@ public class MemberLessonTicketService extends BaseServiceImpl {
// 6.修改课程销售数量
venueLessonService.updateSaleNumById(lessonTicketOrderDTO.getLessonId(), lessonTicketOrderDTO.getNum(), venueLesson);
sendMessageToVenue(memberLessonTicket);
}
return orderSn;
}
/* 发送消息给运动员*/
private void sendMessageToVenue(List<MemberLessonTicket> memberLessonTickets) {
// TODO 需要发送通知
// AsyncTaskUtil.INSTANCE.submit();
}
/**
* 创建用户预约的场馆课程票号记录
*/
@Transactional
public void createMemberLessonTicket(Integer memberId, List<VenueLessonTicket> tickets, Integer lessonId, String orderSn,
public List<MemberLessonTicket> createMemberLessonTicket(Integer memberId, List<VenueLessonTicket> tickets, Integer lessonId, String orderSn,
Integer payType, Integer platformId, Integer memberCardId) {
List<MemberLessonTicket> lessonTicketList = new ArrayList<>();
for (VenueLessonTicket ticket : tickets) {
MemberLessonTicket memberLessonTicket = new MemberLessonTicket();
memberLessonTicket.setVeneuType(ticket.getVenueType());
memberLessonTicket.setVenueId(ticket.getVenueId());
memberLessonTicket.setTicketId(ticket.getId());
memberLessonTicket.setLessonId(ticket.getId());
memberLessonTicket.setTicket(ticket.getTicket());
memberLessonTicket.setLessonId(ticket.getLessonId());
memberLessonTicket.setMemberId(memberId);
@@ -407,7 +415,9 @@ public class MemberLessonTicketService extends BaseServiceImpl {
}
memberLessonTicket.setPlatformId(platformId);
memberLessonTicketMapper.insert(memberLessonTicket);
lessonTicketList.add(memberLessonTicket);
}
return lessonTicketList;
}
/**
@@ -429,6 +439,7 @@ public class MemberLessonTicketService extends BaseServiceImpl {
Integer lessonId = memberLessonTickets.get(0).getLessonId();
memberMoneyLogService.create(order.getMemberId(), order.getPlatformId(), MoneyLogEnum.BUY_LESSON.value, order.getPrice().multiply(new BigDecimal(-1)),
PayTypeEnum.WEI_XIN.value, null, null, null, lessonId);
sendMessageToVenue(memberLessonTickets);
}
/**

View File

@@ -0,0 +1,47 @@
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)) {
}
}
}

View File

@@ -0,0 +1,16 @@
package com.sv.service.api.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public enum AsyncTaskUtil {
INSTANCE;
ExecutorService executorService = Executors.newFixedThreadPool(5);
public void submit(Runnable runnable){
executorService.submit(runnable);
}
}

View File

@@ -0,0 +1,42 @@
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 = "&timestamp=";
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();
}
}

View File

@@ -0,0 +1,37 @@
package com.sv.service.api.util;
import com.dw.ccm.wechat.base.WeChat;
import com.dw.ccm.wechat.base.WeChatHelper;
import com.dw.ccm.wechat.base.message.response.AccessTokenResponse;
import com.dw.ccm.wechat.base.message.template.Attribute;
import com.dw.ccm.wechat.base.message.template.TemplateMessage;
import org.springframework.util.StringUtils;
import java.util.HashMap;
public class WeiXinSendUtils {
public static void sendCard(String webhook){
AccessTokenResponse accessToken = WeChatHelper.getAccessToken("wx51d82eba3f5f4858", "d28320bcb885cc208b6fde2253d8663e");
String token = accessToken.getAccessToken();
if (!StringUtils.isEmpty(token)){
WeChat weChat = WeChatHelper.getWeChat(token);
TemplateMessage templateMessage = new TemplateMessage();
templateMessage.setTemplateId("vPRolOW7D3jnXhT4uqN4FOcIIuHcsHuresbZjlPBg9Y");
templateMessage.setToUser("o81UzwYksMMqbNJgsOvyjhbk-7b0");
templateMessage.setUrl("");
HashMap<String, Attribute> attr = new HashMap<>();
attr.put("thing2",new Attribute("啦啦啦德玛西亚",""));
attr.put("thing3",new Attribute("dadasd",""));
attr.put("time5",new Attribute("2014年9月22日",""));
attr.put("phrase7",new Attribute("你好",""));
templateMessage.setAttributes(attr);
weChat.sendTemplate(templateMessage);
}
}
public static void main(String[] args) {
sendCard("");
}
}

View File

@@ -0,0 +1,297 @@
package com.sv.service.common;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class DingTalkMsg implements Serializable {
private static final String MSG_TEXT = "text";
private static final String MSG_MARKDOWN = "markdown";
private static final String MSG_ACTION_CARD = "actionCard";
private String msgtype;
private DingSendText text;
private AtPerson at;
/**
* 无需设置 singleTitle & singleURL
*/
private Markdown markdown;
private ActionCard actionCard;
public static String getMsgText() {
return MSG_TEXT;
}
public static String getMsgMarkdown() {
return MSG_MARKDOWN;
}
public static String getMsgActionCard() {
return MSG_ACTION_CARD;
}
public String getMsgtype() {
return msgtype;
}
public void setMsgtype(String msgtype) {
this.msgtype = msgtype;
}
public DingSendText getText() {
return text;
}
public void setText(DingSendText text) {
this.text = text;
}
public AtPerson getAt() {
return at;
}
public void setAt(AtPerson at) {
this.at = at;
}
public Markdown getMarkdown() {
return markdown;
}
public void setMarkdown(Markdown markdown) {
this.markdown = markdown;
}
public ActionCard getActionCard() {
return actionCard;
}
public void setActionCard(ActionCard actionCard) {
this.actionCard = actionCard;
}
public void setAtPersonByIds(List<String> ids) {
AtPerson atPerson = new AtPerson();
atPerson.setAtUserIds(ids);
this.at = atPerson;
}
public void setAtPersonByPhone(List<String> phoneNums) {
AtPerson atPerson = new AtPerson();
atPerson.setAtMobiles(phoneNums);
this.at = atPerson;
}
public void setAllAt() {
AtPerson atPerson = new AtPerson();
atPerson.setAtAll(true);
this.at = atPerson;
}
public void sendText(String content){
this.msgtype = MSG_TEXT;
this.text = new DingSendText(content);
}
public void sendMarkDown(String title,String content){
this.msgtype = MSG_MARKDOWN;
this.markdown = new Markdown(title,content);
}
public void sendSingleActionCard(String title,String content,String linkUrl){
this.msgtype = MSG_ACTION_CARD;
ActionCard actionCard = new ActionCard();
actionCard.setTitle(title);
actionCard.setText(content);
actionCard.setSingleTitle("阅读全文");
actionCard.setSingleURL(linkUrl);
this.actionCard = actionCard;
}
public void sendActionCards(String title,String content){
this.msgtype = MSG_ACTION_CARD;
ActionCard actionCard = new ActionCard();
actionCard.setTitle(title);
actionCard.setText(content);
actionCard.setBtnOrientation("1");
List<Button> buttons = new ArrayList<>();
Button button = new Button();
Button button2 = new Button();
Button button3 = new Button();
button.setTitle("查看详情");
button.setActionURL("https://www.baidu.com");
button2.setTitle("同意");
button2.setActionURL("https://336p7t9393.goho.co/ding/talk/quinn");
button3.setTitle("返回");
button3.setActionURL("");
buttons.add(button2);
buttons.add(button3);
actionCard.setBtns(buttons);
this.actionCard = actionCard;
}
private class DingSendText {
public DingSendText(String content) {
this.content = content;
}
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}
private class Markdown {
private String title;
private String text;
public Markdown(String title, String text) {
this.title = title;
this.text = text;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
}
private class ActionCard {
private String title;
private String text;
private String singleTitle;
private String singleURL;
/**
* 0按钮竖直排列
* 1按钮横向排列
*/
private String btnOrientation;
private List<Button> btns;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
public String getSingleTitle() {
return singleTitle;
}
public void setSingleTitle(String singleTitle) {
this.singleTitle = singleTitle;
}
public String getSingleURL() {
return singleURL;
}
public void setSingleURL(String singleURL) {
this.singleURL = singleURL;
}
public String getBtnOrientation() {
return btnOrientation;
}
public void setBtnOrientation(String btnOrientation) {
this.btnOrientation = btnOrientation;
}
public List<Button> getBtns() {
return btns;
}
public void setBtns(List<Button> btns) {
this.btns = btns;
}
}
private class Button {
private String title;
private String actionURL;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getActionURL() {
return actionURL;
}
public void setActionURL(String actionURL) {
this.actionURL = actionURL;
}
}
private class AtPerson {
private boolean isAtAll;
private List<String> atMobiles;
private List<String> atUserIds;
public boolean isAtAll() {
return isAtAll;
}
public void setAtAll(boolean atAll) {
isAtAll = atAll;
}
public List<String> getAtMobiles() {
return atMobiles;
}
public void setAtMobiles(List<String> atMobiles) {
this.atMobiles = atMobiles;
}
public List<String> getAtUserIds() {
return atUserIds;
}
public void setAtUserIds(List<String> atUserIds) {
this.atUserIds = atUserIds;
}
}
}

View File

@@ -0,0 +1,155 @@
package com.sv.service.utils;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class HttpClientUtils {
public static String doGet(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpclient = HttpClients.createDefault();
String resultString = "";
CloseableHttpResponse response = null;
try {
// 创建uri
URIBuilder builder = new URIBuilder(url);
if (param != null) {
for (String key : param.keySet()) {
builder.addParameter(key, param.get(key));
}
}
URI uri = builder.build();
// 创建http GET请求
HttpGet httpGet = new HttpGet(uri);
// 执行请求
response = httpclient.execute(httpGet);
// 判断返回状态是否为200
if (response.getStatusLine().getStatusCode() == 200) {
resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (response != null) {
response.close();
}
httpclient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doGet(String url) {
return doGet(url, null);
}
public static String doPost(String url, Map<String, String> param) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建参数列表
if (param != null) {
List<NameValuePair> paramList = new ArrayList<>();
for (String key : param.keySet()) {
paramList.add(new BasicNameValuePair(key, param.get(key)));
}
// 模拟表单
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(paramList,"utf-8");
httpPost.setEntity(entity);
}
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doPost(String url) {
return doPost(url, null);
}
public static String doPostJson(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
public static String doPostXml(String url, String json) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response = null;
String resultString = "";
try {
// 创建Http Post请求
HttpPost httpPost = new HttpPost(url);
// 创建请求内容
StringEntity entity = new StringEntity(json, ContentType.APPLICATION_XML);
httpPost.setEntity(entity);
// 执行http请求
response = httpClient.execute(httpPost);
resultString = EntityUtils.toString(response.getEntity(), "utf-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return resultString;
}
}