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

优化商户私钥配置方式 #11

Merged
merged 2 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ MCHID=1800000001
# 商户号绑定的AppID
APPID=wxaaaaaaaaaaaaa1

# 商户号私钥
PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\n……\n-----END PRIVATE KEY-----\n
# 商户号私钥文件的本地路径
PRIVATE_KEY_PATH=/date/XXX.pem

# 商户号公钥序列号
SERIAL_NUMBER=72AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ hs_err_pid*
replay_pid*

# config
.pem
.env
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@
- gradle-8.0
## 使用入门
### 1、下载代码
`git clone https://github.com/wechatpay-apiv3/transferbatch-demo-java.git`
### 2、补充信息
复制.env.example文件为[.env](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config),按照注释说明补充信息。
### 3、运行项目
`git clone https://github.com/wujunjiesd/transferbatch-demo-java.git`
### 2、创建.env文件
`cd transferbatch-demo-java`<br>
`cp .env.example .env`
### 3、完善.env内容
打开[.env](https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#features.external-config)文件,按照注释说明填写配置信息。
### 4、运行项目
`gradle bootRun`
### 4、体验Demo
### 5、体验Demo
在浏览器输入:http://localhost:8080/create.html

## 常见问题
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/transfer/dto/MerchantConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public void setAppid(String appid) {
this.appid = appid;
}

public String getPrivateKey() {
return privateKey;
public String getPrivateKeyPath() {
return privateKeyPath;
}

public void setPrivateKey(String privateKey) {
this.privateKey = privateKey;
public void setPrivateKeyPath(String privateKeyPath) {
this.privateKeyPath = privateKeyPath;
}

public String getSerialNumber() {
Expand All @@ -54,8 +54,8 @@ public void setApiV3Key(String apiV3Key) {
@Value("${appid}")
private String appid;

@Value("${private-key}")
private String privateKey;
@Value("${private-key-path}")
private String privateKeyPath;

@Value("${serial-number}")
private String serialNumber;
Expand All @@ -73,7 +73,7 @@ public RSAAutoCertificateConfig getRSAConfig() {
config =
new RSAAutoCertificateConfig.Builder()
.merchantId(mchid)
.privateKey(privateKey)
.privateKeyFromPath(privateKeyPath)
.merchantSerialNumber(serialNumber)
.apiV3Key(apiV3Key)
.build();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/transfer/mapper/BatchTransferOrderMapper.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package transfer.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import transfer.dto.BatchTransferOrderEntity;

Expand All @@ -9,7 +10,8 @@
@Repository
public interface BatchTransferOrderMapper {

BatchTransferOrderEntity query(String mchid, String outBatchNo);
BatchTransferOrderEntity query(
@Param("mchid") String mchid, @Param("outBatchNo") String outBatchNo);

void create(BatchTransferOrderEntity entity);

Expand Down
9 changes: 7 additions & 2 deletions src/main/java/transfer/mapper/TransferDetailOrderMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import transfer.dto.TransferDetailOrderEntity;

Expand All @@ -10,9 +11,13 @@
@Repository
public interface TransferDetailOrderMapper {

TransferDetailOrderEntity query(String mchid, String outBatchNo, String outDetailNo);
TransferDetailOrderEntity query(
@Param("mchid") String mchid,
@Param("outBatchNo") String outBatchNo,
@Param("outDetailNo") String outDetailNo);

ArrayList<TransferDetailOrderEntity> find(String mchid, String outBatchNo);
ArrayList<TransferDetailOrderEntity> find(
@Param("mchid") String mchid, @Param("outBatchNo") String outBatchNo);

void create(TransferDetailOrderEntity entity);

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ mybatis:
envconfig:
mchid: ${MCHID}
appid: ${APPID}
private-key: ${PRIVATE_KEY}
private-key-path: ${PRIVATE_KEY_PATH}
serial-number: ${SERIAL_NUMBER}
apiv3-key: ${APIV3_KEY}