Skip to content

Commit 74cbe68

Browse files
committed
Merge branch 'develop'
Conflicts: README.md
2 parents 399017d + 42418a2 commit 74cbe68

File tree

11 files changed

+74
-55
lines changed

11 files changed

+74
-55
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ weixin-java-tools
1717
<dependency>
1818
<groupId>me.chanjar</groupId>
1919
<artifactId>weixin-java-mp</artifactId>
20-
<version>1.1.7</version>
20+
<version>1.1.8</version>
2121
</dependency>
2222
```
2323

@@ -27,7 +27,7 @@ weixin-java-tools
2727
<dependency>
2828
<groupId>me.chanjar</groupId>
2929
<artifactId>weixin-java-cp</artifactId>
30-
<version>1.1.7</version>
30+
<version>1.1.8</version>
3131
</dependency>
3232
```
3333

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>me.chanjar</groupId>
77
<artifactId>weixin-java-parent</artifactId>
8-
<version>1.1.7</version>
8+
<version>1.1.8</version>
99
<packaging>pom</packaging>
1010
<name>WeiXin Java Tools - Parent</name>
1111
<description>微信公众号、企业号上级POM</description>
@@ -225,6 +225,16 @@
225225
<goals>deploy</goals>
226226
</configuration>
227227
</plugin>
228+
<plugin>
229+
<groupId>org.apache.maven.plugins</groupId>
230+
<artifactId>maven-compiler-plugin</artifactId>
231+
<version>2.3.2</version>
232+
<configuration>
233+
<source>1.7</source>
234+
<target>1.7</target>
235+
<encoding>UTF-8</encoding>
236+
</configuration>
237+
</plugin>
228238
</plugins>
229239
</build>
230240

weixin-java-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.1.7</version>
9+
<version>1.1.8</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-common</artifactId>

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaDownloadRequestExecutor.java

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,29 @@ public File execute(CloseableHttpClient httpclient, HttpHost httpProxy, String u
5353
httpGet.setConfig(config);
5454
}
5555

56-
CloseableHttpResponse response = httpclient.execute(httpGet);
56+
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
5757

58-
Header[] contentTypeHeader = response.getHeaders("Content-Type");
59-
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
60-
// 下载媒体文件出错
61-
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
62-
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
63-
throw new WxErrorException(WxError.fromJson(responseContent));
58+
Header[] contentTypeHeader = response.getHeaders("Content-Type");
59+
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
60+
// 下载媒体文件出错
61+
if (ContentType.TEXT_PLAIN.getMimeType().equals(contentTypeHeader[0].getValue())) {
62+
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
63+
throw new WxErrorException(WxError.fromJson(responseContent));
64+
}
6465
}
66+
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
67+
68+
// 视频文件不支持下载
69+
String fileName = getFileName(response);
70+
if (StringUtils.isBlank(fileName)) {
71+
return null;
72+
}
73+
String[] name_ext = fileName.split("\\.");
74+
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile);
75+
return localFile;
76+
6577
}
66-
InputStream inputStream = InputStreamResponseHandler.INSTANCE.handleResponse(response);
67-
68-
// 视频文件不支持下载
69-
String fileName = getFileName(response);
70-
if (StringUtils.isBlank(fileName)) {
71-
return null;
72-
}
73-
String[] name_ext = fileName.split("\\.");
74-
File localFile = FileUtils.createTmpFile(inputStream, name_ext[0], name_ext[1], tmpDirFile);
75-
return localFile;
78+
7679
}
7780

7881
protected String getFileName(CloseableHttpResponse response) {

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/MediaUploadRequestExecutor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,14 @@ public WxMediaUploadResult execute(CloseableHttpClient httpclient, HttpHost http
3939
httpPost.setEntity(entity);
4040
httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString());
4141
}
42-
CloseableHttpResponse response = httpclient.execute(httpPost);
43-
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
44-
WxError error = WxError.fromJson(responseContent);
45-
if (error.getErrorCode() != 0) {
46-
throw new WxErrorException(error);
42+
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
43+
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
44+
WxError error = WxError.fromJson(responseContent);
45+
if (error.getErrorCode() != 0) {
46+
throw new WxErrorException(error);
47+
}
48+
return WxMediaUploadResult.fromJson(responseContent);
4749
}
48-
return WxMediaUploadResult.fromJson(responseContent);
4950
}
5051

5152
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimpleGetRequestExecutor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@ public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String
3333
httpGet.setConfig(config);
3434
}
3535

36-
CloseableHttpResponse response = httpclient.execute(httpGet);
37-
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
38-
WxError error = WxError.fromJson(responseContent);
39-
if (error.getErrorCode() != 0) {
40-
throw new WxErrorException(error);
36+
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
37+
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
38+
WxError error = WxError.fromJson(responseContent);
39+
if (error.getErrorCode() != 0) {
40+
throw new WxErrorException(error);
41+
}
42+
return responseContent;
4143
}
42-
return responseContent;
4344
}
4445

4546
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,14 @@ public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String
4040
httpPost.setEntity(entity);
4141
}
4242

43-
CloseableHttpResponse response = httpclient.execute(httpPost);
44-
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
45-
WxError error = WxError.fromJson(responseContent);
46-
if (error.getErrorCode() != 0) {
47-
throw new WxErrorException(error);
43+
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
44+
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
45+
WxError error = WxError.fromJson(responseContent);
46+
if (error.getErrorCode() != 0) {
47+
throw new WxErrorException(error);
48+
}
49+
return responseContent;
4850
}
49-
return responseContent;
5051
}
5152

5253
}

weixin-java-cp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.1.7</version>
9+
<version>1.1.8</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-cp</artifactId>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
117117
httpGet.setConfig(config);
118118
}
119119
CloseableHttpClient httpclient = getHttpclient();
120-
CloseableHttpResponse response = httpclient.execute(httpGet);
121-
String resultContent = new BasicResponseHandler().handleResponse(response);
120+
String resultContent = null;
121+
try (CloseableHttpResponse response = httpclient.execute(httpGet)) {
122+
resultContent = new BasicResponseHandler().handleResponse(response);
123+
}
122124
WxError error = WxError.fromJson(resultContent);
123125
if (error.getErrorCode() != 0) {
124126
throw new WxErrorException(error);

weixin-java-mp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.1.7</version>
9+
<version>1.1.8</version>
1010
</parent>
1111
<artifactId>weixin-java-mp</artifactId>
1212
<name>WeiXin Java Tools - MP</name>

0 commit comments

Comments
 (0)