Skip to content

Commit 7c6ebe6

Browse files
committed
#1111 微信支付配置支持接口请求地址的可配置
1 parent d09d295 commit 7c6ebe6

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@
1818
*/
1919
@Data
2020
public class WxPayConfig {
21+
private static final String DEFAULT_PAY_BASE_URL = "https://api.mch.weixin.qq.com";
22+
23+
/**
24+
* 微信支付接口请求地址域名部分.
25+
*/
26+
private String payBaseUrl = DEFAULT_PAY_BASE_URL;
2127

2228
/**
2329
* http请求连接超时时间.
@@ -96,6 +102,18 @@ public class WxPayConfig {
96102
private String httpProxyUsername;
97103
private String httpProxyPassword;
98104

105+
/**
106+
* 返回所设置的微信支付接口请求地址域名.
107+
* @return 微信支付接口请求地址域名
108+
*/
109+
public String getPayBaseUrl() {
110+
if (StringUtils.isEmpty(this.payBaseUrl)) {
111+
return DEFAULT_PAY_BASE_URL;
112+
}
113+
114+
return this.payBaseUrl;
115+
}
116+
99117
/**
100118
* 初始化ssl.
101119
*

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
* @author <a href="https://github.com/binarywang">Binary Wang</a>
4848
*/
4949
public abstract class BaseWxPayServiceImpl implements WxPayService {
50-
private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com";
5150
private static final String TOTAL_FUND_COUNT = "资金流水总笔数";
5251

5352
/**
@@ -89,10 +88,10 @@ public void setConfig(WxPayConfig config) {
8988
@Override
9089
public String getPayBaseUrl() {
9190
if (this.getConfig().isUseSandboxEnv()) {
92-
return PAY_BASE_URL + "/sandboxnew";
91+
return this.getConfig().getPayBaseUrl() + "/sandboxnew";
9392
}
9493

95-
return PAY_BASE_URL;
94+
return this.getConfig().getPayBaseUrl();
9695
}
9796

9897
@Override
@@ -101,7 +100,7 @@ public WxPayRefundResult refund(WxPayRefundRequest request) throws WxPayExceptio
101100

102101
String url = this.getPayBaseUrl() + "/secapi/pay/refund";
103102
if (this.getConfig().isUseSandboxEnv()) {
104-
url = PAY_BASE_URL + "/sandboxnew/pay/refund";
103+
url = this.getConfig().getPayBaseUrl() + "/sandboxnew/pay/refund";
105104
}
106105

107106
String responseContent = this.post(url, request.toXML(), true);

0 commit comments

Comments
 (0)