|
@@ -2,6 +2,7 @@ package com.pj.api.wx.service;
|
|
|
|
|
|
import cn.hutool.cache.CacheUtil;
|
|
|
import cn.hutool.cache.impl.TimedCache;
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.net.URLDecoder;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
@@ -38,6 +39,8 @@ import com.pj.project.tb_order.TbOrder;
|
|
|
import com.pj.project.tb_order.TbOrderService;
|
|
|
import com.pj.project.tb_pay_record.TbPayRecord;
|
|
|
import com.pj.project.tb_pay_record.TbPayRecordService;
|
|
|
+import com.pj.project.wx_send_msg.WxSendMsg;
|
|
|
+import com.pj.project.wx_send_msg.WxSendMsgService;
|
|
|
import com.pj.project4sp.global.BusinessException;
|
|
|
import com.pj.utils.cache.RedisUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -85,6 +88,9 @@ public class WxService {
|
|
|
@Resource
|
|
|
private TbGoodsService tbGoodsService;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private WxSendMsgService wxSendMsgService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 统一下单接口
|
|
@@ -253,10 +259,10 @@ public class WxService {
|
|
|
TbGoods tbGoods = tbGoodsService.getById(tbBusiness.getGoodsId());
|
|
|
List<TbBusinessCar> carList = tbBusinessCarService.findOtherBusinessCar(businessId);
|
|
|
carList.forEach(tbBusinessCar -> {
|
|
|
- String carType=tbBusinessCar.getCarType();
|
|
|
+ String carType = tbBusinessCar.getCarType();
|
|
|
//
|
|
|
- if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType)&&tbGoods.getChinaCarPay()==0
|
|
|
- ||TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType)&&tbGoods.getVietnamCarPay()==0){
|
|
|
+ if (TbItem.ItemTypeEnum.EMPTY_TYPE.getType().equals(carType) && tbGoods.getChinaCarPay() == 0
|
|
|
+ || TbItem.ItemTypeEnum.WEIGHT_TYPE.getType().equals(carType) && tbGoods.getVietnamCarPay() == 0) {
|
|
|
tbBusinessCar.setPay(1).setPayTime(now);
|
|
|
tbBusinessCarService.updateById(tbBusinessCar);
|
|
|
}
|
|
@@ -327,12 +333,31 @@ public class WxService {
|
|
|
}
|
|
|
|
|
|
@Async
|
|
|
- public void sendTemplateMsg(String templateId, String openid, MsgDataBO data, String detailUrl) {
|
|
|
+ public void sendTemplateMsg(String templateId, String openid, Object data, String detailUrl) {
|
|
|
+ if (StrUtil.isEmpty(openid)){
|
|
|
+ return;
|
|
|
+ }
|
|
|
String accessToken = RedisUtil.get(wxConfig.getAccessTokenKey());
|
|
|
BaseTemplate baseTemplate = new BaseTemplate(openid, templateId, detailUrl, data);
|
|
|
String json = JSON.toJSONString(baseTemplate);
|
|
|
String url = wxConfig.getSendMsgUrl().replace("ACCESS_TOKEN", accessToken);
|
|
|
String resp = HttpUtil.post(url, json);
|
|
|
+ JSONObject result = JSONUtil.parseObj(resp);
|
|
|
+ int code = result.getInt("errcode");
|
|
|
log.info("send wx msg{},{},{};return :{}", templateId, openid, JSONUtil.toJsonStr(data), resp);
|
|
|
+ WxSendMsg wxSendMsg = wxSendMsgService.findByOpenidAndDetailUrl(openid, detailUrl);
|
|
|
+ if (code != 0) {
|
|
|
+ if (wxSendMsg == null) {
|
|
|
+ wxSendMsg = new WxSendMsg();
|
|
|
+ wxSendMsg.setCreateTime(DateUtil.now());
|
|
|
+ }
|
|
|
+ wxSendMsg.setCode(code).setDetailUrl(detailUrl)
|
|
|
+ .setMsgData(JSONUtil.toJsonStr(data)).setOpenid(openid).setTemplateId(templateId)
|
|
|
+ .setReturnMsg(result.getStr("errmsg"));
|
|
|
+ wxSendMsgService.saveOrUpdate(wxSendMsg);
|
|
|
+ }else if (wxSendMsg != null){
|
|
|
+ wxSendMsgService.delete(wxSendMsg.getId());
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|