mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	修复重构素材上传处理代码
This commit is contained in:
		| @ -30,23 +30,27 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | |||||||
|       httpPost.setConfig(response); |       httpPost.setConfig(response); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     if (material != null) { |     if (material == null) { | ||||||
|       File file = material.getFile(); |       throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build()); | ||||||
|       if (file == null || !file.exists()) { |  | ||||||
|         throw new FileNotFoundException(); |  | ||||||
|       } |  | ||||||
|       MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); |  | ||||||
|       multipartEntityBuilder |  | ||||||
|           .addBinaryBody("media", file) |  | ||||||
|           .setMode(HttpMultipartMode.RFC6532); |  | ||||||
|       Map<String, String> form = material.getForm(); |  | ||||||
|       if (material.getForm() != null) { |  | ||||||
|         multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form)); |  | ||||||
|       } |  | ||||||
|       httpPost.setEntity(multipartEntityBuilder.build()); |  | ||||||
|       httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     File file = material.getFile(); | ||||||
|  |     if (file == null || !file.exists()) { | ||||||
|  |       throw new FileNotFoundException(); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); | ||||||
|  |     multipartEntityBuilder | ||||||
|  |         .addBinaryBody("media", file) | ||||||
|  |         .setMode(HttpMultipartMode.RFC6532); | ||||||
|  |     Map<String, String> form = material.getForm(); | ||||||
|  |     if (material.getForm() != null) { | ||||||
|  |       multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form)); | ||||||
|  |     } | ||||||
|  |      | ||||||
|  |     httpPost.setEntity(multipartEntityBuilder.build()); | ||||||
|  |     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); | ||||||
| @ -55,7 +59,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | |||||||
|       } else { |       } else { | ||||||
|         return WxMpMaterialUploadResult.fromJson(responseContent); |         return WxMpMaterialUploadResult.fromJson(responseContent); | ||||||
|       } |       } | ||||||
|     }finally { |     } finally { | ||||||
|       httpPost.releaseConnection(); |       httpPost.releaseConnection(); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 BinaryWang
					BinaryWang