分类: Java
2022-11-22 18:08:42
package com.cy.xgsm.controller;
import java.math.BigDecimal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.cy.xgsm.common.Result;
import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request;
import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result;
import com.github.binarywang.wxpay.service.WxPayService;
/**
*
* @author Dylan
*
*/
@RestController
public class WxPayController {
@Autowired
@Qualifier("wxPayService")
private WxPayService wxPayService;
/**
* 申请退款
* @param orderNo 充值单号
* @param amount 退款金额
*/
@GetMapping("/refundV3/nativePay")
@ResponseBody
public Result
Result
//微信支付-申请退款请求参数
WxPayRefundV3Request request = new WxPayRefundV3Request();
WxPayRefundV3Request.Amount am =跟单网gendan5.com new WxPayRefundV3Request.Amount();
am.setTotal(amount.multiply(new BigDecimal(100)).intValue());//原订单金额
//退款币种,符合ISO 4217标准的三位字母代码,目前只支持人民币:CNY。
am.setCurrency("CNY");
//退款金额 注意:退款金额,单位为分,只能为整数,不能超过原订单支付金额。
am.setRefund(amount.multiply(new BigDecimal(100)).intValue());
//金额信息
request.setAmount(am);
//transaction_id:微信支付订单号
request.setTransactionId(orderNo);
//商户订单号
request.setOutRefundNo("return_"+orderNo);
WxPayRefundV3Result result;
try {
//调用微信V3退款API
result = wxPayService.refundV3(request);
String status = result.getStatus();
switch (status) {
case "SUCCESS":
res.success("退款成功");
break;
case "CLOSED":
res.success("退款关闭");
break;
case "PROCESSING":
res.success("退款处理中");
break;
case "ABNORMAL":
res.success("退款异常");
break;
default:
res.error("受理失败");
break;
}
res.setAtt(result);
} catch (Exception e) {
res.error("申请退款失败,"+e.getMessage());
}
return res;
}
}