sola преди 4 месеца
родител
ревизия
24302ebe95

+ 30 - 8
zhsw-common/src/main/java/com/rongwei/zhsw/system/utils/WxApi.java

@@ -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);
+    }
+
 }

+ 18 - 0
zhsw-entity/src/main/java/com/rongwe/zhsw/system/vo/WxPrepayOrderVo.java

@@ -0,0 +1,18 @@
+package com.rongwe.zhsw.system.vo;
+
+import lombok.Data;
+
+@Data
+public class WxPrepayOrderVo {
+    // 小程序用户的opendi
+   private String openId;
+
+   // 下单的金额 单位:分
+    private Integer totalAmount;
+
+    // 商品描述
+    private String description;
+
+    // 订单号
+    private String outTradeNo;
+}

+ 12 - 3
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/weChat/PayMentController.java

@@ -1,6 +1,7 @@
 package com.rongwei.zhsw.system.controller.weChat;
 
 import com.rongwe.zhsw.system.vo.PaymentRocordVo;
+import com.rongwe.zhsw.system.vo.WxPrepayOrderVo;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.zhsw.system.utils.WxApi;
 import com.rongwei.zhsw.system.wechat.PaymentRecordService;
@@ -28,10 +29,18 @@ public class PayMentController {
         return paymentRecordService.getPaymentRecordList(payMentRocordVo);
     }
 
-    @PostMapping("/getSign")
-    public R getSign(@RequestBody Map<String, String> map) {
+    /**
+     * 预下单
+     * @param vo
+     * @return
+     */
+    @PostMapping("/prepayOrder")
+    public R prepayOrder(@RequestBody WxPrepayOrderVo vo) {
         WxApi wxApi = new WxApi();
         wxApi.initMerchant();
-        return R.ok(wxApi.prepayWithRequestPayment());
+        // 生成订单号
+        String nonceStr = UUID.randomUUID().toString().replaceAll("-", "");
+        vo.setOutTradeNo(nonceStr);
+        return R.ok(wxApi.prepayWithRequestPayment(vo));
     }
 }