11package me .chanjar .weixin .mp .util .http ;
22
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+
810import org .apache .commons .io .IOUtils ;
911import org .apache .http .HttpHost ;
1012import org .apache .http .client .config .RequestConfig ;
1315import org .apache .http .entity .StringEntity ;
1416import org .apache .http .impl .client .CloseableHttpClient ;
1517
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 ;
2223
2324public class MaterialVoiceAndImageDownloadRequestExecutor implements RequestExecutor <InputStream , String > {
2425
@@ -44,9 +45,9 @@ public InputStream execute(CloseableHttpClient httpclient, HttpHost httpProxy, S
4445 Map <String , String > params = new HashMap <>();
4546 params .put ("media_id" , materialId );
4647 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 );){
4850 // 下载媒体文件出错
49- InputStream inputStream = InputStreamResponseHandler .INSTANCE .handleResponse (response );
5051 byte [] responseContent = IOUtils .toByteArray (inputStream );
5152 String responseContentString = new String (responseContent , "UTF-8" );
5253 if (responseContentString .length () < 100 ) {
0 commit comments