From 07470c037d45ec9cfb058ac7ced7dbaf0602f3cc Mon Sep 17 00:00:00 2001 From: caolin <1149034574@qq.com> Date: Thu, 24 Aug 2023 01:06:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AppletPayController.java | 12 ++++++- .../server/controller/H5PayController.java | 12 ++++++- src/main/resources/application.yml | 1 + .../com/jwl/driver/server/WechatPayTest.java | 33 +++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/jwl/driver/server/controller/AppletPayController.java b/src/main/java/com/jwl/driver/server/controller/AppletPayController.java index 36ee5f1..d32b005 100644 --- a/src/main/java/com/jwl/driver/server/controller/AppletPayController.java +++ b/src/main/java/com/jwl/driver/server/controller/AppletPayController.java @@ -16,12 +16,14 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; +import java.io.IOException; import java.math.BigDecimal; /** @@ -71,10 +73,18 @@ public class AppletPayController { /** 构建service */ private JsapiServiceExtension createService() { + ClassPathResource keyClassPath = new ClassPathResource("/wechatpay/apiclient_key.pem"); + String privateKeyPath = null; + try { + privateKeyPath = keyClassPath.getURL().getPath(); + } catch (IOException e) { + throw new RuntimeException(e); + } Config config = new RSAAutoCertificateConfig.Builder() .merchantId(wechatPayConfig.getMchId()) - .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath()) +// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath()) + .privateKeyFromPath(privateKeyPath) .merchantSerialNumber(wechatPayConfig.getMchSerialNo()) .apiV3Key(wechatPayConfig.getApiV3Key()) .build(); diff --git a/src/main/java/com/jwl/driver/server/controller/H5PayController.java b/src/main/java/com/jwl/driver/server/controller/H5PayController.java index 793e6a8..b1b0508 100644 --- a/src/main/java/com/jwl/driver/server/controller/H5PayController.java +++ b/src/main/java/com/jwl/driver/server/controller/H5PayController.java @@ -15,12 +15,14 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import javax.annotation.Resource; +import java.io.IOException; import java.math.BigDecimal; import java.util.Objects; @@ -71,10 +73,18 @@ public class H5PayController { } private H5Service createService() { + ClassPathResource keyClassPath = new ClassPathResource("/wechatpay/apiclient_key.pem"); + String privateKeyPath = null; + try { + privateKeyPath = keyClassPath.getURL().getPath(); + } catch (IOException e) { + throw new RuntimeException(e); + } Config config = new RSAAutoCertificateConfig.Builder() .merchantId(wechatPayConfig.getMchId()) - .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath()) +// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath()) + .privateKeyFromPath(privateKeyPath) .merchantSerialNumber(wechatPayConfig.getMchSerialNo()) .apiV3Key(wechatPayConfig.getApiV3Key()) .build(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 3455790..ec2f7cb 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -70,6 +70,7 @@ wechatpay: mchId: 1650477646 apiV3Key: JingWuLianJiaKao20120813ZhouHong mchSerialNo: 52974C99DFCC518EA2E5AD20C3753E38B924868D +# privateKeyPath: classpath*:/wechatPay/apiclient_key.pem privateKeyPath: classpath*:/wechatPay/apiclient_key.pem payNoticeUrl: https://jwl.ahduima.com/driver-api/payNoticeLog diff --git a/src/test/java/com/jwl/driver/server/WechatPayTest.java b/src/test/java/com/jwl/driver/server/WechatPayTest.java index 9094eea..067223a 100644 --- a/src/test/java/com/jwl/driver/server/WechatPayTest.java +++ b/src/test/java/com/jwl/driver/server/WechatPayTest.java @@ -1,9 +1,42 @@ package com.jwl.driver.server; +import com.jwl.driver.server.config.WechatPayConfig; +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Profile; +import org.springframework.core.io.ClassPathResource; + +import java.io.IOException; + /** * @author 曹林 * @description 微信支付 * @create 2023/8/21 10:36 */ +@SpringBootTest +@Profile("dev") public class WechatPayTest { + + @Autowired + private WechatPayConfig wechatPayConfig; + + @Test + void createService() throws IOException { + ClassPathResource keyClassPath = new ClassPathResource("/wechatpay/apiclient_key.pem"); + String privateKeyPath = keyClassPath.getURL().getPath(); + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(wechatPayConfig.getMchId()) + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(wechatPayConfig.getMchSerialNo()) + .apiV3Key(wechatPayConfig.getApiV3Key()) + .build(); + JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build(); + + + } }