微信支付修改为配置文件

This commit is contained in:
zk
2026-05-15 12:01:31 +08:00
parent 221456681b
commit 6abee6910a
2 changed files with 26 additions and 27 deletions
@@ -24,13 +24,12 @@ email:
wx_pay: wx_pay:
# status close:关闭 open:打开 # status close:关闭 open:打开
status: close status: close
merchant_id: ${MERCHANT_ID:1705334978} merchant_id: ${MERCHANT_ID:your_merchant_id}
privateKey_path: ${PRIVATEKEY_PATH:E:\wxPayCertify\1705334978_20250131_cert\apiclient_key.pem} private_key: ${WX_PRIVATE_KEY:your_private_key}
merchant_serial_number: ${MERCHANT_SERIAL_NUMBER:354F4A0BD7A11CB756ED3BC380A0E41442DE68F7} merchant_serial_number: ${MERCHANT_SERIAL_NUMBER:your_merchant_serial_number}
api_v3_key: ${API_V3_KEY:zhyahjkiysetindhGseuHadjKITshons} api_v3_key: ${API_V3_KEY:your_api_v3_key}
public_key_path: ${PUBLIC_KEY_PATH:E:\wxPayCertify\pub_key.pem} public_key: ${WX_PUBLIC_KEY:your_public_key}
public_key_id: ${PUBLIC_KEY_ID:PUB_KEY_ID_0117053349782025013000337100001480} public_key_id: ${PUBLIC_KEY_ID:your_public_key_id}
#回调域名地址
notify_domain: ${API_NOTIFY_DOMAIN:http://127.0.0.1:8080/api/} notify_domain: ${API_NOTIFY_DOMAIN:http://127.0.0.1:8080/api/}
# 支付宝支付 # 支付宝支付
@@ -24,33 +24,33 @@ public class WxPayConfig {
/** /**
* 商户号 * 商户号
*/ */
@Value("${wx_pay.merchant_id}") @Value("${wx_pay.merchant_id:}")
private String merchantId = ""; private String merchantId;
/** /**
* 商户API私钥路径 * 商户API私钥内容
*/ */
@Value("${wx_pay.privateKey_path}") @Value("${wx_pay.private_key:}")
private String privateKeyPath = ""; private String privateKeyContent;
/** /**
* 商户证书序列号 * 商户证书序列号
*/ */
@Value("${wx_pay.merchant_serial_number}") @Value("${wx_pay.merchant_serial_number:}")
private String merchantSerialNumber = ""; private String merchantSerialNumber;
/** /**
* 商户APIV3密钥 * 商户APIV3密钥
*/ */
@Value("${wx_pay.api_v3_key}") @Value("${wx_pay.api_v3_key:}")
private String apiV3Key = ""; private String apiV3Key;
/** /**
* 平台公钥地址 * 平台公钥内容
*/ */
@Value("${wx_pay.public_key_path}") @Value("${wx_pay.public_key:}")
private String publicKeyPath = ""; private String publicKeyContent;
/** /**
* 平台公钥地址ID * 平台公钥ID
*/ */
@Value("${wx_pay.public_key_id}") @Value("${wx_pay.public_key_id:}")
private String publicKeyId = ""; private String publicKeyId;
/** /**
@@ -60,18 +60,18 @@ public class WxPayConfig {
@ConditionalOnProperty(name = "wx_pay.status", havingValue = "open") @ConditionalOnProperty(name = "wx_pay.status", havingValue = "open")
public RSAPublicKeyConfig rSAAutoCertificateConfig() { public RSAPublicKeyConfig rSAAutoCertificateConfig() {
Assert.hasText(merchantId, "微信支付的商户号不能为空"); Assert.hasText(merchantId, "微信支付的商户号不能为空");
Assert.hasText(privateKeyPath, "商户API私钥路径不能为空"); Assert.hasText(privateKeyContent, "商户API私钥不能为空");
Assert.hasText(merchantSerialNumber, "商户证书序列号不能为空"); Assert.hasText(merchantSerialNumber, "商户证书序列号不能为空");
Assert.hasText(apiV3Key, "商户APIV3密钥不能为空"); Assert.hasText(apiV3Key, "商户APIV3密钥不能为空");
Assert.hasText(publicKeyPath, "微信支付平台公钥地址不能为空"); Assert.hasText(publicKeyContent, "微信支付平台公钥不能为空");
Assert.hasText(publicKeyId, "微信支付平台公钥Id不能为空"); Assert.hasText(publicKeyId, "微信支付平台公钥Id不能为空");
return new RSAPublicKeyConfig.Builder() return new RSAPublicKeyConfig.Builder()
.merchantId(merchantId) .merchantId(merchantId)
.privateKeyFromPath(privateKeyPath) .privateKey(privateKeyContent)
.merchantSerialNumber(merchantSerialNumber) .merchantSerialNumber(merchantSerialNumber)
.apiV3Key(apiV3Key) .apiV3Key(apiV3Key)
.publicKeyFromPath(publicKeyPath) .publicKey(publicKeyContent)
.publicKeyId(publicKeyId) .publicKeyId(publicKeyId)
.build(); .build();
} }
@@ -133,7 +133,7 @@ public class WxPayConfig {
@Bean @Bean
@ConditionalOnProperty(name = "wx_pay.status", havingValue = "open") @ConditionalOnProperty(name = "wx_pay.status", havingValue = "open")
public PrivateKey privateKey(){ public PrivateKey privateKey(){
return PemUtil.loadPrivateKeyFromPath(privateKeyPath); return PemUtil.loadPrivateKeyFromString(privateKeyContent);
} }