记得上下班打卡 | git大法好,push需谨慎

Commit bfeb9d1a authored by 张国柄's avatar 张国柄

fix:小程序演出提醒模板消息发送异常处理;

parent 8916d7eb
......@@ -10,6 +10,7 @@ import com.liquidnet.service.sweet.constant.SweetConstant;
import com.liquidnet.service.sweet.entity.SweetWechatUser;
import com.liquidnet.service.sweet.utils.RedisDataUtils;
import com.liquidnet.service.sweet.vo.SweetRemindVo;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
......@@ -34,6 +35,7 @@ import java.util.Set;
* @author liquidnet
* @since 2021-07-27
*/
@Slf4j
@Service
public class SweetWechatTemplateServiceImpl {
......@@ -56,53 +58,58 @@ public class SweetWechatTemplateServiceImpl {
Set<String> keys = redisTemplate.keys(redisKey);
if (!CollectionUtils.isEmpty(keys)) {
for (String rkey : keys) {
SweetRemindVo remindInfo = (SweetRemindVo) redisUtil.get(rkey);
SweetWechatUser sweetWechatUser = redisDataUtils.getSweetWechatUser(remindInfo.getUnionId());
KylinPerformanceVo performanceVo = (KylinPerformanceVo) redisUtil.get(KylinRedisConst.PERFORMANCES.concat(remindInfo.getPerformancesId()));
KylinTicketTimesVo kylinTicketTimesVo = performanceVo.getTicketTimeList().get(0);
if (null == sweetWechatUser || null == performanceVo) {
continue;
}
LocalDateTime nowTime = LocalDateTime.now();
LocalDateTime newNowTime = nowTime.minusMinutes(5);
String nowTimeStr = DateUtil.Formatter.yyyyMMddHHmmss.format(newNowTime);
String sellTime = performanceVo.getSellTime();
String stopSellTime = performanceVo.getStopSellTime();
if (1 == DateUtil.compareStrDay(nowTimeStr, stopSellTime)) { // 超过售卖期 不推 删redis
redisDataUtils.delSweetRemind(remindInfo.getUnionId());
continue;
}
if (-1 == DateUtil.compareStrDay(nowTimeStr, sellTime)) { // 还没到售卖期
continue;
}
// 发送模板消息接口
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
// 接收者openid
.toUser(sweetWechatUser.getOpenId())
// 模板id
.templateId(templateId)
// 模板跳转链接
.url(h5Url.concat("/#/ticket/detail?id=").concat(remindInfo.getPerformancesId()))
.build();
// 添加模板数据
templateMessage.addData(new WxMpTemplateData("first", "您关注的演出即将开始售票"))
.addData(new WxMpTemplateData("keyword1", performanceVo.getTitle()))
.addData(new WxMpTemplateData("keyword2", kylinTicketTimesVo.getTitle()))
.addData(new WxMpTemplateData("keyword3", performanceVo.getFieldName()))
.addData(new WxMpTemplateData("remark", "点击这里跳转购票"));
String msgId = null;
try {
// 发送模板消息
WxMpConfigStorage wxMpConfig = wxMpConfig(appid, secret);
WxMpService wxMpService = wxMpService(wxMpConfig);
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
if (null != msgId) {
SweetRemindVo remindInfo = (SweetRemindVo) redisUtil.get(rkey);
SweetWechatUser sweetWechatUser = redisDataUtils.getSweetWechatUser(remindInfo.getUnionId());
KylinPerformanceVo performanceVo = (KylinPerformanceVo) redisUtil.get(KylinRedisConst.PERFORMANCES.concat(remindInfo.getPerformancesId()));
if (null == sweetWechatUser || null == performanceVo) {
continue;
}
KylinTicketTimesVo kylinTicketTimesVo = performanceVo.getTicketTimeList().get(0);
LocalDateTime nowTime = LocalDateTime.now();
LocalDateTime newNowTime = nowTime.minusMinutes(5);
String nowTimeStr = DateUtil.Formatter.yyyyMMddHHmmss.format(newNowTime);
String sellTime = performanceVo.getSellTime();
String stopSellTime = performanceVo.getStopSellTime();
if (1 == DateUtil.compareStrDay(nowTimeStr, stopSellTime)) { // 超过售卖期 不推 删redis
redisDataUtils.delSweetRemind(remindInfo.getUnionId());
continue;
}
if (-1 == DateUtil.compareStrDay(nowTimeStr, sellTime)) { // 还没到售卖期
continue;
}
// 发送模板消息接口
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
// 接收者openid
.toUser(sweetWechatUser.getOpenId())
// 模板id
.templateId(templateId)
// 模板跳转链接
.url(h5Url.concat("/#/ticket/detail?id=").concat(remindInfo.getPerformancesId()))
.build();
// 添加模板数据
templateMessage.addData(new WxMpTemplateData("first", "您关注的演出即将开始售票"))
.addData(new WxMpTemplateData("keyword1", performanceVo.getTitle()))
.addData(new WxMpTemplateData("keyword2", kylinTicketTimesVo.getTitle()))
.addData(new WxMpTemplateData("keyword3", performanceVo.getFieldName()))
.addData(new WxMpTemplateData("remark", "点击这里跳转购票"));
String msgId = null;
try {
// 发送模板消息
WxMpConfigStorage wxMpConfig = wxMpConfig(appid, secret);
WxMpService wxMpService = wxMpService(wxMpConfig);
msgId = wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
if (null != msgId) {
redisDataUtils.delSweetRemind(remindInfo.getUnionId());
}
} catch (WxErrorException e) {
log.error("小程序演出提醒消息发送异常", e);
}
} catch (WxErrorException e) {
e.printStackTrace();
log.info(msgId);
} catch (Exception e) {
log.error("小程序演出提醒消息处理异常", e);
}
System.out.println(msgId);
}
}
return ResponseDto.success();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment