|
1 | 1 | package com.github.binarywang.wxpay.config; |
2 | 2 |
|
3 | | -import com.github.binarywang.wxpay.exception.WxPayException; |
4 | | -import org.apache.commons.io.IOUtils; |
5 | | -import org.apache.commons.lang3.StringUtils; |
6 | | -import org.apache.http.ssl.SSLContexts; |
7 | | - |
8 | | -import javax.net.ssl.SSLContext; |
9 | 3 | import java.io.File; |
10 | 4 | import java.io.FileInputStream; |
11 | 5 | import java.io.IOException; |
12 | 6 | import java.io.InputStream; |
13 | 7 | import java.security.KeyStore; |
| 8 | +import javax.net.ssl.SSLContext; |
| 9 | + |
| 10 | +import org.apache.commons.io.IOUtils; |
| 11 | +import org.apache.commons.lang3.StringUtils; |
| 12 | +import org.apache.http.ssl.SSLContexts; |
| 13 | + |
| 14 | +import com.github.binarywang.wxpay.exception.WxPayException; |
| 15 | +import lombok.Data; |
14 | 16 |
|
15 | 17 | /** |
16 | 18 | * 微信支付配置 |
17 | 19 | * |
18 | 20 | * @author Binary Wang (https://github.com/binarywang) |
19 | 21 | */ |
| 22 | +@Data |
20 | 23 | public class WxPayConfig { |
21 | 24 |
|
22 | 25 | /** |
23 | | - * http请求连接超时时间 |
| 26 | + * http请求连接超时时间. |
24 | 27 | */ |
25 | 28 | private int httpConnectionTimeout = 5000; |
26 | 29 |
|
27 | 30 | /** |
28 | | - * http请求数据读取等待时间 |
| 31 | + * http请求数据读取等待时间. |
29 | 32 | */ |
30 | 33 | private int httpTimeout = 10000; |
31 | 34 |
|
32 | | - private String appId; |
33 | | - private String subAppId; |
34 | | - private String mchId; |
35 | | - private String mchKey; |
36 | | - private String subMchId; |
37 | | - private String notifyUrl; |
38 | | - private String tradeType; |
39 | | - private String signType; |
40 | | - private SSLContext sslContext; |
41 | | - private String keyPath; |
42 | | - private boolean useSandboxEnv = false; |
43 | | - private String httpProxyHost; |
44 | | - private Integer httpProxyPort; |
45 | | - private String httpProxyUsername; |
46 | | - private String httpProxyPassword; |
47 | | - |
48 | | - public String getKeyPath() { |
49 | | - return keyPath; |
50 | | - } |
51 | | - |
52 | | - /** |
53 | | - * 设置证书 |
54 | | - * |
55 | | - * @param keyPath apiclient_cert.p12的文件的绝对路径 |
56 | | - */ |
57 | | - public void setKeyPath(String keyPath) { |
58 | | - this.keyPath = keyPath; |
59 | | - } |
60 | | - |
61 | 35 | /** |
62 | | - * 商户号 |
| 36 | + * 公众号appid. |
63 | 37 | */ |
64 | | - public String getMchId() { |
65 | | - return this.mchId; |
66 | | - } |
67 | | - |
68 | | - public void setMchId(String mchId) { |
69 | | - this.mchId = mchId; |
70 | | - } |
71 | | - |
| 38 | + private String appId; |
72 | 39 | /** |
73 | | - * 商户密钥 |
| 40 | + * 服务商模式下的子商户公众账号ID. |
74 | 41 | */ |
75 | | - public String getMchKey() { |
76 | | - return this.mchKey; |
77 | | - } |
78 | | - |
79 | | - public void setMchKey(String mchKey) { |
80 | | - this.mchKey = mchKey; |
81 | | - } |
82 | | - |
| 42 | + private String subAppId; |
83 | 43 | /** |
84 | | - * 公众号appid |
| 44 | + * 商户号. |
85 | 45 | */ |
86 | | - public String getAppId() { |
87 | | - return this.appId; |
88 | | - } |
89 | | - |
90 | | - public void setAppId(String appId) { |
91 | | - this.appId = appId; |
92 | | - } |
93 | | - |
| 46 | + private String mchId; |
94 | 47 | /** |
95 | | - * 服务商模式下的子商户公众账号ID |
| 48 | + * 商户密钥. |
96 | 49 | */ |
97 | | - public String getSubAppId() { |
98 | | - return this.subAppId; |
99 | | - } |
100 | | - |
101 | | - public void setSubAppId(String subAppId) { |
102 | | - this.subAppId = subAppId; |
103 | | - } |
104 | | - |
| 50 | + private String mchKey; |
105 | 51 | /** |
106 | | - * 服务商模式下的子商户号 |
| 52 | + * 服务商模式下的子商户号. |
107 | 53 | */ |
108 | | - public String getSubMchId() { |
109 | | - return this.subMchId; |
110 | | - } |
111 | | - |
112 | | - public void setSubMchId(String subMchId) { |
113 | | - this.subMchId = subMchId; |
114 | | - } |
115 | | - |
| 54 | + private String subMchId; |
116 | 55 | /** |
117 | | - * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。 |
| 56 | + * 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数. |
118 | 57 | */ |
119 | | - public String getNotifyUrl() { |
120 | | - return this.notifyUrl; |
121 | | - } |
122 | | - |
123 | | - public void setNotifyUrl(String notifyUrl) { |
124 | | - this.notifyUrl = notifyUrl; |
125 | | - } |
126 | | - |
| 58 | + private String notifyUrl; |
127 | 59 | /** |
128 | | - * 交易类型 |
| 60 | + * 交易类型. |
129 | 61 | * <pre> |
130 | 62 | * JSAPI--公众号支付 |
131 | 63 | * NATIVE--原生扫码支付 |
132 | 64 | * APP--app支付 |
133 | 65 | * </pre> |
134 | 66 | */ |
135 | | - public String getTradeType() { |
136 | | - return this.tradeType; |
137 | | - } |
138 | | - |
139 | | - public void setTradeType(String tradeType) { |
140 | | - this.tradeType = tradeType; |
141 | | - } |
142 | | - |
| 67 | + private String tradeType; |
143 | 68 | /** |
144 | | - * 签名方式 |
| 69 | + * 签名方式. |
145 | 70 | * 有两种HMAC_SHA256 和MD5 |
| 71 | + * |
146 | 72 | * @see com.github.binarywang.wxpay.constant.WxPayConstants.SignType |
147 | 73 | */ |
148 | | - public String getSignType() { |
149 | | - return this.signType; |
150 | | - } |
151 | | - |
152 | | - public void setSignType(String signType) { |
153 | | - this.signType = signType; |
154 | | - } |
155 | | - |
156 | | - public SSLContext getSslContext() { |
157 | | - return this.sslContext; |
158 | | - } |
159 | | - |
160 | | - public void setSslContext(SSLContext sslContext) { |
161 | | - this.sslContext = sslContext; |
162 | | - } |
163 | | - |
| 74 | + private String signType; |
| 75 | + private SSLContext sslContext; |
164 | 76 | /** |
165 | | - * 微信支付是否使用仿真测试环境 |
| 77 | + * 证书apiclient_cert.p12的文件的绝对路径. |
| 78 | + */ |
| 79 | + private String keyPath; |
| 80 | + /** |
| 81 | + * 微信支付是否使用仿真测试环境. |
166 | 82 | * 默认不使用 |
167 | 83 | */ |
168 | | - public boolean useSandbox() { |
169 | | - return this.useSandboxEnv; |
170 | | - } |
| 84 | + private boolean useSandboxEnv = false; |
| 85 | + private String httpProxyHost; |
| 86 | + private Integer httpProxyPort; |
| 87 | + private String httpProxyUsername; |
| 88 | + private String httpProxyPassword; |
171 | 89 |
|
172 | 90 | /** |
173 | | - * 设置是否使用沙箱仿真测试环境 |
| 91 | + * 初始化ssl. |
174 | 92 | */ |
175 | | - public void setUseSandboxEnv(boolean useSandboxEnv) { |
176 | | - this.useSandboxEnv = useSandboxEnv; |
177 | | - } |
178 | | - |
179 | 93 | public SSLContext initSSLContext() throws WxPayException { |
180 | 94 | if (StringUtils.isBlank(this.getMchId())) { |
181 | 95 | throw new WxPayException("请确保商户号mchId已设置"); |
@@ -224,57 +138,4 @@ public SSLContext initSSLContext() throws WxPayException { |
224 | 138 | } |
225 | 139 | } |
226 | 140 |
|
227 | | - /** |
228 | | - * http请求连接超时时间 |
229 | | - */ |
230 | | - public int getHttpConnectionTimeout() { |
231 | | - return this.httpConnectionTimeout; |
232 | | - } |
233 | | - |
234 | | - public void setHttpConnectionTimeout(int httpConnectionTimeout) { |
235 | | - this.httpConnectionTimeout = httpConnectionTimeout; |
236 | | - } |
237 | | - |
238 | | - /** |
239 | | - * http请求数据读取等待时间 |
240 | | - */ |
241 | | - public int getHttpTimeout() { |
242 | | - return this.httpTimeout; |
243 | | - } |
244 | | - |
245 | | - public void setHttpTimeout(int httpTimeout) { |
246 | | - this.httpTimeout = httpTimeout; |
247 | | - } |
248 | | - |
249 | | - public String getHttpProxyHost() { |
250 | | - return httpProxyHost; |
251 | | - } |
252 | | - |
253 | | - public void setHttpProxyHost(String httpProxyHost) { |
254 | | - this.httpProxyHost = httpProxyHost; |
255 | | - } |
256 | | - |
257 | | - public Integer getHttpProxyPort() { |
258 | | - return httpProxyPort; |
259 | | - } |
260 | | - |
261 | | - public void setHttpProxyPort(Integer httpProxyPort) { |
262 | | - this.httpProxyPort = httpProxyPort; |
263 | | - } |
264 | | - |
265 | | - public String getHttpProxyUsername() { |
266 | | - return httpProxyUsername; |
267 | | - } |
268 | | - |
269 | | - public void setHttpProxyUsername(String httpProxyUsername) { |
270 | | - this.httpProxyUsername = httpProxyUsername; |
271 | | - } |
272 | | - |
273 | | - public String getHttpProxyPassword() { |
274 | | - return httpProxyPassword; |
275 | | - } |
276 | | - |
277 | | - public void setHttpProxyPassword(String httpProxyPassword) { |
278 | | - this.httpProxyPassword = httpProxyPassword; |
279 | | - } |
280 | 141 | } |
0 commit comments