| @@ -507,98 +507,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| */ | */ | ||||
| } | } | ||||
| @Override | |||||
| public void sendPaySuccess() { | |||||
| /* | |||||
| WxAppinfo appinfoQ = new WxAppinfo(); | |||||
| appinfoQ.setTenantId("234"); | |||||
| appinfoQ.setType(EnumAppType.C.getCode()); | |||||
| List<WxAppinfo> appinfoList= wxAppinfoMapper.select(appinfoQ); | |||||
| WxAppinfo appinfo = appinfoList.get(0); | |||||
| String payOrderIdStr = "196936823522459648"; | |||||
| Long payOrderId = Long.valueOf(payOrderIdStr); | |||||
| WxPayOrder updateOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); | |||||
| WxOrder order = wxOrderMapper.selectByPrimaryKey(updateOrder.getOrderId()); | |||||
| sendPaySuccessMsg(appinfo, order, updateOrder); | |||||
| */ | |||||
| } | |||||
| /** | |||||
| * 微信模板通知用户 | |||||
| * @param updateOrder | |||||
| * 支付时间 {{keyword1.DATA}} | |||||
| * 支付方式 {{keyword2.DATA}} | |||||
| * 支付金额 {{keyword3.DATA}} | |||||
| * 商品名称 {{keyword4.DATA}} | |||||
| * 商家名称 {{keyword5.DATA}} | |||||
| * 订单状态 {{keyword6.DATA}} | |||||
| */ | |||||
| private void sendPaySuccessMsg(WxAppinfo appInfo, WxOrder order, WxPayOrder updateOrder) { | |||||
| // 1. get template id | |||||
| WxTemplateMsg msgQ = new WxTemplateMsg(); | |||||
| msgQ.setTenantId(order.getTenantId()); | |||||
| msgQ.setType(EnumTemplateType.PAY_SUCCESS.getCode()); | |||||
| WxTemplateMsg msg = null; | |||||
| List<WxTemplateMsg> list= wxTemplateMsgMapper.select(msgQ); | |||||
| if (list.size() > 0) { | |||||
| msg = list.get(0); | |||||
| } | |||||
| if (msg == null) { | |||||
| logger.error("找不到模板Id"); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_NOT_FOUND); | |||||
| } | |||||
| // 2. get coupon info | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(order.getCouponId()); | |||||
| if (coupon == null) { | |||||
| logger.error("找不到券信息"); | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| // 3. merchant info | |||||
| WxMerchant merchant = wxMerchantMapper.selectByPrimaryKey(order.getMerchantId()); | |||||
| if (merchant == null) { | |||||
| logger.error("找不到商户信息"); | |||||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||||
| } | |||||
| // 3. get user info | |||||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(order.getCUserId()); | |||||
| if (user == null) { | |||||
| logger.error("找不到C端用户"); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if (StringUtils.isBlank(updateOrder.getPrepayId())) { | |||||
| logger.error("prepayId为空"); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| WxMaService wxMaService = MaUtil.getWeappService(appInfo); | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | |||||
| WxMaTemplateMessage templateMessage = WxMaTemplateMessage.builder() | |||||
| .toUser(user.getOpenId()) | |||||
| .formId(updateOrder.getPrepayId()) // 微信支付的formId是prepayId | |||||
| .page("pages/index/index") | |||||
| .data(Lists.newArrayList( | |||||
| new WxMaTemplateMessage.Data("keyword1", dateFormat.format(new Date()), "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword2", "微信支付", "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword3", String.valueOf(updateOrder.getPayAmount()*1.0/100) + "元", "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword4", coupon.getTitle(), "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword5", merchant.getName(), "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword6", EnumOrderStatus.getEnum(order.getOrderStatus()).getMessage(), "#173177"))) | |||||
| .templateId(msg.getTemplateId()) | |||||
| .emphasisKeyword("keyword1.DATA") | |||||
| .build(); | |||||
| //templateMessage.addData( new WxMaTemplateMessage.Data("keyword1", "339208499", "#173177")); | |||||
| try { | |||||
| wxMaService.getMsgService().sendTemplateMsg(templateMessage); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error("支付通知发送失败: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| } | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public void handlePayOrderStatusUpdate(WxPayOrder record) { | public void handlePayOrderStatusUpdate(WxPayOrder record) { | ||||
| @@ -712,5 +620,95 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| wxPayOrderMapper.deleteByPrimaryKey(id); | wxPayOrderMapper.deleteByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public void sendPaySuccess() { | |||||
| /* | |||||
| WxAppinfo appinfoQ = new WxAppinfo(); | |||||
| appinfoQ.setTenantId("234"); | |||||
| appinfoQ.setType(EnumAppType.C.getCode()); | |||||
| List<WxAppinfo> appinfoList= wxAppinfoMapper.select(appinfoQ); | |||||
| WxAppinfo appinfo = appinfoList.get(0); | |||||
| String payOrderIdStr = "196936823522459648"; | |||||
| Long payOrderId = Long.valueOf(payOrderIdStr); | |||||
| WxPayOrder updateOrder = wxPayOrderMapper.selectByPrimaryKey(payOrderId); | |||||
| WxOrder order = wxOrderMapper.selectByPrimaryKey(updateOrder.getOrderId()); | |||||
| sendPaySuccessMsg(appinfo, order, updateOrder); | |||||
| */ | |||||
| } | |||||
| /** | |||||
| * 微信模板通知用户 | |||||
| * @param updateOrder | |||||
| * 支付时间 {{keyword1.DATA}} | |||||
| * 支付方式 {{keyword2.DATA}} | |||||
| * 支付金额 {{keyword3.DATA}} | |||||
| * 商品名称 {{keyword4.DATA}} | |||||
| * 商家名称 {{keyword5.DATA}} | |||||
| * 订单状态 {{keyword6.DATA}} | |||||
| */ | |||||
| private void sendPaySuccessMsg(WxAppinfo appInfo, WxOrder order, WxPayOrder updateOrder) { | |||||
| // 1. get template id | |||||
| WxTemplateMsg msgQ = new WxTemplateMsg(); | |||||
| msgQ.setTenantId(order.getTenantId()); | |||||
| msgQ.setType(EnumTemplateType.PAY_SUCCESS.getCode()); | |||||
| WxTemplateMsg msg = null; | |||||
| List<WxTemplateMsg> list= wxTemplateMsgMapper.select(msgQ); | |||||
| if (list.size() > 0) { | |||||
| msg = list.get(0); | |||||
| } | |||||
| if (msg == null) { | |||||
| logger.error("找不到模板Id"); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_NOT_FOUND); | |||||
| } | |||||
| // 2. get coupon info | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(order.getCouponId()); | |||||
| if (coupon == null) { | |||||
| logger.error("找不到券信息"); | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| // 3. merchant info | |||||
| WxMerchant merchant = wxMerchantMapper.selectByPrimaryKey(order.getMerchantId()); | |||||
| if (merchant == null) { | |||||
| logger.error("找不到商户信息"); | |||||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||||
| } | |||||
| // 3. get user info | |||||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(order.getCUserId()); | |||||
| if (user == null) { | |||||
| logger.error("找不到C端用户"); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| if (StringUtils.isBlank(updateOrder.getPrepayId())) { | |||||
| logger.error("prepayId为空"); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| WxMaService wxMaService = MaUtil.getWeappService(appInfo); | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); | |||||
| WxMaTemplateMessage templateMessage = WxMaTemplateMessage.builder() | |||||
| .toUser(user.getOpenId()) | |||||
| .formId(updateOrder.getPrepayId()) // 微信支付的formId是prepayId | |||||
| .page("pages/index/index") | |||||
| .data(Lists.newArrayList( | |||||
| new WxMaTemplateMessage.Data("keyword1", dateFormat.format(new Date()), "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword2", "微信支付", "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword3", String.valueOf(updateOrder.getPayAmount()*1.0/100) + "元", "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword4", coupon.getTitle(), "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword5", merchant.getName(), "#173177"), | |||||
| new WxMaTemplateMessage.Data("keyword6", EnumOrderStatus.getEnum(order.getOrderStatus()).getMessage(), "#173177"))) | |||||
| .templateId(msg.getTemplateId()) | |||||
| .emphasisKeyword("keyword1.DATA") | |||||
| .build(); | |||||
| //templateMessage.addData( new WxMaTemplateMessage.Data("keyword1", "339208499", "#173177")); | |||||
| try { | |||||
| wxMaService.getMsgService().sendTemplateMsg(templateMessage); | |||||
| } catch (WxErrorException e) { | |||||
| logger.error("支付通知发送失败: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| } | |||||
| } | } | ||||