|
|
@ -6,6 +6,9 @@ import com.github.binarywang.wxpay.config.WxPayConfig; |
|
|
import com.github.binarywang.wxpay.exception.WxPayException; |
|
|
import com.github.binarywang.wxpay.exception.WxPayException; |
|
|
import com.github.binarywang.wxpay.service.WxPayService; |
|
|
import com.github.binarywang.wxpay.service.WxPayService; |
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; |
|
|
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; |
|
|
|
|
|
import com.qniao.dam.api.command.notify.user.response.WeChatNotification; |
|
|
|
|
|
import com.qniao.dam.api.command.notify.user.response.WeChatNotificationVo; |
|
|
|
|
|
import com.qniao.dam.application.service.paymentchannelorder.processor.wechat.utils.WXPayV3Util; |
|
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.PaymentChannelOrderAggregate; |
|
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.PaymentChannelOrderAggregate; |
|
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
|
|
import com.qniao.dam.domain.aggregate.paymentchannelorder.entity.PaymentChannelOrder; |
|
|
import com.qniao.dam.domian.aggregate.paymentchannelorder.constant.PaymentChannelOrderStatusEnum; |
|
|
import com.qniao.dam.domian.aggregate.paymentchannelorder.constant.PaymentChannelOrderStatusEnum; |
|
|
@ -13,14 +16,18 @@ import com.qniao.dam.infrastructure.persistent.dao.domain.PaymentChannelOrderDao |
|
|
import com.qniao.domain.BaseApplicationService; |
|
|
import com.qniao.domain.BaseApplicationService; |
|
|
import com.qniao.domain.BaseDomainEvent; |
|
|
import com.qniao.domain.BaseDomainEvent; |
|
|
import com.qniao.framework.exception.BizException; |
|
|
import com.qniao.framework.exception.BizException; |
|
|
|
|
|
import com.qniao.framework.utils.TypeConvertUtils; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.Assert; |
|
|
import org.springframework.util.Assert; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.RoundingMode; |
|
|
import java.math.RoundingMode; |
|
|
|
|
|
import java.time.LocalDateTime; |
|
|
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
|
|
|
|
|
@Service |
|
|
@Service |
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@ -34,29 +41,34 @@ public class NotifyApplicationService extends BaseApplicationService { |
|
|
private static final String WX_FAIL_RTN = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[报文为空]]></return_msg></xml>"; |
|
|
private static final String WX_FAIL_RTN = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[报文为空]]></return_msg></xml>"; |
|
|
public static final String RETURN_VALUE_SUCCESS = "SUCCESS"; |
|
|
public static final String RETURN_VALUE_SUCCESS = "SUCCESS"; |
|
|
|
|
|
|
|
|
|
|
|
public DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); |
|
|
|
|
|
|
|
|
@Resource |
|
|
@Resource |
|
|
private PaymentChannelOrderDao paymentChannelOrderDao; |
|
|
private PaymentChannelOrderDao paymentChannelOrderDao; |
|
|
@Resource |
|
|
@Resource |
|
|
private PaymentChannelOrderAggregate paymentChannelOrderAggregate; |
|
|
private PaymentChannelOrderAggregate paymentChannelOrderAggregate; |
|
|
|
|
|
@Resource |
|
|
|
|
|
private WXPayV3Util wxPayV3Util; |
|
|
|
|
|
|
|
|
public String wx(String xmlResult) { |
|
|
|
|
|
|
|
|
public WeChatNotificationVo wx(HttpServletRequest request) { |
|
|
|
|
|
WeChatNotificationVo notificationVo = new WeChatNotificationVo(); |
|
|
try { |
|
|
try { |
|
|
WxPayOrderNotifyResult result = parseOrderNotifyResult(xmlResult); |
|
|
|
|
|
// 查询订单 |
|
|
|
|
|
PaymentChannelOrder paymentChannelOrder = paymentChannelOrderDao.selectById(result.getOutTradeNo()); |
|
|
|
|
|
Assert.notNull(paymentChannelOrder, "支付订单不存在"); |
|
|
|
|
|
// 验证业务数据是否正确 |
|
|
|
|
|
checkWxPayParams(result, paymentChannelOrder); |
|
|
|
|
|
// 更新订单信息 |
|
|
|
|
|
paymentChannelOrder.setPaidTime(DateUtil.parseLocalDateTime(result.getTimeEnd(), "yyyyMMddHHmmss")); |
|
|
|
|
|
paymentChannelOrder.setExtOrderNo(result.getTransactionId()); |
|
|
|
|
|
BaseDomainEvent event = paymentChannelOrderAggregate.paid(paymentChannelOrder); |
|
|
|
|
|
this.sendEvent(event); |
|
|
|
|
|
return WX_SUCCESS_RTN; |
|
|
|
|
|
} catch (WxPayException e) { |
|
|
|
|
|
|
|
|
WeChatNotification notification = wxPayV3Util.weChatNotificationHandler(request); |
|
|
|
|
|
notificationVo = TypeConvertUtils.convert(notification, WeChatNotificationVo.class); |
|
|
|
|
|
if (RETURN_VALUE_SUCCESS.equals(notification.getCode())) { |
|
|
|
|
|
// 查询订单 |
|
|
|
|
|
PaymentChannelOrder paymentChannelOrder = paymentChannelOrderDao.selectById(notification.getOutTradeNo()); |
|
|
|
|
|
Assert.notNull(paymentChannelOrder, "支付订单不存在"); |
|
|
|
|
|
// 更新订单信息 |
|
|
|
|
|
paymentChannelOrder.setPaidTime(LocalDateTime.parse(notification.getSuccessTime(), formatter)); |
|
|
|
|
|
paymentChannelOrder.setExtOrderNo(notification.getTransactionId()); |
|
|
|
|
|
BaseDomainEvent event = paymentChannelOrderAggregate.paid(paymentChannelOrder); |
|
|
|
|
|
this.sendEvent(event); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
log.error("微信回调结果异常,异常原因", e); |
|
|
log.error("微信回调结果异常,异常原因", e); |
|
|
} |
|
|
} |
|
|
return WX_FAIL_RTN; |
|
|
|
|
|
|
|
|
return notificationVo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private WxPayOrderNotifyResult parseOrderNotifyResult(String xmlResult) throws WxPayException { |
|
|
private WxPayOrderNotifyResult parseOrderNotifyResult(String xmlResult) throws WxPayException { |
|
|
|