|
@@ -0,0 +1,89 @@
|
|
|
+package com.rongwei.zhsw.system.utils;
|
|
|
+import com.wechat.pay.java.core.Config;
|
|
|
+import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
|
|
+import com.wechat.pay.java.core.exception.HttpException;
|
|
|
+import com.wechat.pay.java.core.exception.MalformedMessageException;
|
|
|
+import com.wechat.pay.java.core.exception.ServiceException;
|
|
|
+import com.wechat.pay.java.service.refund.RefundService;
|
|
|
+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 org.springframework.core.io.ClassPathResource;
|
|
|
+
|
|
|
+public class WxRefundApi {
|
|
|
+ /**
|
|
|
+ * 商户号
|
|
|
+ */
|
|
|
+ public String merchantId = "1711246421";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商户API私钥路径
|
|
|
+ */
|
|
|
+ public String privateKeyPath = "D:\\code\\project\\zhsw\\zhsw_service\\zhsw-server\\src\\main\\resources\\cert\\apiclient_key.pem";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商户证书序列号
|
|
|
+ */
|
|
|
+ public String merchantSerialNumber = "6F46F471C22D410F9ECEDC8B197979A4CA42BC96";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 商户APIV3密钥
|
|
|
+ */
|
|
|
+ public String apiV3Key = "GBA67AVWJESPJ3TFJ3GT3NLQBEOTO1FW";
|
|
|
+
|
|
|
+ public RefundService service;
|
|
|
+
|
|
|
+ public void initMerchant() {
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource("cert/apiclient_key.pem");
|
|
|
+ Config config =
|
|
|
+ new RSAAutoCertificateConfig.Builder()
|
|
|
+ .merchantId(merchantId)
|
|
|
+ // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
|
|
+ .privateKeyFromPath(privateKeyPath)
|
|
|
+ .merchantSerialNumber(merchantSerialNumber)
|
|
|
+ .apiV3Key(apiV3Key)
|
|
|
+ .build();
|
|
|
+ service = new RefundService.Builder().config(config).build();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 退款申请 */
|
|
|
+ public Refund create() {
|
|
|
+ CreateRequest request = new CreateRequest();
|
|
|
+ // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
+ // 调用接口
|
|
|
+ // 微信支付订单号
|
|
|
+ request.setTransactionId("");
|
|
|
+ // 商户订单号
|
|
|
+ request.setOutTradeNo("");
|
|
|
+ // 商户退款单号
|
|
|
+ request.setOutRefundNo("");
|
|
|
+ // 退款原因
|
|
|
+ request.setReason("");
|
|
|
+ // 退款结果回调url
|
|
|
+ request.setNotifyUrl("");
|
|
|
+ // 退款资金来源
|
|
|
+// request.setFundsAccount("AVAILABLE");
|
|
|
+ // 金额信息
|
|
|
+ AmountReq amount = new AmountReq();
|
|
|
+ // 退款金额
|
|
|
+ amount.setRefund(1L);
|
|
|
+ // 原订单金额
|
|
|
+ amount.setTotal(1L);
|
|
|
+ // 退款币种
|
|
|
+ amount.setCurrency("CNY");
|
|
|
+ request.setAmount(amount);
|
|
|
+ return service.create(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 查询单笔退款(通过商户退款单号) */
|
|
|
+ public Refund queryByOutRefundNo() {
|
|
|
+
|
|
|
+ QueryByOutRefundNoRequest request = new QueryByOutRefundNoRequest();
|
|
|
+ // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
+ // 调用接口
|
|
|
+ // 商户退款单号
|
|
|
+ request.setOutRefundNo("");
|
|
|
+ return service.queryByOutRefundNo(request);
|
|
|
+ }
|
|
|
+}
|