Compare commits

...

7 Commits

Author SHA1 Message Date
caolin bd00a6125e 微信支付bug调整 2023-08-24 12:52:19 +08:00
caolin c8672c15ea 微信支付bug调整 2023-08-24 12:51:27 +08:00
caolin ae3af80e9c 查询调整 2023-08-24 03:01:33 +08:00
caolin 443cf0b890 查询调整 2023-08-24 02:34:46 +08:00
caolin 0273c01772 查询调整 2023-08-24 02:28:30 +08:00
caolin 3653366102 查询调整 2023-08-24 01:31:16 +08:00
caolin 5cf311efea 查询调整 2023-08-24 01:20:02 +08:00
6 changed files with 145 additions and 22 deletions

28
apiclient_key.pem Normal file
View File

@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMBI4+DYjagdDr
HHIEBu2xyZQXhtKHvwwawu//wx/qm9WLS4U4hIgpIIAIhMlCna6w9RbFM4b09ycL
GHR+Iq5jaEbekSPH/98ssEN48CCuZoCrVoaArSpayDO2++4VGkZrWJAPXckTVV3c
NXQVQIPnvm9YY2FQjAKGvzQ3bNLF6xOBfN8kn9ZZEyXEYa/acaD5YzbUoB45P6Yp
Df4WtLDAVj8qW+yUFLsmKuuISBBBhZPMMaDCaVWXPevwCUEV8JE7GHzpoHlEq/Lh
khXU1yoTL0E8l6Dw+t6fXMAxRr/g7BzPrDwc3Csd/fePybgVDyIaJIkT75X37OSc
klhZlOuBAgMBAAECggEAOc1wn5QmGgJ9tp8wjoOIBL8f/ipsq5ktTMe+R7B48neE
YRrce87Q5RYYMFGu0/jo7aoC8YxPyEfd//7FwpcA4ZlBuv1ULe4IxRiLhVBDciYI
foLdSMfHIEFopYdrRP9UxEUrS68+sQOWvDVI1lyZAqep1FkT0UZZ0OOLX8itTvVx
6EN67EjpVfg60sQ3IxDc1qmhh/+qKC1XBmnCn73wB/OZ6EtVjmgQEVJFspK9bK7j
J9zHBPTaeyNwC9eKKUeoxiESd5r2sugu8yZ8kvqwhJECa4AgHOZfskxG4YhmhROk
l7aI0Vw/fXngj7hXyMXXHuk7FgkdMpNcVwz2RBR4AQKBgQDmaxiV52tjMp+vqNAi
XjsE/jLAQuOI1Sz9gUoHipT4qdHnPgvtygMjSrVBCb28CE/tyNp3t/DVDuRmg+HE
GGXhfJPA2L6uOelsH7QKyQlWSqcv8BykDPEumwhubjv/bjJw4/HkZOP3LiLSGuzu
K+1dlcww3Fa2bEL62pN6TltdsQKBgQDiqxvG3vVIQo4kckaGNyrPDi55oph8k4H1
s450YDfEXCy95PXpeltK9gJO/bUDmqcliLDY8PBK7aGcmEdkRcLo6KBpOS0KDRdu
ATadnGn1w+DCtHSmrecZ5J6If+F/9YIPCCQ4gYXsVIniX6xDxhcR/Y6VVP0WwO37
QwaDzmnO0QKBgAbl6eSC+xoLJ/CwUxrUS1wI6CgNWJZ+G0yzlC3JnlAbdWdA2kaS
J6nk0KxTyFRaw1nRC4lN/m3CdmADTrz6JgKsIhhB5ON+ZFiSUmeIQTlOHtc2jwTy
Rj4o8gWsUyuAdw4eJN27j3+U6AH2QGWY9xA4LdbAoe/wKcksxgGBWwbhAoGBAJSJ
susxAqX2z3U82dBsaIZFcdlN3wWMGJctsoW64/CuwrcySqBVCWxnKH4hLjUNbMlg
+RtBUQaZENYwyGACg0bj4vLxf/1dNORmsSa58IoYcbrGTMdJoO9L7UPgIaMb/L3j
BPFul5eWksEhFx9WuZmVgpGDn1MA3TNR6fwIEThxAoGBAIcHOfiJH3d3q33aODPA
cqZb5RVNc1ZpiXC5yBwsiuTw3TYXuJmcUrRKuStsXXkIr2vyc3x9Af5+vWy7eJw/
+N+p5zxW9F5QQdEZKt/ALjXEonxkRlebz+GvsWYEP9+Li8DwFM1wlc97kLLt4XJn
EK4LLlyBAz3ZBGm18p7RgnMP
-----END PRIVATE KEY-----

