use of com.guhanjie.weixin.model.WeixinMedia in project weixin-boot by guhanjie.
the class MediaKit method postMedia.
public static String postMedia(String path, String type) {
LOGGER.debug("starting to post media: path[{}] type[{}]...", path, type);
final WeixinMedia wm = new WeixinMedia();
try {
String url = WeixinConstants.API_POST_MEDIA;
url = url.replace("TYPE", type);
FileBody fb = new FileBody(new File(path));
HttpEntity entity = MultipartEntityBuilder.create().addPart("media", fb).build();
WeixinHttpUtil.sendPost(url, entity, new WeixinHttpCallback() {
@Override
public void process(String json) {
WeixinMedia t = JSONObject.parseObject(json, WeixinMedia.class);
if (t != null && t.getMedia_id() != null) {
wm.setMedia_id(t.getMedia_id());
LOGGER.info("Success to post media:[{}].", t.getMedia_id());
} else {
LOGGER.error("Failed to post media.");
}
}
});
} catch (Exception e) {
LOGGER.error("error post media: type[{}], path[{}]", type, path);
}
return wm.getMedia_id();
}
Aggregations