doum
8 小时以前 59b1f0e9967902aa10f5e017d5a0bdfd1b60c9ea
server/services/src/main/java/com/doumee/config/wx/WxPayV3Service.java
@@ -2,12 +2,12 @@
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.ID;
import com.wechat.pay.java.core.notification.RequestParam;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import com.wechat.pay.java.service.refund.model.AmountReq;
import com.wechat.pay.java.service.refund.model.CreateRequest;
import com.wechat.pay.java.service.refund.model.QueryByOutRefundNoRequest;
import com.wechat.pay.java.service.refund.model.Refund;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
@@ -59,7 +59,7 @@
            com.wechat.pay.java.service.payments.jsapi.model.Amount amount =
                    new com.wechat.pay.java.service.payments.jsapi.model.Amount();
            amount.setTotal(1);//totalCents.intValue());
            amount.setTotal(totalCents.intValue());
            amount.setCurrency("CNY");
            request.setAmount(amount);
@@ -88,6 +88,7 @@
    /**
     * V3退款
     *
     * @param outRefundNo  商户退款单号(由调用方生成)
     * @param outTradeNo   商户订单号
     * @param totalCents   原订单金额(分)
     * @param refundCents  退款金额(分)
@@ -95,14 +96,12 @@
     * @param notifyUrl    退款回调地址
     * @return Refund 退款结果(包含 outRefundNo、status 等)
     */
    public Refund refund(String outTradeNo, Long totalCents, Long refundCents,
    public Refund refund(String outRefundNo, String outTradeNo, Long totalCents, Long refundCents,
                         String reason, String notifyUrl) {
        if (WxMiniConfig.v3RefundService == null) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "微信支付V3未初始化");
        }
        try {
            String outRefundNo = ID.nextGUID();
            CreateRequest request = new CreateRequest();
            request.setOutTradeNo(outTradeNo);
            request.setOutRefundNo(outRefundNo);
@@ -110,8 +109,8 @@
            request.setNotifyUrl(notifyUrl);
            AmountReq amount = new AmountReq();
            amount.setRefund(1L);//refundCents);
            amount.setTotal(1L);//totalCents);
            amount.setRefund(refundCents);
            amount.setTotal(totalCents);
            amount.setCurrency("CNY");
            request.setAmount(amount);
@@ -183,4 +182,26 @@
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "退款回调验签失败");
        }
    }
    /**
     * 查询单笔退款
     *
     * @param outRefundNo 商户退款单号
     * @return Refund 退款结果
     */
    public Refund queryRefund(String outRefundNo) {
        if (WxMiniConfig.v3RefundService == null) {
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "微信支付V3未初始化");
        }
        try {
            QueryByOutRefundNoRequest request = new QueryByOutRefundNoRequest();
            request.setOutRefundNo(outRefundNo);
            Refund result = WxMiniConfig.v3RefundService.queryByOutRefundNo(request);
            log.info("微信支付V3查询单笔退款, outRefundNo={}, status={}", outRefundNo, result.getStatus());
            return result;
        } catch (Exception e) {
            log.error("微信支付V3查询退款失败: {}", e.getMessage(), e);
            throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "查询退款失败:" + e.getMessage());
        }
    }
}