代码如下
@PostConstruct
public void init() {
log.info("微信支付初始化 appId={}", appId);
WxPayService wxPayService = new WxPayServiceImpl();
WxPayConfig payConfig = new WxPayConfig();
payConfig.setAppId(appId);
payConfig.setMchId(mchId);
payConfig.setMchKey(mchKey);
// 证书配置
payConfig.setKeyPath("classpath:cert/apiclient_cert.p12");
wxPayService.setConfig(payConfig);
payService = wxPayService;
log.info("微信支付初始化完毕 ");
}
退款代码如下
WxPayRefundRequest request = new WxPayRefundRequest();
Integer totalFee = price.multiply(new BigDecimal("100")).intValue();
Integer refundFee = totalFee;
// 订单金额
request.setTotalFee(totalFee);
// 退款金额
request.setRefundFee(refundFee);
// 商户订单号
request.setOutTradeNo(orderNo);
// 商户退款单号
request.setOutRefundNo(refundNo);
// 回调地址
request.setNotifyUrl(WxConstants.notifyUrl);
WxPayService wxPayService = WxPayAutoConfiguration.getWxPayService();
try {
return wxPayService.refund(request);
} catch (WxPayException e) {
throw new BusinessException(e.getMessage());
}