Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(): migrate springboot3 #130

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions payment-spring-boot-autoconfigure/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@
<parent>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.20.RELEASE</version>
<version>${revision}</version>
</parent>

<artifactId>payment-spring-boot-autoconfigure</artifactId>
<version>1.0.20.RELEASE</version>
<version>${revision}</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -74,9 +74,10 @@
<artifactId>alipay-sdk-java</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<scope>provided</scope>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.3</version>
<!-- <scope>provided</scope>-->
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,20 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import lombok.Getter;
import lombok.SneakyThrows;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.hc.client5.http.config.ConnectionConfig;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactoryBuilder;
import org.apache.hc.core5.http.io.SocketConfig;
import org.apache.hc.core5.http.ssl.TLS;
import org.apache.hc.core5.pool.PoolConcurrencyPolicy;
import org.apache.hc.core5.pool.PoolReusePolicy;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.core5.ssl.SSLContexts;
import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
import org.bouncycastle.crypto.Digest;
import org.bouncycastle.crypto.digests.MD5Digest;
import org.bouncycastle.util.encoders.Hex;
Expand Down Expand Up @@ -65,6 +74,7 @@
import java.util.TreeMap;
import java.util.stream.Collectors;


/**
* The type Base model.
*
Expand Down Expand Up @@ -231,13 +241,26 @@ private RestTemplate getRestTemplateClientAuthentication(String mchId)
SSLContext sslcontext = SSLContextBuilder.create()
.loadKeyMaterial(store, pem)
.build();
// Allow TLSv1 protocol only
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1"},
null, hostnameVerifier);

PoolingHttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(SSLConnectionSocketFactoryBuilder.create()
.setSslContext(SSLContexts.createSystemDefault())
.setTlsVersions(TLS.V_1_3)
.build())
.setDefaultSocketConfig(SocketConfig.custom()
.setSoTimeout(Timeout.ofMinutes(1))
.build())
.setPoolConcurrencyPolicy(PoolConcurrencyPolicy.STRICT)
.setConnPoolPolicy(PoolReusePolicy.LIFO)
.setDefaultConnectionConfig(ConnectionConfig.custom()
.setSocketTimeout(Timeout.ofMinutes(1))
.setConnectTimeout(Timeout.ofMinutes(1))
.setTimeToLive(TimeValue.ofMinutes(10))
.build())
.build();

CloseableHttpClient httpclient = HttpClients.custom()
.setSSLSocketFactory(sslsf)
.setConnectionManager(connectionManager)
.build();
HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory(httpclient);
return new RestTemplate(clientHttpRequestFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.util.AlternativeJdkIdGenerator;
import org.springframework.util.Assert;
import org.springframework.util.Base64Utils;
import org.springframework.util.IdGenerator;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
Expand Down Expand Up @@ -161,7 +160,7 @@ public String doRequestSign(PrivateKey privateKey, String... orderedComponents)
signer.initSign(privateKey);
final String signatureStr = createSign(orderedComponents);
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
return Base64Utils.encodeToString(signer.sign());
return Base64.getEncoder().encodeToString(signer.sign());
}

/**
Expand Down Expand Up @@ -189,7 +188,7 @@ public boolean responseSignVerify(ResponseSignVerifyParams params) {
Signature signer = Signature.getInstance("SHA256withRSA", BC_PROVIDER);
signer.initVerify(certificate.getX509Certificate());
signer.update(signatureStr.getBytes(StandardCharsets.UTF_8));
return signer.verify(Base64Utils.decodeFromString(params.getWechatpaySignature()));
return signer.verify(Base64.getDecoder().decode((params.getWechatpaySignature())));
} catch (Exception e) {
throw new PayException("An exception occurred during the response verification, the cause: " + e.getMessage());
}
Expand Down Expand Up @@ -288,7 +287,7 @@ public String decryptResponseBody(String tenantId, String associatedData, String

byte[] bytes;
try {
bytes = cipher.doFinal(Base64Utils.decodeFromString(ciphertext));
bytes = cipher.doFinal(Base64.getDecoder().decode((ciphertext)));
} catch (GeneralSecurityException e) {
throw new PayException(e);
}
Expand All @@ -314,7 +313,7 @@ public String encryptRequestMessage(String message, Certificate certificate) {

byte[] data = message.getBytes(StandardCharsets.UTF_8);
byte[] cipherData = cipher.doFinal(data);
return Base64Utils.encodeToString(cipherData);
return Base64.getEncoder().encodeToString(cipherData);

} catch (Exception e) {
throw new PayException(e);
Expand All @@ -335,7 +334,7 @@ public String decryptResponseMessage(String message, String tenantId) {
PrivateKey privateKey = wechatMetaBean.getKeyPair().getPrivate();
Cipher cipher = Cipher.getInstance("RSA/ECB/OAEPWithSHA-1AndMGF1Padding", BC_PROVIDER);
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] data = Base64Utils.decodeFromString(message);
byte[] data = Base64.getDecoder().decode((message));
byte[] cipherData = cipher.doFinal(data);
return new String(cipherData, StandardCharsets.UTF_8);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ private <T> void doExecute(WechatRequestEntity<T> requestEntity) {
ResponseEntity<ObjectNode> responseEntity = restOperations.exchange(requestEntity, ObjectNode.class);
HttpHeaders headers = responseEntity.getHeaders();
ObjectNode body = responseEntity.getBody();
HttpStatus statusCode = responseEntity.getStatusCode();
HttpStatusCode statusCode = responseEntity.getStatusCode();

// 微信请求id
String requestId = headers.getFirst("Request-ID");
if (!statusCode.is2xxSuccessful()) {
Expand Down Expand Up @@ -298,7 +299,7 @@ private <T> String doDownload(WechatRequestEntity<T> requestEntity) {

ResponseEntity<String> responseEntity = restOperations.exchange(requestEntity, String.class);

HttpStatus statusCode = responseEntity.getStatusCode();
HttpStatusCode statusCode = responseEntity.getStatusCode();
// 微信请求id
String requestId = requestEntity.getHeaders().getFirst("Request-ID");
if (!statusCode.is2xxSuccessful()) {
Expand All @@ -322,7 +323,7 @@ private <T> ResponseEntity<Resource> doResource(WechatRequestEntity<T> requestEn

ResponseEntity<Resource> responseEntity = restOperations.exchange(requestEntity, Resource.class);

HttpStatus statusCode = responseEntity.getStatusCode();
HttpStatusCode statusCode = responseEntity.getStatusCode();
// 微信请求id
String requestId = requestEntity.getHeaders().getFirst("Request-ID");
if (!statusCode.is2xxSuccessful()) {
Expand Down
15 changes: 8 additions & 7 deletions payment-spring-boot-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,21 @@
<parent>
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.20.RELEASE</version>
<version>${revision}</version>
</parent>

<artifactId>payment-spring-boot-starter</artifactId>
<version>1.0.20.RELEASE</version>
<version>${revision}</version>
<packaging>jar</packaging>
<modelVersion>4.0.0</modelVersion>


<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>17</java.version>
</properties>

<dependencies>
Expand All @@ -53,8 +53,9 @@
<artifactId>bcprov-jdk15to18</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
Expand Down
13 changes: 7 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<groupId>cn.felord</groupId>
<artifactId>payment-spring-boot</artifactId>
<version>1.0.20.RELEASE</version>
<version>${revision}</version>
<packaging>pom</packaging>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -47,7 +47,7 @@
</developers>

<scm>
<tag>payment-spring-boot-1.0.18.RELEASE</tag>
<tag>payment-spring-boot-${project.version}</tag>
<url>https://github.com/NotFound403/payment-spring-boot</url>
<connection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</connection>
<developerConnection>scm:git:https://github.com/NotFound403/payment-spring-boot.git</developerConnection>
Expand Down Expand Up @@ -83,14 +83,15 @@
</modules>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-boot.version>2.7.7</spring-boot.version>
<java.version>17</java.version>
<spring-boot.version>3.2.5</spring-boot.version>
<alipay-sdk.version>4.31.7.ALL</alipay-sdk.version>
<bcprov.version>1.78</bcprov.version>
<revision>2.0.1.RELEASE</revision>
</properties>

<distributionManagement>
Expand Down