1
1
package me .chanjar .weixin .mp .util .http ;
2
2
3
- import me .chanjar .weixin .common .bean .result .WxError ;
4
- import me .chanjar .weixin .common .exception .WxErrorException ;
5
- import me .chanjar .weixin .common .util .http .InputStreamResponseHandler ;
6
- import me .chanjar .weixin .common .util .http .RequestExecutor ;
7
- import me .chanjar .weixin .common .util .json .WxGsonBuilder ;
3
+ import java .io .ByteArrayInputStream ;
4
+ import java .io .File ;
5
+ import java .io .IOException ;
6
+ import java .io .InputStream ;
7
+ import java .util .HashMap ;
8
+ import java .util .Map ;
9
+
8
10
import org .apache .commons .io .IOUtils ;
9
11
import org .apache .http .HttpHost ;
10
12
import org .apache .http .client .config .RequestConfig ;
13
15
import org .apache .http .entity .StringEntity ;
14
16
import org .apache .http .impl .client .CloseableHttpClient ;
15
17
16
- import java .io .ByteArrayInputStream ;
17
- import java .io .File ;
18
- import java .io .IOException ;
19
- import java .io .InputStream ;
20
- import java .util .HashMap ;
21
- import java .util .Map ;
18
+ import me .chanjar .weixin .common .bean .result .WxError ;
19
+ import me .chanjar .weixin .common .exception .WxErrorException ;
20
+ import me .chanjar .weixin .common .util .http .InputStreamResponseHandler ;
21
+ import me .chanjar .weixin .common .util .http .RequestExecutor ;
22
+ import me .chanjar .weixin .common .util .json .WxGsonBuilder ;
22
23
23
24
public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExecutor <InputStream , String > {
24
25
@@ -44,9 +45,9 @@ public InputStream execute(CloseableHttpClient httpclient, HttpHost httpProxy, S
44
45
Map <String , String > params = new HashMap <>();
45
46
params .put ("media_id" , materialId );
46
47
httpPost .setEntity (new StringEntity (WxGsonBuilder .create ().toJson (params )));
47
- try (CloseableHttpResponse response = httpclient .execute (httpPost )){
48
+ try (CloseableHttpResponse response = httpclient .execute (httpPost );
49
+ InputStream inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );){
48
50
// 下载媒体文件出错
49
- InputStream inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );
50
51
byte [] responseContent = IOUtils .toByteArray (inputStream );
51
52
String responseContentString = new String (responseContent , "UTF-8" );
52
53
if (responseContentString .length () < 100 ) {
0 commit comments