Skip to content

Commit

Permalink
优化商户私钥配置方式 (#11)
Browse files Browse the repository at this point in the history
* 优化商户私钥配置方式

* 修复错误字

---------

Co-authored-by: jeanwu <[email protected]>
  • Loading branch information
wujunjiesd and jeanwu authored Feb 22, 2024
1 parent 8c53553 commit 2089fbe
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 19 deletions.
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
2 changes: 1 addition & 1 deletion src/main/java/transfer/dto/TransferDetailInput.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package transfer.dto;

// 创建批次单入餐
// 创建批次单入参
public class TransferDetailInput {

private String outDetailNo;
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}

0 comments on commit 2089fbe

Please sign in to comment.