|
@@ -1,5 +1,6 @@
|
|
|
package com.rongwei.zhsw.system.utils;
|
|
|
|
|
|
+import com.rongwe.zhsw.system.vo.WxPrepayOrderVo;
|
|
|
import com.wechat.pay.java.core.Config;
|
|
|
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
|
|
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
|
|
@@ -8,6 +9,9 @@ import com.wechat.pay.java.service.payments.jsapi.model.Payer;
|
|
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
|
|
|
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
+import com.wechat.pay.java.service.payments.model.Transaction;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.QueryOrderByIdRequest;
|
|
|
+import com.wechat.pay.java.service.payments.jsapi.model.QueryOrderByOutTradeNoRequest;
|
|
|
|
|
|
|
|
|
public class WxApi {
|
|
@@ -19,7 +23,7 @@ public class WxApi {
|
|
|
/**
|
|
|
* 商户API私钥路径
|
|
|
*/
|
|
|
- public String privateKeyPath = "D:\\PROJECT\\水务\\zhsw_service\\zhsw-server\\src\\main\\resources\\cert\\apiclient_key.pem";
|
|
|
+ public String privateKeyPath = "D:\\code\\project\\zhsw\\zhsw_service\\zhsw-server\\src\\main\\resources\\cert\\apiclient_key.pem";
|
|
|
|
|
|
/**
|
|
|
* 商户证书序列号
|
|
@@ -49,23 +53,41 @@ public class WxApi {
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
- public PrepayWithRequestPaymentResponse prepayWithRequestPayment() {
|
|
|
+ public PrepayWithRequestPaymentResponse prepayWithRequestPayment(WxPrepayOrderVo vo) {
|
|
|
PrepayRequest request = new PrepayRequest();
|
|
|
+ // 小程序appid
|
|
|
request.setAppid("wxaec1c618349b81a5");
|
|
|
+ // 商户id
|
|
|
request.setMchid(merchantId);
|
|
|
- request.setDescription("pei pei pei");
|
|
|
- request.setOutTradeNo("1217752501201407033233368018");
|
|
|
+ request.setDescription(vo.getDescription());
|
|
|
+ request.setOutTradeNo(vo.getOutTradeNo());
|
|
|
+ // 接收通知的url
|
|
|
request.setNotifyUrl("https://www.weixin.qq.com/wxpay/pay.php");
|
|
|
Amount amount = new Amount();
|
|
|
- amount.setTotal(100);
|
|
|
+ amount.setTotal(vo.getTotalAmount());
|
|
|
amount.setCurrency("CNY");
|
|
|
request.setAmount(amount);
|
|
|
Payer payer = new Payer();
|
|
|
- payer.setOpenid("orz5h7OO73yAkf9_WQ0KIYF1iZ5U");
|
|
|
+ payer.setOpenid(vo.getOpenId());
|
|
|
request.setPayer(payer);
|
|
|
- // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
|
|
|
- // 调用接口
|
|
|
return service.prepayWithRequestPayment(request);
|
|
|
}
|
|
|
|
|
|
+ public Transaction queryOrderById() {
|
|
|
+
|
|
|
+ QueryOrderByIdRequest request = new QueryOrderByIdRequest();
|
|
|
+ request.setMchid(merchantId);
|
|
|
+ // 微信支付订单号
|
|
|
+ request.setTransactionId("4200002623202503245798842166");
|
|
|
+ return service.queryOrderById(request);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Transaction queryOrderByOutTradeNo() {
|
|
|
+
|
|
|
+ QueryOrderByOutTradeNoRequest request = new QueryOrderByOutTradeNoRequest();
|
|
|
+ request.setMchid(merchantId);
|
|
|
+ request.setOutTradeNo("850eb61a906046dfb66801e0bb18206e");
|
|
|
+ return service.queryOrderByOutTradeNo(request);
|
|
|
+ }
|
|
|
+
|
|
|
}
|