mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 02:28:25 +08:00 
			
		
		
		
	Merge branch 'develop' of https://github.com/binarywang/weixin-java-tools into binarywang-develop
Conflicts: weixin-java-mp/src/main/java/me/chanjar/weixin/mp/util/http/MaterialUploadRequestExecutor.java
This commit is contained in:
		| @ -15,7 +15,6 @@ import org.apache.http.client.methods.HttpPost; | |||||||
| import org.apache.http.entity.ContentType; | import org.apache.http.entity.ContentType; | ||||||
| import org.apache.http.entity.mime.HttpMultipartMode; | import org.apache.http.entity.mime.HttpMultipartMode; | ||||||
| import org.apache.http.entity.mime.MultipartEntityBuilder; | import org.apache.http.entity.mime.MultipartEntityBuilder; | ||||||
| import org.apache.http.entity.mime.content.InputStreamBody; |  | ||||||
| import org.apache.http.impl.client.CloseableHttpClient; | import org.apache.http.impl.client.CloseableHttpClient; | ||||||
|  |  | ||||||
| import java.io.*; | import java.io.*; | ||||||
| @ -23,6 +22,7 @@ import java.util.Map; | |||||||
|  |  | ||||||
| public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> { | public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMaterialUploadResult, WxMpMaterial> { | ||||||
|  |  | ||||||
|  |   @Override | ||||||
|   public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, WxMpMaterial material) throws WxErrorException, ClientProtocolException, IOException { |   public WxMpMaterialUploadResult execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, WxMpMaterial material) throws WxErrorException, ClientProtocolException, IOException { | ||||||
|     HttpPost httpPost = new HttpPost(uri); |     HttpPost httpPost = new HttpPost(uri); | ||||||
|     if (httpProxy != null) { |     if (httpProxy != null) { | ||||||
| @ -35,10 +35,9 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | |||||||
|       if (file == null || !file.exists()) { |       if (file == null || !file.exists()) { | ||||||
|         throw new FileNotFoundException(); |         throw new FileNotFoundException(); | ||||||
|       } |       } | ||||||
|       BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file)); |  | ||||||
|       MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); |       MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); | ||||||
|       multipartEntityBuilder |       multipartEntityBuilder | ||||||
|           .addPart("media", new InputStreamBody(bufferedInputStream, material.getName())) |           .addBinaryBody("media", file) | ||||||
|           .setMode(HttpMultipartMode.RFC6532); |           .setMode(HttpMultipartMode.RFC6532); | ||||||
|       Map<String, String> form = material.getForm(); |       Map<String, String> form = material.getForm(); | ||||||
|       if (material.getForm() != null) { |       if (material.getForm() != null) { | ||||||
| @ -48,7 +47,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | |||||||
|       httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); |       httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     try(CloseableHttpResponse response = httpclient.execute(httpPost)){ |     try (CloseableHttpResponse response = httpclient.execute(httpPost)) { | ||||||
|       String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); |       String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | ||||||
|       WxError error = WxError.fromJson(responseContent); |       WxError error = WxError.fromJson(responseContent); | ||||||
|       if (error.getErrorCode() != 0) { |       if (error.getErrorCode() != 0) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Daniel Qian
					Daniel Qian