mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-24 18:04:38 +08:00
微信支付接口请求增加超时时间的设置参数
This commit is contained in:
parent
c5c204b25d
commit
d3c691af09
@ -18,6 +18,17 @@ import java.security.KeyStore;
|
||||
* @author Binary Wang (https://github.com/binarywang)
|
||||
*/
|
||||
public class WxPayConfig {
|
||||
|
||||
/**
|
||||
* http请求连接超时时间
|
||||
*/
|
||||
private int httpConnectionTimeout = 5000;
|
||||
|
||||
/**
|
||||
* http请求数据读取等待时间
|
||||
*/
|
||||
private int httpTimeout = 10000;
|
||||
|
||||
private String appId;
|
||||
private String subAppId;
|
||||
private String mchId;
|
||||
@ -194,4 +205,26 @@ public class WxPayConfig {
|
||||
IOUtils.closeQuietly(inputStream);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* http请求连接超时时间
|
||||
*/
|
||||
public int getHttpConnectionTimeout() {
|
||||
return this.httpConnectionTimeout;
|
||||
}
|
||||
|
||||
public void setHttpConnectionTimeout(int httpConnectionTimeout) {
|
||||
this.httpConnectionTimeout = httpConnectionTimeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* http请求数据读取等待时间
|
||||
*/
|
||||
public int getHttpTimeout() {
|
||||
return this.httpTimeout;
|
||||
}
|
||||
|
||||
public void setHttpTimeout(int httpTimeout) {
|
||||
this.httpTimeout = httpTimeout;
|
||||
}
|
||||
}
|
||||
|
@ -465,9 +465,11 @@ public class WxPayServiceImpl implements WxPayService {
|
||||
* @return 返回请求结果
|
||||
*/
|
||||
private String post(String url, String xmlParam) throws WxPayException {
|
||||
String requestString = new String(xmlParam.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
|
||||
|
||||
HttpRequest request = HttpRequest.post(url).body(requestString);
|
||||
HttpRequest request = HttpRequest
|
||||
.post(url)
|
||||
.timeout(this.config.getHttpTimeout())
|
||||
.connectionTimeout(this.config.getHttpConnectionTimeout())
|
||||
.body(new String(xmlParam.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
|
||||
String responseString = this.getResponseString(request.send());
|
||||
|
||||
this.log.info("\n【请求地址】: {}\n【请求参数】:{}\n【响应数据】:{}", url, xmlParam, responseString);
|
||||
@ -489,6 +491,8 @@ public class WxPayServiceImpl implements WxPayService {
|
||||
|
||||
HttpRequest request = HttpRequest
|
||||
.post(url)
|
||||
.timeout(this.config.getHttpTimeout())
|
||||
.connectionTimeout(this.config.getHttpConnectionTimeout())
|
||||
.withConnectionProvider(new SSLSocketHttpConnectionProvider(sslContext))
|
||||
.bodyText(requestStr);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user