11
pom.xml
View File

@ -20,6 +20,17 @@
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- 使用谷歌的gson来实现json的传递-->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

View File

@ -9,6 +9,8 @@ import com.jwl.driver.server.vo.AppletPayVo;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.exception.ServiceException; import com.wechat.pay.java.core.exception.ServiceException;
import com.wechat.pay.java.core.util.IOUtil;
import com.wechat.pay.java.core.util.PemUtil;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.*; import com.wechat.pay.java.service.payments.jsapi.model.*;
import com.wechat.pay.java.service.payments.model.Transaction; import com.wechat.pay.java.service.payments.model.Transaction;
@ -21,16 +23,20 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.math.BigDecimal; import java.math.BigDecimal;
/** /**
* *
*/ */
@Api(tags = "小程序支付") @Api(tags = "小程序支付")
@Controller @RestController
@RequestMapping("/applet/pay") @RequestMapping("/applet/pay")
@Slf4j @Slf4j
public class AppletPayController { public class AppletPayController {
@ -46,6 +52,7 @@ public class AppletPayController {
@PostMapping("/prepay") @PostMapping("/prepay")
public BaseResponse createPrepay(@RequestBody AppletPayVo payDto){ public BaseResponse createPrepay(@RequestBody AppletPayVo payDto){
// 构建service // 构建service
log.info("payDto===================>{}",payDto);
JsapiServiceExtension service = createService(); JsapiServiceExtension service = createService();
OrderPayInfo orderPayInfo = orderPayInfoService.createOrderPayInfo(payDto.getMoney(),payDto.getUserId(), payDto.getDescription(), payDto.getOutTradeNo(), "applet"); OrderPayInfo orderPayInfo = orderPayInfoService.createOrderPayInfo(payDto.getMoney(),payDto.getUserId(), payDto.getDescription(), payDto.getOutTradeNo(), "applet");
@ -66,25 +73,46 @@ public class AppletPayController {
// 调用下单方法,得到应答 // 调用下单方法,得到应答
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request); PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
// 使用微信扫描 code_url 对应的二维码即可体验Native支付 // 使用微信扫描 code_url 对应的二维码即可体验Native支付
// log.info(response); log.info("response=================>{}",response);
// return BaseResponse.success();
return BaseResponse.success(response); return BaseResponse.success(response);
} }
/** 构建service */ /** 构建service */
private JsapiServiceExtension createService() { private JsapiServiceExtension createService() {
ClassPathResource keyClassPath = new ClassPathResource("/wechatpay/apiclient_key.pem");
String privateKeyPath = null; InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wechatPay/apiclient_key.pem");
String keyString;
try { try {
privateKeyPath = keyClassPath.getURL().getPath(); Throwable var2 = null;
} catch (IOException e) { try {
throw new RuntimeException(e); keyString = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
} }
Config config = Config config =
new RSAAutoCertificateConfig.Builder() new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId()) .merchantId(wechatPayConfig.getMchId())
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath()) // .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(wechatPayConfig.getMchSerialNo()) .merchantSerialNumber(wechatPayConfig.getMchSerialNo())
.apiV3Key(wechatPayConfig.getApiV3Key()) .apiV3Key(wechatPayConfig.getApiV3Key())
.build(); .build();

View File

@ -8,6 +8,8 @@ import com.jwl.driver.server.vo.H5PayVo;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.exception.ServiceException; import com.wechat.pay.java.core.exception.ServiceException;
import com.wechat.pay.java.core.util.IOUtil;
import com.wechat.pay.java.core.util.PemUtil;
import com.wechat.pay.java.service.payments.h5.H5Service; import com.wechat.pay.java.service.payments.h5.H5Service;
import com.wechat.pay.java.service.payments.h5.model.*; import com.wechat.pay.java.service.payments.h5.model.*;
import com.wechat.pay.java.service.payments.model.Transaction; import com.wechat.pay.java.service.payments.model.Transaction;
@ -20,9 +22,12 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Objects; import java.util.Objects;
@ -30,7 +35,7 @@ import java.util.Objects;
* *
*/ */
@Api(tags = "H5支付") @Api(tags = "H5支付")
@Controller @RestController
@RequestMapping("/H5/pay") @RequestMapping("/H5/pay")
@Slf4j @Slf4j
public class H5PayController { public class H5PayController {
@ -73,18 +78,38 @@ public class H5PayController {
} }
private H5Service createService() { private H5Service createService() {
ClassPathResource keyClassPath = new ClassPathResource("/wechatpay/apiclient_key.pem"); InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wechatPay/apiclient_key.pem");
String privateKeyPath = null; String keyString;
try { try {
privateKeyPath = keyClassPath.getURL().getPath(); Throwable var2 = null;
} catch (IOException e) { try {
throw new RuntimeException(e); keyString = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
} }
Config config = Config config =
new RSAAutoCertificateConfig.Builder() new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId()) .merchantId(wechatPayConfig.getMchId())
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath()) // .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(wechatPayConfig.getMchSerialNo()) .merchantSerialNumber(wechatPayConfig.getMchSerialNo())
.apiV3Key(wechatPayConfig.getApiV3Key()) .apiV3Key(wechatPayConfig.getApiV3Key())
.build(); .build();

View File

@ -70,7 +70,7 @@ wechatpay:
mchId: 1650477646 mchId: 1650477646
apiV3Key: JingWuLianJiaKao20120813ZhouHong apiV3Key: JingWuLianJiaKao20120813ZhouHong
mchSerialNo: 52974C99DFCC518EA2E5AD20C3753E38B924868D mchSerialNo: 52974C99DFCC518EA2E5AD20C3753E38B924868D
# privateKeyPath: classpath*:/wechatPay/apiclient_key.pem # 路径设置没生效 不知道原因
privateKeyPath: classpath*:/wechatPay/apiclient_key.pem privateKeyPath: classpath*:/wechatPay/apiclient_key.pem
payNoticeUrl: https://jwl.ahduima.com/driver-api/payNoticeLog payNoticeUrl: https://jwl.ahduima.com/driver-api/payNoticeLog

View File

@ -3,14 +3,20 @@ package com.jwl.driver.server;
import com.jwl.driver.server.config.WechatPayConfig; import com.jwl.driver.server.config.WechatPayConfig;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.util.IOUtil;
import com.wechat.pay.java.core.util.PemUtil;
import com.wechat.pay.java.service.payments.h5.H5Service;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.data.repository.init.ResourceReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
/** /**
* @author * @author
@ -26,17 +32,42 @@ public class WechatPayTest {
@Test @Test
void createService() throws IOException { void createService() throws IOException {
ClassPathResource keyClassPath = new ClassPathResource("/wechatpay/apiclient_key.pem");
String privateKeyPath = keyClassPath.getURL().getPath(); InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("wechatPay/apiclient_key.pem");
String keyString;
try {
Throwable var2 = null;
try {
keyString = IOUtil.toString(inputStream);
} catch (Throwable var13) {
var2 = var13;
throw var13;
} finally {
if (inputStream != null) {
if (var2 != null) {
try {
inputStream.close();
} catch (Throwable var12) {
var2.addSuppressed(var12);
}
} else {
inputStream.close();
}
}
}
} catch (IOException var15) {
throw new UncheckedIOException(var15);
}
Config config = Config config =
new RSAAutoCertificateConfig.Builder() new RSAAutoCertificateConfig.Builder()
.merchantId(wechatPayConfig.getMchId()) .merchantId(wechatPayConfig.getMchId())
.privateKeyFromPath(privateKeyPath) .privateKey(PemUtil.loadPrivateKeyFromString(keyString))
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
.merchantSerialNumber(wechatPayConfig.getMchSerialNo()) .merchantSerialNumber(wechatPayConfig.getMchSerialNo())
.apiV3Key(wechatPayConfig.getApiV3Key()) .apiV3Key(wechatPayConfig.getApiV3Key())
.build(); .build();
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build(); H5Service service = new H5Service.Builder().config(config).build();
} }
} }