4.3)资源上传相关API


包括如下接口:

  • uploadTempMedia - 上传临时资源
  • downloadTempMedia - 下载临时资源
  • uploadMedia - 上传永久资源
  • downloadMedia - 下载永久资源
  • downloadNewsMedia - 下载图文资源
  • downloadVideoMedia - 下载视频资源
  • deleteMediaMaterial - 删除永久资源
  • imageDomainChange - 上传图片变成腾讯域名下的图片
  • getMaterialCount - 获取永久资源个数
  • batchGetMeterial - 批量获取永久资源
1. uploadTempMedia 上传临时文件到微信服务器
        //可以上传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) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

2. downloadTempMedia 下载临时文件,存在E://temp文件夹
        try {
            File file = iService.downloadTempMedia("media_id",new File("E://temp"));
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

3. uploadMedia 上传永久文件到微信服务器。可以传File或者输入流
        try {
            //这里注意,如果是上传非视频格式的素材,第三个参数(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) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

4. downloadMedia 下载永久文件,与临时文件一样用法(注意:图文和视频需要使用另外的方法)
        try {
            File file = iService.downloadMedia("media_id",new File("E://temp"));
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

5. downloadNewsMedia 下载图文素材
        try {
            //图文结果
            WxNewsMediaResult result = iService.downloadNewsMedia("media_id");
            System.out.println(result.toString());
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

6. downloadVideoMedia 下载视频素材
        try {
            //视频结果,取出URL即可下载
            WxVideoMediaResult result = iService.downloadVideoMedia("media_id", new File("E://temp"));
            System.out.println(result.toString());
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

7. deleteMediaMaterial 删除素材资源
        try {
            WxError result = iService.deleteMediaMaterial("media_id");
            System.out.println(result.getErrcode());
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

8. imageDomainChange 上传图片变成腾讯域名下的图片
        try {
            WxMediaUploadResult result = iService.imageDomainChange(new File("E://test.jpg"));
            System.out.println(result.getUrl());
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

9. getMaterialCount 获取永久素材数量接口
        try {
            WxMaterialCountResult result = iService.getMaterialCount();
            System.out.println(result.getImage_count());
            System.out.println(result.getNews_count());
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

10. batchGetMeterial 批量获取永久素材资源信息
        try {
            WxBatchGetMaterialResult result = iService.batchGetMeterial(WxConsts.MEDIA_IMAGE, 0, 5);
        } catch (WxErrorException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

results matching ""

    No results matching ""