| @@ -1,9 +1,13 @@ | |||
| package com.iformall.controller.callback; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.controller.base.BaseController; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.domain.po.msg.FmInsideNotifyPaySuccessMsg; | |||
| import com.iformall.domain.po.msg.FmInsideNotifyRefundSuccessMsg; | |||
| import com.iformall.enums.*; | |||
| import com.iformall.exception.BizMessageException; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mq.MqBaseProducer; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| @@ -38,10 +42,10 @@ public class WxPayController extends BaseController { | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Autowired | |||
| private WxRefundOrderService wxRefundOrderService; | |||
| private WxSubsidyService wxSubsidyService; | |||
| @Autowired | |||
| private WxSubsidyService wxSubsidyService; | |||
| private MqBaseProducer mqBaseProducer; | |||
| /** | |||
| * | |||
| * @return 接收微信异步通知 | |||
| @@ -66,12 +70,29 @@ public class WxPayController extends BaseController { | |||
| Map<String, String> paramMap = null; | |||
| try { | |||
| paramMap = WxPayment.xmlToMap(resultxml); | |||
| logger.info("微信支付回调, notify, param: " + paramMap.toString() ); | |||
| String response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| logger.info("微信支付回调, notify success, req : " + resultxml + ", resp: " + response.toString()); | |||
| return response; | |||
| String jsonMsg = JSON.toJSONString(paramMap); | |||
| FmInsideNotifyPaySuccessMsg paySuccessMsg = new FmInsideNotifyPaySuccessMsg(); | |||
| paySuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode()); | |||
| paySuccessMsg.setDelayTimeLevel(3); | |||
| paySuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||
| paySuccessMsg.setJsonMsg(jsonMsg); | |||
| // String response = wxPayOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| mqBaseProducer.sendMessage(paySuccessMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| logger.info("微信支付回调, notify success, req : " + resultxml); | |||
| SortedMap resultMap = new TreeMap(); | |||
| resultMap.put("return_code", "SUCCESS"); | |||
| resultMap.put("return_msg", "OK"); | |||
| return XmlUtil.getRequestXml(resultMap); | |||
| } catch (BizMessageException e) { | |||
| if (paramMap == null) { | |||
| logger.error("微信支付回调, order create error, e: " + e.getMessage()); | |||
| @@ -121,7 +142,17 @@ public class WxPayController extends BaseController { | |||
| xml = IOUtils.toString(request.getInputStream(), Charset.forName("UTF-8")); | |||
| logger.info(xml); | |||
| paramMap = WxPayment.xmlToMap(xml); | |||
| response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| String jsonMsg = JSON.toJSONString(paramMap); | |||
| FmInsideNotifyRefundSuccessMsg refundSuccessMsg = new FmInsideNotifyRefundSuccessMsg(); | |||
| refundSuccessMsg.setMsgType(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode()); | |||
| refundSuccessMsg.setDelayTimeLevel(3); | |||
| refundSuccessMsg.setPayWay(EnumPayWay.PAY_WAY_WEAPP.getCode()); | |||
| refundSuccessMsg.setJsonMsg(jsonMsg); | |||
| // response = wxRefundOrderService.notify(paramMap, EnumPayWay.PAY_WAY_WEAPP); | |||
| mqBaseProducer.sendMessage(refundSuccessMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||
| logger.info("refund wxpay, notify success, req : " + xml + ", resp: " + response.toString()); | |||
| return response; | |||
| } catch (BizMessageException e) { | |||
| @@ -5,6 +5,7 @@ import com.iformall.enums.*; | |||
| import com.iformall.mapper.WxMsgRecordMapper; | |||
| import com.iformall.service.msg.impl.*; | |||
| import com.iformall.utils.JsonUtil; | |||
| import org.checkerframework.checker.units.qual.A; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| @@ -37,6 +38,13 @@ public class MqBaseConsumer { | |||
| @Autowired | |||
| private MqBaseProducer mqBaseProducer; | |||
| @Autowired | |||
| private FmInsideNotifyPaySuccessMsgServiceImpl fmInsideNotifyPaySuccessMsgService; | |||
| @Autowired | |||
| private FmInsideNotifyRefundSuccessMsgServiceImpl fmInsideNotifyRefundSuccessMsgService; | |||
| public void doMessage(String message) { | |||
| log.info("received message: {}", message); | |||
| BaseMsg baseMsg = null; | |||
| @@ -80,6 +88,14 @@ public class MqBaseConsumer { | |||
| // 内部消息 - c端登录 | |||
| FmInsideCLoginMsg msg = (FmInsideCLoginMsg)JsonUtil.readValue(message,FmInsideCLoginMsg.class); | |||
| fmInsideCouponVerifyMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.INSIDE_NOTIFY_PAY_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 微信支付通知 | |||
| FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); | |||
| fmInsideNotifyPaySuccessMsgService.send(msg); | |||
| } else if(EnumMsgRecordType.INSIDE_NOTIFY_REFUND_SUCCESS.getCode().equals(baseMsg.getMsgType())) { | |||
| // 内部消息 - 微信退款通知 | |||
| FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg)JsonUtil.readValue(message,FmInsideNotifyPaySuccessMsg.class); | |||
| fmInsideNotifyRefundSuccessMsgService.send(msg); | |||
| } | |||
| baseMsg.setMsgStatus(EnumMsgRecordStatus.CONSUME_SUCC.getCode()); | |||
| wxMsgRecordMapper.update(baseMsg); | |||
| @@ -0,0 +1,18 @@ | |||
| package com.iformall.domain.po.msg; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class FmInsideNotifyPaySuccessMsg extends BaseMsg { | |||
| private static final long serialVersionUID = 1L; | |||
| @io.swagger.annotations.ApiModelProperty(value = "消息来源", name = "payWay") | |||
| private Integer payWay; | |||
| @io.swagger.annotations.ApiModelProperty(value = "消息内容", name = "jsonMsg") | |||
| private String jsonMsg; | |||
| } | |||
| @@ -0,0 +1,18 @@ | |||
| package com.iformall.domain.po.msg; | |||
| import lombok.Data; | |||
| import lombok.EqualsAndHashCode; | |||
| import lombok.ToString; | |||
| @Data | |||
| @ToString(callSuper = true) | |||
| @EqualsAndHashCode(callSuper = true) | |||
| public class FmInsideNotifyRefundSuccessMsg extends BaseMsg { | |||
| private static final long serialVersionUID = 1L; | |||
| @io.swagger.annotations.ApiModelProperty(value = "消息来源", name = "payWay") | |||
| private Integer payWay; | |||
| @io.swagger.annotations.ApiModelProperty(value = "消息内容", name = "jsonMsg") | |||
| private String jsonMsg; | |||
| } | |||
| @@ -15,6 +15,8 @@ public enum EnumMsgRecordType { | |||
| INSIDE_ORDER_SUCCESS(100, "下订单成功"), | |||
| INSIDE_COUPON_VERIFY(101, "券核销"), | |||
| INSIDE_C_LOGIN(102, "C端用户登录"), | |||
| INSIDE_NOTIFY_PAY_SUCCESS(103, "微信支付回调"), | |||
| INSIDE_NOTIFY_REFUND_SUCCESS(104, "微信退款回调"), | |||
| ; | |||
| public static EnumMsgRecordType getEnum(Integer code) { | |||
| @@ -871,11 +871,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| break; | |||
| } | |||
| } | |||
| updateOrder.setOrderStatus(enumOrderStatus.getCode()); | |||
| updateOrder.setUpdateDate(currentDate); | |||
| WxOrder refOrder = new WxOrder(); | |||
| refOrder.setId(updateOrder.getId()); | |||
| refOrder.setOrderStatus(enumOrderStatus.getCode()); | |||
| refOrder.setUpdateDate(currentDate); | |||
| int ret = 0; | |||
| try { | |||
| ret = wxOrderMapper.updateByPrimaryKey(updateOrder); | |||
| ret = wxOrderMapper.updateByPrimaryKey(refOrder); | |||
| } catch (Exception e) { | |||
| logger.error("订单状态更新失败, e:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
| @@ -0,0 +1,34 @@ | |||
| package com.iformall.service.msg.impl; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.domain.po.msg.FmInsideNotifyPaySuccessMsg; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.Map; | |||
| /** | |||
| * | |||
| * @author Stormeye Wu | |||
| * @date 2019/5/10 | |||
| */ | |||
| @Service | |||
| public class FmInsideNotifyPaySuccessMsgServiceImpl implements MsgSendService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxPayOrderService wxPayOrderService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) throws Exception { | |||
| FmInsideNotifyPaySuccessMsg msg = (FmInsideNotifyPaySuccessMsg)baseMsg; | |||
| Map<String, String> paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class); | |||
| wxPayOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay())); | |||
| } | |||
| } | |||
| @@ -0,0 +1,34 @@ | |||
| package com.iformall.service.msg.impl; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.iformall.domain.po.msg.BaseMsg; | |||
| import com.iformall.domain.po.msg.FmInsideNotifyRefundSuccessMsg; | |||
| import com.iformall.enums.EnumPayWay; | |||
| import com.iformall.service.WxRefundOrderService; | |||
| import com.iformall.service.msg.MsgSendService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import java.util.Map; | |||
| /** | |||
| * | |||
| * @author Stormeye Wu | |||
| * @date 2019/5/10 | |||
| */ | |||
| @Service | |||
| public class FmInsideNotifyRefundSuccessMsgServiceImpl implements MsgSendService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxRefundOrderService wxRefundOrderService; | |||
| @Override | |||
| public void send(BaseMsg baseMsg) throws Exception { | |||
| FmInsideNotifyRefundSuccessMsg msg = (FmInsideNotifyRefundSuccessMsg)baseMsg; | |||
| Map<String, String> paramMap = JSON.parseObject(msg.getJsonMsg(), Map.class); | |||
| wxRefundOrderService.notify(paramMap, EnumPayWay.getEnum(msg.getPayWay())); | |||
| } | |||
| } | |||