Skip to content

Commit

Permalink
fix: 修复AbstractSigner并发错误 (#115)
Browse files Browse the repository at this point in the history
* fix: 修复AbstractSigner并发错误

resolve #114

* bump version v0.2.5
  • Loading branch information
xy-peng authored Jan 6, 2023
1 parent cb0d870 commit 25d0be6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![JavaDoc](http://img.shields.io/badge/javadoc-reference-blue.svg)](https://www.javadoc.io/doc/com.github.wechatpay-apiv3/wechatpay-java/latest/index.html)
![Maven Central](https://img.shields.io/maven-central/v/com.github.wechatpay-apiv3/wechatpay-java?versionPrefix=0.2.4)
![Maven Central](https://img.shields.io/maven-central/v/com.github.wechatpay-apiv3/wechatpay-java?versionPrefix=0.2.5)
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=wechatpay-apiv3_wechatpay-java&metric=security_rating)](https://sonarcloud.io/summary/overall?id=wechatpay-apiv3_wechatpay-java)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=wechatpay-apiv3_wechatpay-java&metric=sqale_rating)](https://sonarcloud.io/summary/overall?id=wechatpay-apiv3_wechatpay-java)
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=wechatpay-apiv3_wechatpay-java&metric=coverage)](https://sonarcloud.io/summary/overall?id=wechatpay-apiv3_wechatpay-java)
Expand Down Expand Up @@ -30,7 +30,7 @@
#### Gradle
在你的 build.gradle 文件中加入如下的依赖
```groovy
implementation 'com.github.wechatpay-apiv3:wechatpay-java:0.2.4'
implementation 'com.github.wechatpay-apiv3:wechatpay-java:0.2.5'
```

#### Maven
Expand All @@ -39,7 +39,7 @@ implementation 'com.github.wechatpay-apiv3:wechatpay-java:0.2.4'
<dependency>
<groupId>com.github.wechatpay-apiv3</groupId>
<artifactId>wechatpay-java</artifactId>
<version>0.2.4</version>
<version>0.2.5</version>
</dependency>
```

Expand Down Expand Up @@ -174,9 +174,9 @@ Config config =
同时,`RSAAutoCertificateProvider` 会启动一个后台线程,定时更新证书(目前设计为60分钟),以实现证书过期时的新老证书平滑切换。

> **Note**
>
>
> 每个商户号只能创建一个 `RSAAutoCertificateConfig`。同一个商户号构造多个实例,会抛出 `IllegalStateException` 异常。
>
>
> 我们建议你将配置类作为全局变量。如果你的程序是多线程,建议使用**多线程安全**的单例模式。

Expand Down Expand Up @@ -268,7 +268,7 @@ inputStream.close();
```

> **Warning**
>
>
> 开发者在下载文件之后,应使用第一步获取的账单摘要校验文件的完整性。
## 敏感信息加解密
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/groovy/common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
id "jacoco"
}

version "0.2.4"
version "0.2.5"
group "com.github.wechatpay-apiv3"
compileJava.options.encoding = "UTF-8"
compileTestJava.options.encoding = "UTF-8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public abstract class AbstractSigner implements Signer {

private final String certificateSerialNumber;
private final String algorithm;
private final Signature signature;
private final String algorithmName;
private final PrivateKey privateKey;

/**
* AbstractSigner 构造函数
Expand All @@ -30,25 +31,26 @@ protected AbstractSigner(
String certificateSerialNumber,
PrivateKey privateKey) {
this.algorithm = requireNonNull(algorithm);
this.algorithmName = requireNonNull(algorithmName);
this.certificateSerialNumber = requireNonNull(certificateSerialNumber);
try {
this.signature = Signature.getInstance(algorithmName);
this.signature.initSign(privateKey);
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedOperationException(
"The current Java environment does not support " + algorithmName, e);
} catch (InvalidKeyException e) {
throw new IllegalArgumentException(algorithm + " signature uses an illegal privateKey.", e);
}
this.privateKey = requireNonNull(privateKey);
}

@Override
public SignatureResult sign(String message) {
requireNonNull(message);

byte[] sign;
try {
Signature signature = Signature.getInstance(algorithmName);
signature.initSign(privateKey);
signature.update(message.getBytes(StandardCharsets.UTF_8));
sign = signature.sign();
} catch (NoSuchAlgorithmException e) {
throw new UnsupportedOperationException(
"The current Java environment does not support " + algorithmName, e);
} catch (InvalidKeyException e) {
throw new IllegalArgumentException(algorithm + " signature uses an illegal privateKey.", e);
} catch (SignatureException e) {
throw new RuntimeException("An error occurred during the sign process.", e);
}
Expand Down

0 comments on commit 25d0be6

Please sign in to comment.