包括如下接口:
- uploadTempMedia - 上傳臨時資源
- downloadTempMedia - 下載臨時資源
- uploadMedia - 上傳永久資源
- downloadMedia - 下載永久資源
- downloadNewsMedia - 下載圖文資源
- downloadVideoMedia - 下載視頻資源
- deleteMediaMaterial - 刪除永久資源
- imageDomainChange - 上傳圖片變成騰訊域名下的圖片
- getMaterialCount - 獲取永久資源個數(shù)
- batchGetMeterial - 批量獲取永久資源
//可以上傳file或者InputSteam,拿到MediaID
try {
WxMediaUploadResult result = iService.uploadTempMedia(WxConsts.MEDIA_IMAGE,new File("E://test.jpg"));
System.out.println(result.getMedia_id());
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
File file = iService.downloadTempMedia("media_id",new File("E://temp"));
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
//這里注意,如果是上傳非視頻格式的素材,第三個參數(shù)(WxVideoIntroduction)為null即可
WxMediaUploadResult result1 = iService.uploadMedia(WxConsts.MEDIA_VOICE, new File("E://test.m4a"), null);
//如果是上傳視頻Video,可以添加描述
WxVideoIntroduction intro = new WxVideoIntroduction();
intro.setTitle("視頻1");
intro.setIntroduction("描述1");
WxMediaUploadResult result2 = iService.uploadMedia(WxConsts.MEDIA_VIDEO, new File("E://test.mp4"), intro);
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
File file = iService.downloadMedia("media_id",new File("E://temp"));
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
//圖文結(jié)果
WxNewsMediaResult result = iService.downloadNewsMedia("media_id");
System.out.println(result.toString());
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
//視頻結(jié)果,取出URL即可下載
WxVideoMediaResult result = iService.downloadVideoMedia("media_id", new File("E://temp"));
System.out.println(result.toString());
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
WxError result = iService.deleteMediaMaterial("media_id");
System.out.println(result.getErrcode());
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
WxMediaUploadResult result = iService.imageDomainChange(new File("E://test.jpg"));
System.out.println(result.getUrl());
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
WxMaterialCountResult result = iService.getMaterialCount();
System.out.println(result.getImage_count());
System.out.println(result.getNews_count());
} catch (WxErrorException e) {
e.printStackTrace();
}
try {
WxBatchGetMaterialResult result = iService.batchGetMeterial(WxConsts.MEDIA_IMAGE, 0, 5);
} catch (WxErrorException e) {
e.printStackTrace();
}
更多建議: