Compare commits
7 Commits
07470c037d
...
bd00a6125e
Author | SHA1 | Date |
---|---|---|
|
bd00a6125e | |
|
c8672c15ea | |
|
ae3af80e9c | |
|
443cf0b890 | |
|
0273c01772 | |
|
3653366102 | |
|
5cf311efea |
|
@ -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
11
pom.xml
|
@ -20,6 +20,17 @@
|
|||
</properties>
|
||||
|
||||
<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>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
|
|
|
@ -9,6 +9,8 @@ import com.jwl.driver.server.vo.AppletPayVo;
|
|||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
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.model.*;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 微信支付小程序 接口
|
||||
*/
|
||||
@Api(tags = "小程序支付")
|
||||
@Controller
|
||||
@RestController
|
||||
@RequestMapping("/applet/pay")
|
||||
@Slf4j
|
||||
public class AppletPayController {
|
||||
|
@ -46,6 +52,7 @@ public class AppletPayController {
|
|||
@PostMapping("/prepay")
|
||||
public BaseResponse createPrepay(@RequestBody AppletPayVo payDto){
|
||||
// 构建service
|
||||
log.info("payDto===================>{}",payDto);
|
||||
JsapiServiceExtension service = createService();
|
||||
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);
|
||||
// 使用微信扫描 code_url 对应的二维码,即可体验Native支付
|
||||
// log.info(response);
|
||||
log.info("response=================>{}",response);
|
||||
// return BaseResponse.success();
|
||||
return BaseResponse.success(response);
|
||||
|
||||
}
|
||||
|
||||
/** 构建service */
|
||||
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 {
|
||||
privateKeyPath = keyClassPath.getURL().getPath();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
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 =
|
||||
new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(wechatPayConfig.getMchId())
|
||||
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
|
||||
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
|
||||
.apiV3Key(wechatPayConfig.getApiV3Key())
|
||||
.build();
|
||||
|
|
|
@ -8,6 +8,8 @@ import com.jwl.driver.server.vo.H5PayVo;
|
|||
import com.wechat.pay.java.core.Config;
|
||||
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
|
||||
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.model.*;
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Objects;
|
||||
|
||||
|
@ -30,7 +35,7 @@ import java.util.Objects;
|
|||
* 微信支付小程序 接口
|
||||
*/
|
||||
@Api(tags = "H5支付")
|
||||
@Controller
|
||||
@RestController
|
||||
@RequestMapping("/H5/pay")
|
||||
@Slf4j
|
||||
public class H5PayController {
|
||||
|
@ -73,18 +78,38 @@ public class H5PayController {
|
|||
}
|
||||
|
||||
private H5Service 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 {
|
||||
privateKeyPath = keyClassPath.getURL().getPath();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
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 =
|
||||
new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(wechatPayConfig.getMchId())
|
||||
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
|
||||
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
|
||||
.apiV3Key(wechatPayConfig.getApiV3Key())
|
||||
.build();
|
||||
|
|
|
@ -70,7 +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
|
||||
|
||||
|
|
|
@ -3,14 +3,20 @@ 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.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 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 org.springframework.data.repository.init.ResourceReader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
|
||||
/**
|
||||
* @author 曹林
|
||||
|
@ -26,17 +32,42 @@ public class WechatPayTest {
|
|||
|
||||
@Test
|
||||
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 =
|
||||
new RSAAutoCertificateConfig.Builder()
|
||||
.merchantId(wechatPayConfig.getMchId())
|
||||
.privateKeyFromPath(privateKeyPath)
|
||||
.privateKey(PemUtil.loadPrivateKeyFromString(keyString))
|
||||
// .privateKeyFromPath(wechatPayConfig.getPrivateKeyPath())
|
||||
.merchantSerialNumber(wechatPayConfig.getMchSerialNo())
|
||||
.apiV3Key(wechatPayConfig.getApiV3Key())
|
||||
.build();
|
||||
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
|
||||
|
||||
|
||||
H5Service service = new H5Service.Builder().config(config).build();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue