mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
修复重构素材上传处理代码
This commit is contained in:
parent
bc22b03ea3
commit
13d76c1c50
@ -30,11 +30,15 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri
|
|||||||
httpPost.setConfig(response);
|
httpPost.setConfig(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material != null) {
|
if (material == null) {
|
||||||
|
throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build());
|
||||||
|
}
|
||||||
|
|
||||||
File file = material.getFile();
|
File file = material.getFile();
|
||||||
if (file == null || !file.exists()) {
|
if (file == null || !file.exists()) {
|
||||||
throw new FileNotFoundException();
|
throw new FileNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create();
|
||||||
multipartEntityBuilder
|
multipartEntityBuilder
|
||||||
.addBinaryBody("media", file)
|
.addBinaryBody("media", file)
|
||||||
@ -43,9 +47,9 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri
|
|||||||
if (material.getForm() != null) {
|
if (material.getForm() != null) {
|
||||||
multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
|
multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form));
|
||||||
}
|
}
|
||||||
|
|
||||||
httpPost.setEntity(multipartEntityBuilder.build());
|
httpPost.setEntity(multipartEntityBuilder.build());
|
||||||
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);
|
||||||
@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user