🎨 #3968【微信支付】修复微信支付api-host-url配置反向代理路径前缀时会导致v3签名异常的问题
This commit is contained in:
@@ -255,6 +255,7 @@ public class PayService {
|
||||
| payScorePermissionNotifyUrl | 支付分授权回调地址 | 无 |
|
||||
| useSandboxEnv | 是否使用沙箱环境 | false |
|
||||
| apiHostUrl | 自定义API主机地址 | https://api.mch.weixin.qq.com |
|
||||
| apiHostUrlPath | 自定义API主机路径前缀(代理入口前缀) | 空 |
|
||||
| strictlyNeedWechatPaySerial | 是否所有V3请求都添加序列号头 | true |
|
||||
| fullPublicKeyModel | 是否完全使用公钥模式 | true |
|
||||
| publicKeyId | 公钥ID | 无 |
|
||||
|
||||
@@ -112,6 +112,12 @@ public class WxPaySingleProperties implements Serializable {
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义API主机路径前缀(用于代理入口前缀).
|
||||
* 例如:/api-weixin
|
||||
*/
|
||||
private String apiHostUrlPath;
|
||||
|
||||
/**
|
||||
* 是否将全部v3接口的请求都添加Wechatpay-Serial请求头,默认添加.
|
||||
*/
|
||||
|
||||
@@ -83,6 +83,7 @@ public class WxPayMultiServicesImpl implements WxPayMultiServices {
|
||||
payConfig.setPublicKeyId(StringUtils.trimToNull(properties.getPublicKeyId()));
|
||||
payConfig.setPublicKeyPath(StringUtils.trimToNull(properties.getPublicKeyPath()));
|
||||
payConfig.setApiHostUrl(StringUtils.trimToNull(properties.getApiHostUrl()));
|
||||
payConfig.setApiHostUrlPath(StringUtils.trimToNull(properties.getApiHostUrlPath()));
|
||||
payConfig.setStrictlyNeedWechatPaySerial(properties.isStrictlyNeedWechatPaySerial());
|
||||
payConfig.setFullPublicKeyModel(properties.isFullPublicKeyModel());
|
||||
|
||||
|
||||
@@ -26,6 +26,8 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||
"wx.pay.configs.app1.notify-url=https://example.com/pay/notify",
|
||||
"wx.pay.configs.app2.app-id=wx2222222222222222",
|
||||
"wx.pay.configs.app2.mch-id=2222222222",
|
||||
"wx.pay.configs.app2.api-host-url=http://10.0.0.1:3128",
|
||||
"wx.pay.configs.app2.api-host-url-path=/api-weixin",
|
||||
"wx.pay.configs.app2.apiv3-key=22222222222222222222222222222222",
|
||||
"wx.pay.configs.app2.cert-serial-no=2222222222222222",
|
||||
"wx.pay.configs.app2.private-key-path=classpath:cert/apiclient_key.pem",
|
||||
@@ -57,7 +59,9 @@ public class WxPayMultiServicesTest {
|
||||
assertNotNull(app2Config, "app2 configuration should exist");
|
||||
assertEquals("wx2222222222222222", app2Config.getAppId());
|
||||
assertEquals("2222222222", app2Config.getMchId());
|
||||
assertEquals("22222222222222222222222222222222", app2Config.getApiV3Key());
|
||||
assertEquals("http://10.0.0.1:3128", app2Config.getApiHostUrl());
|
||||
assertEquals("/api-weixin", app2Config.getApiHostUrlPath());
|
||||
assertEquals("22222222222222222222222222222222", app2Config.getApiv3Key());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,6 +75,7 @@ public class WxPayMultiServicesTest {
|
||||
assertNotNull(app2Service, "Should get WxPayService for app2");
|
||||
assertEquals("wx2222222222222222", app2Service.getConfig().getAppId());
|
||||
assertEquals("2222222222", app2Service.getConfig().getMchId());
|
||||
assertEquals("/api-weixin", app2Service.getConfig().getApiHostUrlPath());
|
||||
|
||||
// 测试相同key返回相同实例
|
||||
WxPayService app1ServiceAgain = wxPayMultiServices.getWxPayService("app1");
|
||||
|
||||
@@ -23,6 +23,8 @@ wx:
|
||||
pay:
|
||||
appId: xxxxxxxxxxx
|
||||
mchId: 15xxxxxxxxx #商户id
|
||||
apiHostUrl: http://10.0.0.1:3128 # 可选:代理主机
|
||||
apiHostUrlPath: /api-weixin # 可选:代理入口前缀
|
||||
apiV3Key: Dc1DBwSc094jACxxxxxxxxxxxxxxx #V3密钥
|
||||
certSerialNo: 62C6CEAA360BCxxxxxxxxxxxxxxx
|
||||
privateKeyPath: classpath:cert/apiclient_key.pem #apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径
|
||||
|
||||
@@ -63,6 +63,7 @@ public class WxPayAutoConfiguration {
|
||||
payConfig.setPublicKeyId(StringUtils.trimToNull(this.properties.getPublicKeyId()));
|
||||
payConfig.setPublicKeyPath(StringUtils.trimToNull(this.properties.getPublicKeyPath()));
|
||||
payConfig.setApiHostUrl(StringUtils.trimToNull(this.properties.getApiHostUrl()));
|
||||
payConfig.setApiHostUrlPath(StringUtils.trimToNull(this.properties.getApiHostUrlPath()));
|
||||
payConfig.setStrictlyNeedWechatPaySerial(this.properties.isStrictlyNeedWechatPaySerial());
|
||||
payConfig.setFullPublicKeyModel(this.properties.isFullPublicKeyModel());
|
||||
|
||||
|
||||
@@ -111,6 +111,12 @@ public class WxPayProperties {
|
||||
*/
|
||||
private String apiHostUrl;
|
||||
|
||||
/**
|
||||
* 自定义API主机路径前缀(用于代理入口前缀)
|
||||
* 例如:/api-weixin
|
||||
*/
|
||||
private String apiHostUrlPath;
|
||||
|
||||
/**
|
||||
* 是否将全部v3接口的请求都添加Wechatpay-Serial请求头,默认添加
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user