|
|
@@ -19,10 +19,7 @@ import org.apache.http.auth.AuthScope; |
|
|
|
import org.apache.http.auth.UsernamePasswordCredentials; |
|
|
|
import org.apache.http.client.CredentialsProvider; |
|
|
|
import org.apache.http.client.config.RequestConfig; |
|
|
|
import org.apache.http.client.methods.CloseableHttpResponse; |
|
|
|
import org.apache.http.client.methods.HttpGet; |
|
|
|
import org.apache.http.client.methods.HttpPost; |
|
|
|
import org.apache.http.client.methods.HttpRequestBase; |
|
|
|
import org.apache.http.client.methods.*; |
|
|
|
import org.apache.http.conn.ssl.DefaultHostnameVerifier; |
|
|
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory; |
|
|
|
import org.apache.http.entity.ContentType; |
|
|
@@ -122,8 +119,46 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl { |
|
|
|
} finally { |
|
|
|
httpPost.releaseConnection(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String patchV3(String url, String requestStr) throws WxPayException { |
|
|
|
CloseableHttpClient httpClient = this.createApiV3HttpClient(); |
|
|
|
HttpPatch httpPatch = new HttpPatch(url); |
|
|
|
httpPatch.setEntity(this.createEntry(requestStr)); |
|
|
|
|
|
|
|
httpPatch.setConfig(RequestConfig.custom() |
|
|
|
.setConnectionRequestTimeout(this.getConfig().getHttpConnectionTimeout()) |
|
|
|
.setConnectTimeout(this.getConfig().getHttpConnectionTimeout()) |
|
|
|
.setSocketTimeout(this.getConfig().getHttpTimeout()) |
|
|
|
.build()); |
|
|
|
|
|
|
|
httpPatch.addHeader("Accept", "application/json"); |
|
|
|
httpPatch.addHeader("Content-Type", "application/json"); |
|
|
|
try (CloseableHttpResponse response = httpClient.execute(httpPatch)) { |
|
|
|
//v3已经改为通过状态码判断200 204 成功 |
|
|
|
int statusCode = response.getStatusLine().getStatusCode(); |
|
|
|
//post方法有可能会没有返回值的情况 |
|
|
|
String responseString; |
|
|
|
if (response.getEntity() == null) { |
|
|
|
responseString = null; |
|
|
|
} else { |
|
|
|
responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); |
|
|
|
} |
|
|
|
if (HttpStatus.SC_OK == statusCode || HttpStatus.SC_NO_CONTENT == statusCode) { |
|
|
|
this.log.info("\n【请求地址】:{}\n【请求数据】:{}\n【响应数据】:{}", url, requestStr, responseString); |
|
|
|
return responseString; |
|
|
|
} else { |
|
|
|
//有错误提示信息返回 |
|
|
|
JsonObject jsonObject = GsonParser.parse(responseString); |
|
|
|
throw convertException(jsonObject); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
this.log.error("\n【请求地址】:{}\n【请求数据】:{}\n【异常信息】:{}", url, requestStr, e.getMessage()); |
|
|
|
throw (e instanceof WxPayException) ? (WxPayException) e : new WxPayException(e.getMessage(), e); |
|
|
|
} finally { |
|
|
|
httpPatch.releaseConnection(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
@@ -137,11 +172,9 @@ public class WxPayServiceApacheHttpImpl extends BaseWxPayServiceImpl { |
|
|
|
try (CloseableHttpResponse response = httpClient.execute(httpPost)) { |
|
|
|
//v3已经改为通过状态码判断200 204 成功 |
|
|
|
int statusCode = response.getStatusLine().getStatusCode(); |
|
|
|
this.log.error("====="+statusCode); |
|
|
|
String responseString = "{}"; |
|
|
|
HttpEntity entity = response.getEntity(); |
|
|
|
if (entity != null) { |
|
|
|
this.log.error("====="+entity.toString()); |
|
|
|
responseString = EntityUtils.toString(entity, StandardCharsets.UTF_8); |
|
|
|
} |
|
|
|
|
|
|
|