Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public byte[] postForBytes(String url, String requestStr, boolean useKey) throws
httpPost.releaseConnection();
}
} catch (Exception e) {
this.logError( url, requestStr, e);
this.logError(url, requestStr, e);
wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage()));
throw new WxPayException(e.getMessage(), e);
}
Expand Down Expand Up @@ -105,8 +105,8 @@ public String postV3(String url, String requestStr) throws WxPayException {
}

private String requestV3(String url, String requestStr, HttpRequestBase httpRequestBase) throws WxPayException {
try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpRequestBase)) {
CloseableHttpClient httpClient = this.createApiV3HttpClient();
try (CloseableHttpResponse response = httpClient.execute(httpRequestBase)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
//post方法有可能会没有返回值的情况
Expand Down Expand Up @@ -142,8 +142,8 @@ public String patchV3(String url, String requestStr) throws WxPayException {
public String postV3WithWechatpaySerial(String url, String requestStr) throws WxPayException {
HttpPost httpPost = this.createHttpPost(url, requestStr);
this.configureRequest(httpPost);
try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpPost)) {
CloseableHttpClient httpClient = this.createApiV3HttpClient();
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
String responseString = "{}";
Expand All @@ -170,17 +170,14 @@ public String postV3WithWechatpaySerial(String url, String requestStr) throws Wx

@Override
public String postV3(String url, HttpPost httpPost) throws WxPayException {
String serialNumber = getWechatPaySerial(getConfig());
httpPost.addHeader(WECHAT_PAY_SERIAL, serialNumber);
return this.requestV3(url, httpPost);
}

@Override
public String requestV3(String url, HttpRequestBase httpRequest) throws WxPayException {
this.configureRequest(httpRequest);

try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpRequest)) {
CloseableHttpClient httpClient = this.createApiV3HttpClient();
try (CloseableHttpResponse response = httpClient.execute(httpRequest)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
//post方法有可能会没有返回值的情况
Expand Down Expand Up @@ -223,11 +220,9 @@ public String getV3WithWechatPaySerial(String url) throws WxPayException {
@Override
public InputStream downloadV3(String url) throws WxPayException {
HttpGet httpGet = new WxPayV3DownloadHttpGet(url);
httpGet.addHeader(ACCEPT, ContentType.WILDCARD.getMimeType());
String serialNumber = getWechatPaySerial(getConfig());
httpGet.addHeader(WECHAT_PAY_SERIAL, serialNumber);
try (CloseableHttpClient httpClient = this.createApiV3HttpClient();
CloseableHttpResponse response = httpClient.execute(httpGet)) {
this.configureRequest(httpGet);
CloseableHttpClient httpClient = this.createApiV3HttpClient();
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
//v3已经改为通过状态码判断200 204 成功
int statusCode = response.getStatusLine().getStatusCode();
Header contentType = response.getFirstHeader(HttpHeaders.CONTENT_TYPE);
Expand Down Expand Up @@ -267,8 +262,11 @@ public String deleteV3(String url) throws WxPayException {

private void configureRequest(HttpRequestBase request) {
String serialNumber = getWechatPaySerial(getConfig());
String method = request.getMethod();
request.addHeader(ACCEPT, APPLICATION_JSON);
request.addHeader(CONTENT_TYPE, APPLICATION_JSON);
if (!method.equals("POST")) {
request.addHeader(CONTENT_TYPE, APPLICATION_JSON);
}
request.addHeader(WECHAT_PAY_SERIAL, serialNumber);

request.setConfig(RequestConfig.custom()
Expand Down