package com.doumee.api.web; import com.doumee.config.wx.WxMiniConfig; import com.doumee.core.constants.Constants; import com.doumee.core.utils.ID; import com.doumee.service.business.OrdersService; import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RestController; import java.util.Date; import java.util.Objects; /** * 支付回调 * * @Author : Rk * @create 2023/3/24 16:57 */ @Slf4j @RestController @CrossOrigin public class PaymentCallback extends ApiController { @Autowired private OrdersService ordersService; @PostMapping("/web/api/wxPayNotify") public String wxPay_notify(@RequestBody String xmlResult) { String wxId = ID.nextGUID(); log.info("支付回调信息("+wxId+") = > " + xmlResult); if (StringUtils.isEmpty(xmlResult)){ return null; } try { WxPayOrderNotifyResult result = WxMiniConfig.wxPayService.parseOrderNotifyResult(xmlResult); //自定义订单号 String outTradeNo = result.getOutTradeNo(); //微信订单号 String paymentNo = result.getTransactionId(); if (Constants.SUCCESS.equals(result.getReturnCode())) { // 支付成功 switch (result.getAttach()) { //寄存订单 case "storageOrder": { ordersService.handleStorageOrderPayNotify(outTradeNo, paymentNo); break; } //店铺押金订单 case "shopDeposit": { ordersService.handleShopDepositPayNotify(outTradeNo, paymentNo); break; } //逾期费用订单 case "overdueFee": { ordersService.handleOverdueFeePayNotify(outTradeNo, paymentNo); break; } } return WxPayNotifyResponse.success("处理成功!"); } return WxPayNotifyResponse.fail(result.getReturnMsg()); } catch (Exception e) { e.printStackTrace(); log.error("微信回调结果异常,异常原因{}", e.getLocalizedMessage()); return WxPayNotifyResponse.fail(e.getMessage()); } } }