Commit 90ac1a09 by 吕明尚

在自动任务中增加订阅消息推送

parent da387aba
...@@ -53,11 +53,7 @@ ...@@ -53,11 +53,7 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.8.16</version> <version>5.8.16</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>4.5.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
......
...@@ -6,13 +6,16 @@ import cn.hutool.core.date.LocalDateTimeUtil; ...@@ -6,13 +6,16 @@ import cn.hutool.core.date.LocalDateTimeUtil;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import share.system.config.WxMaProperties;
import share.system.domain.vo.SendTemplateMessageItemVo;
import share.system.domain.vo.TemplateMessageVo;
import share.system.service.WechatNewService;
import share.system.util.WXMsgPushUtils; import share.system.util.WXMsgPushUtils;
import share.web.core.config.WxMaProperties;
import java.time.LocalDateTime; import java.time.LocalDateTime;
...@@ -63,6 +66,22 @@ public class WxMsgPushController { ...@@ -63,6 +66,22 @@ public class WxMsgPushController {
@GetMapping("/getOpenId") @GetMapping("/getOpenId")
public void getOpenId(String openId) throws Exception { public void getOpenId(String openId) throws Exception {
// HashMap<String, SendTemplateMessageItemVo> data = new HashMap<>();
// TemplateMessageVo templateMessageVo = new TemplateMessageVo();
// templateMessageVo.setTouser(openId);
// templateMessageVo.setTemplate_id("oTc000e4NHkoc7v9OLBZiwM6Q6SFzguemrx6d0iuVS8");
// templateMessageVo.setUrl("http://www.baidu.com");
// data.put("thing4", new SendTemplateMessageItemVo("预约门店"));
// data.put("thing7", new SendTemplateMessageItemVo("服务名称"));
// data.put("date3", new SendTemplateMessageItemVo(LocalDateTimeUtil.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm:ss")));
// data.put("thing5", new SendTemplateMessageItemVo("地址"));
// templateMessageVo.setData(data);
// log.info("开始发送消息!!!!");
// Boolean b = wechatNewService.sendMiniSubscribeMessage(templateMessageVo);
// if(b){
// log.info("消息发送成功!!!!");
// }
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("thing4", "预约门店"); map.put("thing4", "预约门店");
map.put("thing7", "服务名称"); map.put("thing7", "服务名称");
......
...@@ -16,10 +16,8 @@ import share.common.constant.Constants; ...@@ -16,10 +16,8 @@ import share.common.constant.Constants;
import share.common.core.redis.RedisUtil; import share.common.core.redis.RedisUtil;
import share.common.enums.*; import share.common.enums.*;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.system.domain.SConsumer; import share.system.domain.*;
import share.system.domain.SConsumerCoupon; import share.system.domain.vo.TemplateMessageVo;
import share.system.domain.SOrder;
import share.system.domain.SRoom;
import share.system.service.*; import share.system.service.*;
import java.util.*; import java.util.*;
...@@ -63,6 +61,10 @@ public class OrderTask { ...@@ -63,6 +61,10 @@ public class OrderTask {
@Autowired @Autowired
private RedisTemplate redisTemplate; private RedisTemplate redisTemplate;
@Autowired
private WechatNewService wechatNewService;
final int ZERO = 0; final int ZERO = 0;
//10分钟的常量 //10分钟的常量
final long TEN_MINUTES = 60 * 10; final long TEN_MINUTES = 60 * 10;
...@@ -227,7 +229,8 @@ public class OrderTask { ...@@ -227,7 +229,8 @@ public class OrderTask {
//时间到期前10分钟到9分 //时间到期前10分钟到9分
long expire = (expirationTime.getTime() - new Date().getTime()) / 1000; long expire = (expirationTime.getTime() - new Date().getTime()) / 1000;
if (expire < TEN_MINUTES && expire > NINE_MINUTES) { if (expire < TEN_MINUTES && expire > NINE_MINUTES) {
SOrder byOrderNo = orderService.getByOrderNo(String.valueOf(o));
wechatNewService.sendMiniSubscribeMessage(byOrderNo, MessageReminderEnum.RESERVER)
} }
if (expirationTime.getTime() < new Date().getTime()) { if (expirationTime.getTime() < new Date().getTime()) {
sOrders.add(orderService.getByOrderNo(String.valueOf(o))); sOrders.add(orderService.getByOrderNo(String.valueOf(o)));
...@@ -255,6 +258,8 @@ public class OrderTask { ...@@ -255,6 +258,8 @@ public class OrderTask {
room.setUpdateTime(new Date()); room.setUpdateTime(new Date());
} }
}); });
//推送订单开始预定消息
wechatNewService.sendMiniSubscribeMessage(item, MessageReminderEnum.START);
//到达预定时间进行通电 //到达预定时间进行通电
deviceOpService.openOrCloseDevice(item.getRoomId(), item.getConsumerPhone(), OpTypeEnum.GET_ELECTRIC.getCode(), false, ZERO); deviceOpService.openOrCloseDevice(item.getRoomId(), item.getConsumerPhone(), OpTypeEnum.GET_ELECTRIC.getCode(), false, ZERO);
} }
......
...@@ -47,6 +47,9 @@ public class RedisTask { ...@@ -47,6 +47,9 @@ public class RedisTask {
@Autowired @Autowired
private DeviceOpService deviceOpService; private DeviceOpService deviceOpService;
@Autowired
private WechatNewService wechatNewService;
//15分钟的常量 //15分钟的常量
final long FIFTEEN_MINUTES = 60 * 15; final long FIFTEEN_MINUTES = 60 * 15;
//14分钟的常量 //14分钟的常量
...@@ -158,6 +161,8 @@ public class RedisTask { ...@@ -158,6 +161,8 @@ public class RedisTask {
if (b) { if (b) {
//删除redis中的值 //删除redis中的值
redisUtil.delete(o); redisUtil.delete(o);
//推送订单结束消息
wechatNewService.sendMiniSubscribeMessage(sOrder, MessageReminderEnum.END);
deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.SEND_CUSTOMER.getCode(), deviceOpService.actionExecute(sOrder.getRoomId(), sOrder.getConsumerPhone(), VoiceEnum.SEND_CUSTOMER.getCode(),
DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN), DateUtil.format(new Date(), DatePattern.NORM_DATETIME_PATTERN),
DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1"); DateUtil.format(DateUtil.offsetMinute(new Date(), 1), DatePattern.NORM_DATETIME_PATTERN), "1");
......
package share.web.core.config; package share.system.config;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
......
package share.web.core.config; package share.system.config;
import lombok.Data; import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.context.properties.ConfigurationProperties;
......
package share.system.service; package share.system.service;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import share.common.enums.MessageReminderEnum;
import share.system.domain.SOrder;
import share.system.domain.vo.*; import share.system.domain.vo.*;
import share.system.response.WeChatJsSdkConfigResponse; import share.system.response.WeChatJsSdkConfigResponse;
...@@ -94,6 +96,8 @@ public interface WechatNewService { ...@@ -94,6 +96,8 @@ public interface WechatNewService {
*/ */
Boolean sendMiniSubscribeMessage(TemplateMessageVo templateMessage); Boolean sendMiniSubscribeMessage(TemplateMessageVo templateMessage);
Boolean sendMiniSubscribeMessage(SOrder byOrderNo, MessageReminderEnum messageReminderEnum);
/** /**
* 获取微信公众号自定义菜单配置 * 获取微信公众号自定义菜单配置
* (使用本自定义菜单查询接口可以获取默认菜单和全部个性化菜单信息) * (使用本自定义菜单查询接口可以获取默认菜单和全部个性化菜单信息)
......
...@@ -347,6 +347,11 @@ public class QPServiceImpl implements QPService { ...@@ -347,6 +347,11 @@ public class QPServiceImpl implements QPService {
} }
/**
* 适用店铺查询接口
*
* @return
*/
@Override @Override
public List<CustomerKeyShopScopeResponseEntity> scope() { public List<CustomerKeyShopScopeResponseEntity> scope() {
Boolean b = redisUtil.exists(ReceiptRdeisEnum.MT_SESSION_KEY.getValue()); Boolean b = redisUtil.exists(ReceiptRdeisEnum.MT_SESSION_KEY.getValue());
......
...@@ -93,7 +93,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -93,7 +93,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
private ISConsumptionRecordsService sConsumptionRecordsService; private ISConsumptionRecordsService sConsumptionRecordsService;
@Autowired @Autowired
private MqttxService mqttxService; private WechatNewService wechatNewService;
/** /**
* 查询订单 * 查询订单
...@@ -335,6 +335,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -335,6 +335,11 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
sConsumptionRecords.setPayType(PayTypeEnum.WECHAT.getName()); sConsumptionRecords.setPayType(PayTypeEnum.WECHAT.getName());
sConsumptionRecords.setSign(SignEnum.BURDEN.getValue()); sConsumptionRecords.setSign(SignEnum.BURDEN.getValue());
sConsumptionRecordsService.insertSConsumptionRecords(sConsumptionRecords); sConsumptionRecordsService.insertSConsumptionRecords(sConsumptionRecords);
Map<String, String> map = new HashMap<>();
map.put("orderNo", sOrder.getOrderNo());
map.put("expirationTime", sOrder.getPreStartDate().toString());
JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO.getValue() + sOrder.getOrderNo(), jsonObject.toString());
} }
if (sOrder.getOrderType().equals(OrderTypeEnum.RENEW.getCode())) { if (sOrder.getOrderType().equals(OrderTypeEnum.RENEW.getCode())) {
sOrder.setStartDate(sOrder.getPreStartDate()); sOrder.setStartDate(sOrder.getPreStartDate());
...@@ -651,7 +656,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme ...@@ -651,7 +656,7 @@ public class SOrderServiceImpl extends ServiceImpl<SOrderMapper, SOrder> impleme
map.put("expirationTime", sOrder.getEndDate().toString()); map.put("expirationTime", sOrder.getEndDate().toString());
JSONObject jsonObject = new JSONObject(map); JSONObject jsonObject = new JSONObject(map);
redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString()); redisUtils.set(ReceiptRdeisEnum.ORDER_NO_KEY.getValue() + sOrder.getOrderNo(), jsonObject.toString());
} else { } else if (sOrder.getOrderType().equals(OrderTypeEnum.RESERVER.getCode())) {
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
map.put("orderNo", sOrder.getOrderNo()); map.put("orderNo", sOrder.getOrderNo());
map.put("expirationTime", sOrder.getPreStartDate().toString()); map.put("expirationTime", sOrder.getPreStartDate().toString());
......
...@@ -2,6 +2,7 @@ package share.system.service.impl; ...@@ -2,6 +2,7 @@ package share.system.service.impl;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
...@@ -19,27 +20,26 @@ import share.common.config.WeChatConfig; ...@@ -19,27 +20,26 @@ import share.common.config.WeChatConfig;
import share.common.constant.PayConstants; import share.common.constant.PayConstants;
import share.common.constant.WeChatConstants; import share.common.constant.WeChatConstants;
import share.common.core.redis.RedisUtil; import share.common.core.redis.RedisUtil;
import share.common.enums.MessageReminderEnum;
import share.common.utils.http.RestTemplateUtil; import share.common.utils.http.RestTemplateUtil;
import share.common.exception.base.BaseException; import share.common.exception.base.BaseException;
import share.common.utils.BaseUtil; import share.common.utils.BaseUtil;
import share.common.utils.XmlUtil; import share.common.utils.XmlUtil;
import share.system.domain.WechatExceptions; import share.system.domain.*;
import share.system.domain.WechatPayInfo;
import share.system.domain.vo.*; import share.system.domain.vo.*;
import share.system.response.WeChatJsSdkConfigResponse; import share.system.response.WeChatJsSdkConfigResponse;
import share.system.service.WechatExceptionsService; import share.system.service.*;
import share.system.service.WechatNewService;
import share.system.service.WechatPayInfoService;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
* 微信公用服务实现类 * 微信公用服务实现类
*/ */
@Service @Service
public class WechatNewServiceImpl implements WechatNewService { public class WechatNewServiceImpl implements WechatNewService {
...@@ -61,6 +61,12 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -61,6 +61,12 @@ public class WechatNewServiceImpl implements WechatNewService {
@Autowired @Autowired
private WechatExceptionsService wechatExceptionsService; private WechatExceptionsService wechatExceptionsService;
@Autowired
private SConsumerTokenService sConsumerTokenService;
@Autowired
private ISStoreService storeService;
/** /**
* 获取公众号accessToken * 获取公众号accessToken
*/ */
...@@ -89,6 +95,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -89,6 +95,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取小程序accessToken * 获取小程序accessToken
*
* @return accessToken * @return accessToken
*/ */
@Override @Override
...@@ -117,6 +124,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -117,6 +124,7 @@ public class WechatNewServiceImpl implements WechatNewService {
* 获取开放平台access_token * 获取开放平台access_token
* 通过 code 获取 * 通过 code 获取
* 公众号使用 * 公众号使用
*
* @return 开放平台accessToken对象 * @return 开放平台accessToken对象
*/ */
@Override @Override
...@@ -146,9 +154,10 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -146,9 +154,10 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取开放平台用户信息 * 获取开放平台用户信息
*
* @param accessToken 调用凭证 * @param accessToken 调用凭证
* @param openid 普通用户的标识,对当前开发者帐号唯一 * @param openid 普通用户的标识,对当前开发者帐号唯一
* 公众号使用 * 公众号使用
* @return 开放平台用户信息对象 * @return 开放平台用户信息对象
*/ */
@Override @Override
...@@ -170,6 +179,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -170,6 +179,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 小程序登录凭证校验 * 小程序登录凭证校验
*
* @return 小程序登录校验对象 * @return 小程序登录校验对象
*/ */
@Override @Override
...@@ -199,6 +209,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -199,6 +209,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取微信公众号js配置参数 * 获取微信公众号js配置参数
*
* @return WeChatJsSdkConfigResponse * @return WeChatJsSdkConfigResponse
*/ */
@Override @Override
...@@ -216,7 +227,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -216,7 +227,7 @@ public class WechatNewServiceImpl implements WechatNewService {
String ticket = getJsApiTicket(); String ticket = getJsApiTicket();
String nonceStr = BaseUtil.getUuid(); String nonceStr = BaseUtil.getUuid();
Long timestamp = DateUtil.currentSeconds(); Long timestamp = DateUtil.currentSeconds();
String signature = getJsSDKSignature(nonceStr, ticket, timestamp , url); String signature = getJsSDKSignature(nonceStr, ticket, timestamp, url);
WeChatJsSdkConfigResponse response = new WeChatJsSdkConfigResponse(); WeChatJsSdkConfigResponse response = new WeChatJsSdkConfigResponse();
response.setUrl(url); response.setUrl(url);
...@@ -225,13 +236,14 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -225,13 +236,14 @@ public class WechatNewServiceImpl implements WechatNewService {
response.setTimestamp(timestamp); response.setTimestamp(timestamp);
response.setSignature(signature); response.setSignature(signature);
response.setJsApiList(BaseUtil.stringToArrayStr(WeChatConstants.PUBLIC_API_JS_API_SDK_LIST)); response.setJsApiList(BaseUtil.stringToArrayStr(WeChatConstants.PUBLIC_API_JS_API_SDK_LIST));
response.setDebug(weChatConfig.getWechatJsApiDebug()==0); response.setDebug(weChatConfig.getWechatJsApiDebug() == 0);
return response; return response;
} }
/** /**
* 生成小程序码 * 生成小程序码
* @param page 必须是已经发布的小程序存在的页面 *
* @param page 必须是已经发布的小程序存在的页面
* @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符 * @param scene 最大32个可见字符,只支持数字,大小写英文以及部分特殊字符:!#$&'()*+,/:;=?@-._~,其它字符请自行编码为合法字符
* @return 小程序码 * @return 小程序码
*/ */
...@@ -245,8 +257,8 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -245,8 +257,8 @@ public class WechatNewServiceImpl implements WechatNewService {
map.put("width", 200); map.put("width", 200);
byte[] bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(map)); byte[] bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(map));
String response = new String(bytes); String response = new String(bytes);
if (StringUtils.contains(response,"errcode")) { if (StringUtils.contains(response, "errcode")) {
logger.error("微信生成小程序码异常"+response); logger.error("微信生成小程序码异常" + response);
JSONObject data = JSONObject.parseObject(response); JSONObject data = JSONObject.parseObject(response);
// 保存到微信异常表 // 保存到微信异常表
wxExceptionDispose(data, "微信小程序生成小程序码异常"); wxExceptionDispose(data, "微信小程序生成小程序码异常");
...@@ -256,8 +268,8 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -256,8 +268,8 @@ public class WechatNewServiceImpl implements WechatNewService {
url = StrUtil.format(WeChatConstants.WECHAT_MINI_QRCODE_UNLIMITED_URL, miniAccessToken); url = StrUtil.format(WeChatConstants.WECHAT_MINI_QRCODE_UNLIMITED_URL, miniAccessToken);
bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(map)); bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(map));
response = new String(bytes); response = new String(bytes);
if (StringUtils.contains(response,"errcode")) { if (StringUtils.contains(response, "errcode")) {
logger.error("微信生成小程序码重试异常"+response); logger.error("微信生成小程序码重试异常" + response);
JSONObject data2 = JSONObject.parseObject(response); JSONObject data2 = JSONObject.parseObject(response);
// 保存到微信异常表 // 保存到微信异常表
wxExceptionDispose(data2, "微信小程序重试生成小程序码异常"); wxExceptionDispose(data2, "微信小程序重试生成小程序码异常");
...@@ -282,20 +294,21 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -282,20 +294,21 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 自定义参数二维码 * 自定义参数二维码
*
* @param param * @param param
* @return * @return
*/ */
@Override @Override
public String createQrCodeCustomParam(Map<String, Object> param) { public String createQrCodeCustomParam(Map<String, Object> param) {
if (CollectionUtil.isEmpty(param)){ if (CollectionUtil.isEmpty(param)) {
throw new BaseException("请求参数不可为空"); throw new BaseException("请求参数不可为空");
} }
String miniAccessToken = getMiniAccessToken(); String miniAccessToken = getMiniAccessToken();
String url = StrUtil.format(WeChatConstants.WECHAT_MINI_QRCODE_UNLIMITED_URL, miniAccessToken); String url = StrUtil.format(WeChatConstants.WECHAT_MINI_QRCODE_UNLIMITED_URL, miniAccessToken);
byte[] bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(param)); byte[] bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(param));
String response = new String(bytes); String response = new String(bytes);
if (StringUtils.contains(response,"errcode")) { if (StringUtils.contains(response, "errcode")) {
logger.error("微信生成小程序码异常"+response); logger.error("微信生成小程序码异常" + response);
JSONObject data = JSONObject.parseObject(response); JSONObject data = JSONObject.parseObject(response);
// 保存到微信异常表 // 保存到微信异常表
wxExceptionDispose(data, "微信小程序生成小程序码异常"); wxExceptionDispose(data, "微信小程序生成小程序码异常");
...@@ -305,8 +318,8 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -305,8 +318,8 @@ public class WechatNewServiceImpl implements WechatNewService {
url = StrUtil.format(WeChatConstants.WECHAT_MINI_QRCODE_UNLIMITED_URL, miniAccessToken); url = StrUtil.format(WeChatConstants.WECHAT_MINI_QRCODE_UNLIMITED_URL, miniAccessToken);
bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(param)); bytes = restTemplateUtil.postJsonDataAndReturnBuffer(url, new JSONObject(param));
response = new String(bytes); response = new String(bytes);
if (StringUtils.contains(response,"errcode")) { if (StringUtils.contains(response, "errcode")) {
logger.error("微信生成小程序码重试异常"+response); logger.error("微信生成小程序码重试异常" + response);
JSONObject data2 = JSONObject.parseObject(response); JSONObject data2 = JSONObject.parseObject(response);
// 保存到微信异常表 // 保存到微信异常表
wxExceptionDispose(data2, "微信小程序重试生成小程序码异常"); wxExceptionDispose(data2, "微信小程序重试生成小程序码异常");
...@@ -331,6 +344,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -331,6 +344,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信预下单接口(统一下单) * 微信预下单接口(统一下单)
*
* @param unifiedorderVo 预下单请求对象 * @param unifiedorderVo 预下单请求对象
* @return 微信预下单返回对象 * @return 微信预下单返回对象
*/ */
...@@ -353,7 +367,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -353,7 +367,7 @@ public class WechatNewServiceImpl implements WechatNewService {
wxPayExceptionDispose(map, "微信支付预下单异常"); wxPayExceptionDispose(map, "微信支付预下单异常");
wechatPayInfo.setErrCode(map.get("return_code").toString()); wechatPayInfo.setErrCode(map.get("return_code").toString());
wechatPayInfoService.save(wechatPayInfo); wechatPayInfoService.save(wechatPayInfo);
throw new BaseException("微信下单失败1!" + responseVo.getReturnMsg()); throw new BaseException("微信下单失败1!" + responseVo.getReturnMsg());
} }
if (responseVo.getResultCode().toUpperCase().equals("FAIL")) { if (responseVo.getResultCode().toUpperCase().equals("FAIL")) {
...@@ -375,6 +389,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -375,6 +389,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 生成微信订单表对象 * 生成微信订单表对象
*
* @param vo 预下单数据 * @param vo 预下单数据
* @return WechatPayInfo * @return WechatPayInfo
*/ */
...@@ -405,6 +420,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -405,6 +420,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信支付查询订单 * 微信支付查询订单
*
* @return 支付订单查询结果 * @return 支付订单查询结果
*/ */
@Override @Override
...@@ -421,7 +437,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -421,7 +437,7 @@ public class WechatNewServiceImpl implements WechatNewService {
record.setColums(map); record.setColums(map);
if (record.getStr("return_code").toUpperCase().equals("FAIL")) { if (record.getStr("return_code").toUpperCase().equals("FAIL")) {
wxPayQueryExceptionDispose(record, "微信支付查询订单通信异常"); wxPayQueryExceptionDispose(record, "微信支付查询订单通信异常");
throw new BaseException("微信订单查询失败1!" + record.getStr("return_msg")); throw new BaseException("微信订单查询失败1!" + record.getStr("return_msg"));
} }
if (record.getStr("result_code").toUpperCase().equals("FAIL")) { if (record.getStr("result_code").toUpperCase().equals("FAIL")) {
...@@ -442,6 +458,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -442,6 +458,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信公众号发送模板消息 * 微信公众号发送模板消息
*
* @param templateMessage 模板消息对象 * @param templateMessage 模板消息对象
* @return 是否发送成功 * @return 是否发送成功
*/ */
...@@ -466,6 +483,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -466,6 +483,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信小程序发送订阅消息 * 微信小程序发送订阅消息
*
* @param templateMessage 消息对象 * @param templateMessage 消息对象
* @return 是否发送成功 * @return 是否发送成功
*/ */
...@@ -504,9 +522,61 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -504,9 +522,61 @@ public class WechatNewServiceImpl implements WechatNewService {
return Boolean.TRUE; return Boolean.TRUE;
} }
@Override
public Boolean sendMiniSubscribeMessage(SOrder byOrderNo, MessageReminderEnum messageReminderEnum) {
//发送模板消息 预约提醒到期
TemplateMessageVo templateMessageVo = new TemplateMessageVo();
HashMap<String, SendTemplateMessageItemVo> data = new HashMap<>();
SStore sStore = storeService.getById(byOrderNo.getStoreId());
//拼接开始和结束时间
Date preStartDate = byOrderNo.getPreStartDate();
Date preEndDate = byOrderNo.getPreEndDate();
//转字符串
String preStartDateStr = DateUtil.format(preStartDate, DatePattern.NORM_DATETIME_MINUTE_FORMATTER);
String preEndDateStr = DateUtil.format(preEndDate, DatePattern.NORM_DATETIME_MINUTE_FORMATTER);
SConsumerToken tokenByUserId = sConsumerTokenService.getTokenByUserId(byOrderNo.getConsumerId());
templateMessageVo.setTouser(tokenByUserId.getToken());
if (messageReminderEnum.equals(MessageReminderEnum.RESERVER)) {
templateMessageVo.setTemplate_id(MessageReminderEnum.RESERVER.getValue());
//添加门店名称
data.put("thing4", new SendTemplateMessageItemVo());
//服务名称
data.put("thing7", new SendTemplateMessageItemVo());
//预约时间
data.put("date3", new SendTemplateMessageItemVo(preStartDateStr + "-" + preEndDateStr));
//地址
data.put("thing5", new SendTemplateMessageItemVo(sStore.getAddress()));
} else if (messageReminderEnum.equals(MessageReminderEnum.START)) {
templateMessageVo.setTemplate_id(MessageReminderEnum.START.getValue());
//预约门店
data.put("thing6", new SendTemplateMessageItemVo());
//服务名称
data.put("thing7", new SendTemplateMessageItemVo());
//预约时间
data.put("time8", new SendTemplateMessageItemVo(preStartDateStr + "-" + preEndDateStr));
//地址
data.put("thing9", new SendTemplateMessageItemVo(sStore.getAddress()));
//订单金额
data.put("amount4", new SendTemplateMessageItemVo(String.valueOf(byOrderNo.getPackPrice())));
} else if (messageReminderEnum.equals(MessageReminderEnum.END)) {
templateMessageVo.setTemplate_id(MessageReminderEnum.END.getValue());
//订单门店
data.put("thing5", new SendTemplateMessageItemVo());
//服务名称
data.put("thing6", new SendTemplateMessageItemVo());
//订单时间
data.put("time7", new SendTemplateMessageItemVo(preStartDateStr + "-" + preEndDateStr));
//地址
data.put("time8", new SendTemplateMessageItemVo(sStore.getAddress()));
}
templateMessageVo.setData(data);
return sendMiniSubscribeMessage(templateMessageVo);
}
/** /**
* 获取微信公众号自定义菜单配置 * 获取微信公众号自定义菜单配置
* (使用本自定义菜单查询接口可以获取默认菜单和全部个性化菜单信息) * (使用本自定义菜单查询接口可以获取默认菜单和全部个性化菜单信息)
*
* @return 公众号自定义菜单 * @return 公众号自定义菜单
*/ */
@Override @Override
...@@ -529,6 +599,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -529,6 +599,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 创建微信自定义菜单 * 创建微信自定义菜单
*
* @param data 菜单json字符串 * @param data 菜单json字符串
* @return 创建结果 * @return 创建结果
*/ */
...@@ -554,6 +625,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -554,6 +625,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 删除微信自定义菜单 * 删除微信自定义菜单
*
* @return 删除结果 * @return 删除结果
*/ */
@Override @Override
...@@ -577,6 +649,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -577,6 +649,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 企业号上传其他类型永久素材 * 企业号上传其他类型永久素材
* 获取url * 获取url
*
* @param type 素材类型:图片(image)、语音(voice)、视频(video),普通文件(file) * @param type 素材类型:图片(image)、语音(voice)、视频(video),普通文件(file)
*/ */
@Override @Override
...@@ -587,8 +660,9 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -587,8 +660,9 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信申请退款 * 微信申请退款
*
* @param wxRefundVo 微信申请退款对象 * @param wxRefundVo 微信申请退款对象
* @param path 商户p12证书绝对路径 * @param path 商户p12证书绝对路径
* @return 申请退款结果对象 * @return 申请退款结果对象
*/ */
@Override @Override
...@@ -612,7 +686,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -612,7 +686,7 @@ public class WechatNewServiceImpl implements WechatNewService {
WxRefundResponseVo responseVo = BaseUtil.mapToObj(map, WxRefundResponseVo.class); WxRefundResponseVo responseVo = BaseUtil.mapToObj(map, WxRefundResponseVo.class);
if (responseVo.getReturnCode().toUpperCase().equals("FAIL")) { if (responseVo.getReturnCode().toUpperCase().equals("FAIL")) {
wxPayExceptionDispose(map, "微信申请退款异常1"); wxPayExceptionDispose(map, "微信申请退款异常1");
throw new BaseException("微信申请退款失败1!" + responseVo.getReturnMsg()); throw new BaseException("微信申请退款失败1!" + responseVo.getReturnMsg());
} }
if (responseVo.getResultCode().toUpperCase().equals("FAIL")) { if (responseVo.getResultCode().toUpperCase().equals("FAIL")) {
...@@ -625,6 +699,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -625,6 +699,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取我的公众号模板消息列表 * 获取我的公众号模板消息列表
*
* @return List * @return List
*/ */
@Override @Override
...@@ -649,6 +724,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -649,6 +724,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 删除微信公众号模板消息 * 删除微信公众号模板消息
*
* @param templateId 模板编号 * @param templateId 模板编号
* @return Boolean * @return Boolean
*/ */
...@@ -675,6 +751,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -675,6 +751,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 添加公众号模板消息 * 添加公众号模板消息
*
* @param templateIdShort 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式 * @param templateIdShort 模板库中模板的编号,有“TM**”和“OPENTMTM**”等形式
* @return 公众号模板编号(自己的) * @return 公众号模板编号(自己的)
*/ */
...@@ -701,6 +778,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -701,6 +778,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取当前帐号下的个人模板列表 * 获取当前帐号下的个人模板列表
*
* @return List * @return List
*/ */
@Override @Override
...@@ -725,6 +803,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -725,6 +803,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 删除微信小程序订阅消息 * 删除微信小程序订阅消息
*
* @return Boolean * @return Boolean
*/ */
@Override @Override
...@@ -750,6 +829,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -750,6 +829,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取小程序平台上的标准模板 * 获取小程序平台上的标准模板
*
* @param tempKey 模板编号 * @param tempKey 模板编号
* @return List * @return List
*/ */
...@@ -775,6 +855,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -775,6 +855,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 添加小程序订阅消息 * 添加小程序订阅消息
*
* @param tempKey 模板编号 * @param tempKey 模板编号
* @param kidList 小程序订阅消息模板kid数组 * @param kidList 小程序订阅消息模板kid数组
* @return 小程序订阅消息模板编号(自己的) * @return 小程序订阅消息模板编号(自己的)
...@@ -804,6 +885,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -804,6 +885,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取手机号信息 * 获取手机号信息
*
* @param code 手机号获取凭证 * @param code 手机号获取凭证
* @return 微信手机号信息 * @return 微信手机号信息
*/ */
...@@ -835,10 +917,11 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -835,10 +917,11 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取JS-SDK的签名 * 获取JS-SDK的签名
* @param nonceStr 随机字符串 *
* @param ticket ticket * @param nonceStr 随机字符串
* @param ticket ticket
* @param timestamp 时间戳 * @param timestamp 时间戳
* @param url url * @param url url
* @return 签名 * @return 签名
*/ */
private String getJsSDKSignature(String nonceStr, String ticket, Long timestamp, String url) { private String getJsSDKSignature(String nonceStr, String ticket, Long timestamp, String url) {
...@@ -850,6 +933,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -850,6 +933,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取JS-SDK的ticket * 获取JS-SDK的ticket
* 用于计算签名 * 用于计算签名
*
* @return ticket * @return ticket
*/ */
private String getJsApiTicket() { private String getJsApiTicket() {
...@@ -878,9 +962,10 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -878,9 +962,10 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 获取微信accessToken * 获取微信accessToken
* @param appId appId *
* @param appId appId
* @param secret secret * @param secret secret
* @param type mini-小程序,public-公众号,app-app * @param type mini-小程序,public-公众号,app-app
* @return WeChatAccessTokenVo * @return WeChatAccessTokenVo
*/ */
private WeChatAccessTokenVo getAccessToken(String appId, String secret, String type) { private WeChatAccessTokenVo getAccessToken(String appId, String secret, String type) {
...@@ -901,8 +986,9 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -901,8 +986,9 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信异常处理 * 微信异常处理
*
* @param jsonObject 微信返回数据 * @param jsonObject 微信返回数据
* @param remark 备注 * @param remark 备注
*/ */
private void wxExceptionDispose(JSONObject jsonObject, String remark) { private void wxExceptionDispose(JSONObject jsonObject, String remark) {
WechatExceptions wechatExceptions = new WechatExceptions(); WechatExceptions wechatExceptions = new WechatExceptions();
...@@ -917,7 +1003,8 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -917,7 +1003,8 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信支付异常处理 * 微信支付异常处理
* @param map 微信返回数据 *
* @param map 微信返回数据
* @param remark 备注 * @param remark 备注
*/ */
private void wxPayExceptionDispose(HashMap<String, Object> map, String remark) { private void wxPayExceptionDispose(HashMap<String, Object> map, String remark) {
...@@ -939,6 +1026,7 @@ public class WechatNewServiceImpl implements WechatNewService { ...@@ -939,6 +1026,7 @@ public class WechatNewServiceImpl implements WechatNewService {
/** /**
* 微信支付查询异常处理 * 微信支付查询异常处理
*
* @param record 微信返回数据 * @param record 微信返回数据
* @param remark 备注 * @param remark 备注
*/ */
......
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