|
@@ -0,0 +1,54 @@
|
|
|
+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.payments.jsapi.JsapiServiceExtension;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.CloseOrderRequest;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.QueryOrderByIdRequest;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.QueryOrderByOutTradeNoRequest;
|
|
|
+import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
+
|
|
|
+
|
|
|
+public class WxApi {
|
|
|
+ /** 商户号 */
|
|
|
+ public String merchantId = "1711246421";
|
|
|
+
|
|
|
+ /** 商户API私钥路径 */
|
|
|
+ public String privateKeyPath = "D:\\code\\project\\zhsw\\zhsw_service\\zhsw-common\\src\\main\\resources\\cert\\apiclient_key.pem";
|
|
|
+
|
|
|
+ /** 商户证书序列号 */
|
|
|
+ public String merchantSerialNumber = "6F46F471C22D410F9ECEDC8B197979A4CA42BC96";
|
|
|
+
|
|
|
+ /** 商户APIV3密钥 */
|
|
|
+ public String apiV3Key = "GBA67AVWJESPJ3TFJ3GT3NLQBEOTO1FW";
|
|
|
+
|
|
|
+ public JsapiServiceExtension service;
|
|
|
+
|
|
|
+ public void initMerchant() {
|
|
|
+ Config config =
|
|
|
+ new RSAAutoCertificateConfig.Builder()
|
|
|
+ .merchantId(merchantId)
|
|
|
+ // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名
|
|
|
+ .privateKeyFromPath(privateKeyPath)
|
|
|
+ .merchantSerialNumber(merchantSerialNumber)
|
|
|
+ .apiV3Key(apiV3Key)
|
|
|
+ .build();
|
|
|
+ service = new JsapiServiceExtension.Builder()
|
|
|
+ .config(config)
|
|
|
+ .signType("RSA") // 不填默认为RSA
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+
|
|
|
+ public PrepayWithRequestPaymentResponse prepayWithRequestPayment() {
|
|
|
+ PrepayRequest request = new PrepayRequest();
|
|
|
+ // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
+ // 调用接口
|
|
|
+ return service.prepayWithRequestPayment(request);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|