代码如下
@PostConstructpublic 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());}
