nidapeng
2024-03-19 6c40e04eb7c2060feb2533735cd3089d438965e5
server/dmvisit_service/src/main/java/com/doumee/core/wx/WxMiniUtilService.java
@@ -3,10 +3,10 @@
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.core.utils.ID;
import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
import com.github.binarywang.wxpay.exception.WxPayException;
//import com.github.binarywang.wxpay.bean.request.BaseWxPayRequest;
//import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
//import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
//import com.github.binarywang.wxpay.exception.WxPayException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -20,34 +20,34 @@
@Slf4j
public class WxMiniUtilService {
    /**
     * 订单微信退款
     * orderNo:商户订单号
     * totalPrice:订单总金额
     * refundPrice;退款金额
     */
    @Transactional(rollbackFor = Exception.class)
    public static String wxRefund(String orderNo, BigDecimal totalPrice, BigDecimal refundPrice) {
        try {
            // 发送退款请求
            String refNum = ID.nextGUID();
            WxPayRefundRequest request = new WxPayRefundRequest();
            request.setOutTradeNo(orderNo);
            request.setOutRefundNo(refNum);
           // request.setTotalFee(2);
          //  request.setRefundFee(1);
            request.setTotalFee(BaseWxPayRequest.yuanToFen(totalPrice.toString()));
            request.setRefundFee(BaseWxPayRequest.yuanToFen(refundPrice.toString()));
            WxPayRefundResult response = WxMiniConfig.wxPayService.refund(request);
            if ("SUCCESS".equals(response.getReturnCode()) && "SUCCESS".equals(response.getResultCode())) {
                return refNum;
            } else {
                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),response.getErrCode() + response.getErrCodeDes());
            }
        } catch (WxPayException e) {
            e.printStackTrace();
        }
        throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"退款发生异常请联系管理员");
    }
//
//    /**
//     * 订单微信退款
//     * orderNo:商户订单号
//     * totalPrice:订单总金额
//     * refundPrice;退款金额
//     */
//    @Transactional(rollbackFor = Exception.class)
//    public static String wxRefund(String orderNo, BigDecimal totalPrice, BigDecimal refundPrice) {
//        try {
//            // 发送退款请求
//            String refNum = ID.nextGUID();
//            WxPayRefundRequest request = new WxPayRefundRequest();
//            request.setOutTradeNo(orderNo);
//            request.setOutRefundNo(refNum);
//           // request.setTotalFee(2);
//          //  request.setRefundFee(1);
//            request.setTotalFee(BaseWxPayRequest.yuanToFen(totalPrice.toString()));
//            request.setRefundFee(BaseWxPayRequest.yuanToFen(refundPrice.toString()));
//            WxPayRefundResult response = WxMiniConfig.wxPayService.refund(request);
//            if ("SUCCESS".equals(response.getReturnCode()) && "SUCCESS".equals(response.getResultCode())) {
//                return refNum;
//            } else {
//                throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),response.getErrCode() + response.getErrCodeDes());
//            }
//        } catch (WxPayException e) {
//            e.printStackTrace();
//        }
//        throw  new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"退款发生异常请联系管理员");
//    }
}