Pu Zhibing
2024-10-16 c4664502dfdaffff555b532e65b51a57ac8b29c2
ruoyi-service/ruoyi-payment/src/main/java/com/ruoyi/payment/controller/WxPayController.java
@@ -5,6 +5,7 @@
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.order.api.feignClient.ChargingOrderClient;
import com.ruoyi.order.api.feignClient.OrderClient;
import com.ruoyi.order.api.feignClient.ShoppingOrderClient;
import com.ruoyi.payment.api.vo.PaymentOrder;
import com.ruoyi.payment.api.vo.WxRefundNotifyResp;
import com.ruoyi.payment.wx.enums.RefundEnum;
@@ -41,6 +42,9 @@
    
    @Resource
    private ChargingOrderClient chargingOrderClient;
    @Resource
    private ShoppingOrderClient shoppingOrderClient;
@@ -119,7 +123,7 @@
     */
    @PostMapping("pay/notify")
    @ApiOperation("订单回调")
    public R<Map<String, Object>> payNotify(HttpServletRequest request) throws Exception {
    public void payNotify(HttpServletRequest request) throws Exception {
        try {
            Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {});
            log.info("支付回调:{}", params);
@@ -143,13 +147,10 @@
                    break;
            }
            wxV3Pay.ack();
            return R.ok(params);
        } catch (Exception e) {
            log.error("支付回调异常:{}", e, e);
            wxV3Pay.ack(false, e.getMessage());
            return R.fail("回调异常");
        }
    }
    
    /**
@@ -171,7 +172,7 @@
     * 退款回调
     */
    @PostMapping("refund/notify")
    public R<WxRefundNotifyResp> refundNotify(HttpServletRequest request) throws IOException {
    public void refundNotify(HttpServletRequest request) throws IOException {
        try {
            Map<String, Object> params = wxV3Pay.verifyNotify(request, new TypeReference<Map<String, Object>>() {
            });
@@ -191,10 +192,19 @@
            if (tradeState.equals(RefundEnum.SUCCESS.name())) {
                String substring = out_refund_no.substring(0, 3);
                switch (substring){
                    //购物订单
                    //充电订单
                    case "CDF":
                        chargingOrderClient.chargingOrderStartupFailureWxRefund(out_refund_no, refund_id, tradeState, success_time);
                        System.err.println("----充电启动失败退款回调通知");
                        break;
                    case "GDF":
                        shoppingOrderClient.cancelShoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time);
                        System.err.println("----商城订单取消退款回调通知");
                        break;
                    //充电订单
                    case "GWF":
                        chargingOrderClient.shoppingOrderWxRefund(out_refund_no, refund_id, tradeState, success_time);
                        System.err.println("----管理后台取消购物订单退款回调通知");
                        break;
                }
                
@@ -206,14 +216,13 @@
                resp.setRefund_id(refund_id);
                resp.setSuccess_time(success_time);
                wxV3Pay.ack();
                return R.ok(resp);
            } else {
                wxV3Pay.ack(false, "不是成功的退款状态");
            }
        } catch (Exception e) {
            e.printStackTrace();
            wxV3Pay.ack(false, e.getMessage());
        }
        return R.fail();
    }
    
    /**