mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 22:11:40 +08:00
parent
4bee1ba2eb
commit
d3d61d753e
@ -53,7 +53,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
|
||||
|
||||
Header[] contentTypeHeader = response.getHeaders("Content-Type");
|
||||
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
|
||||
@ -63,9 +63,7 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin
|
||||
throw new WxErrorException(WxError.fromJson(responseContent));
|
||||
}
|
||||
}
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
|
||||
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
|
||||
|
||||
// 视频文件不支持下载
|
||||
String fileName = getFileName(response);
|
||||
@ -75,11 +73,9 @@ public class MediaDownloadRequestExecutor implements RequestExecutor<File, Strin
|
||||
String[] name_ext = fileName.split("\\.");
|
||||
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile);
|
||||
return localFile;
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
inputStream.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected String getFileName(CloseableHttpResponse response) {
|
||||
|
@ -39,7 +39,7 @@ public class MediaUploadRequestExecutor implements RequestExecutor<WxMediaUpload
|
||||
httpPost.setEntity(entity);
|
||||
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
|
||||
}
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
@ -47,5 +47,6 @@ public class MediaUploadRequestExecutor implements RequestExecutor<WxMediaUpload
|
||||
}
|
||||
return WxMediaUploadResult.fromJson(responseContent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class SimpleGetRequestExecutor implements RequestExecutor<String, String>
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
@ -41,5 +41,6 @@ public class SimpleGetRequestExecutor implements RequestExecutor<String, String>
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ public class SimplePostRequestExecutor implements RequestExecutor<String, String
|
||||
httpPost.setEntity(entity);
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpPost);
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
|
||||
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
|
||||
WxError error = WxError.fromJson(responseContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
@ -48,5 +48,6 @@ public class SimplePostRequestExecutor implements RequestExecutor<String, String
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -117,8 +117,10 @@ public class WxCpServiceImpl implements WxCpService {
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
CloseableHttpClient httpclient = getHttpclient();
|
||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||
String resultContent = null;
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
|
||||
resultContent = new BasicResponseHandler().handleResponse(response);
|
||||
}
|
||||
WxError error = WxError.fromJson(resultContent);
|
||||
if (error.getErrorCode() != 0) {
|
||||
throw new WxErrorException(error);
|
||||
|
@ -47,8 +47,7 @@ public class QrCodeRequestExecutor implements RequestExecutor<File, WxMpQrCodeTi
|
||||
httpGet.setConfig(config);
|
||||
}
|
||||
|
||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||
|
||||
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
|
||||
Header[] contentTypeHeader = response.getHeaders("Content-Type");
|
||||
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
|
||||
// 出错
|
||||
@ -64,3 +63,5 @@ public class QrCodeRequestExecutor implements RequestExecutor<File, WxMpQrCodeTi
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user