2
0

2 Commits bd5a0aa1d1 ... 7a197aba88

Autor SHA1 Nachricht Datum
  sola 7a197aba88 Merge remote-tracking branch 'origin/master' vor 4 Monaten
  sola efe0836f5d 集成微信支付包 vor 4 Monaten

+ 31 - 0
zhsw-common/pom.xml

@@ -28,6 +28,37 @@
             <version>1.0-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib</artifactId>
+            <version>2.1.20</version>
+        </dependency>
+        <dependency>
+            <groupId>org.jetbrains.kotlin</groupId>
+            <artifactId>kotlin-stdlib-jdk8</artifactId>
+            <version>1.8.21</version>
+        </dependency>
+        <dependency>
+            <groupId>com.squareup.okio</groupId>
+            <artifactId>okio-jvm</artifactId>
+            <version>3.10.2</version>
+            <scope>runtime</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>4.12.0</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.wechatpay-apiv3</groupId>
+            <artifactId>wechatpay-java</artifactId>
+            <version>0.2.16</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.wechatpay-apiv3</groupId>
+            <artifactId>wechatpay-java-core</artifactId>
+            <version>0.2.16</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 54 - 0
zhsw-common/src/main/java/com/rongwei/zhsw/system/utils/WxApi.java

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

+ 11 - 0
zhsw-server/src/main/java/com/rongwei/zhsw/system/controller/weChat/PayMentController.java

@@ -2,6 +2,7 @@ package com.rongwei.zhsw.system.controller.weChat;
 
 import com.rongwe.zhsw.system.vo.PaymentRocordVo;
 import com.rongwei.rwcommon.base.R;
+import com.rongwei.zhsw.system.utils.WxApi;
 import com.rongwei.zhsw.system.wechat.PaymentRecordService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -10,6 +11,9 @@ import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
+import java.util.UUID;
+import java.util.HashMap;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/wechat/payment")
@@ -23,4 +27,11 @@ public class PayMentController {
     private R info(@RequestBody PaymentRocordVo payMentRocordVo) {
         return paymentRecordService.getPaymentRecordList(payMentRocordVo);
     }
+
+    @PostMapping("/getSign")
+    public R getSign(@RequestBody Map<String, String> map) {
+        WxApi wxApi = new WxApi();
+        wxApi.initMerchant();
+        return R.ok(wxApi.prepayWithRequestPayment());
+    }
 }