zhanghua
2023-10-23 1295c58e706a74ad68d3c2c84b2bdde779507fb5
ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -2,8 +2,11 @@
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.xxpt.gateway.shared.api.request.OapiMediaUploadRequest;
import com.alibaba.xxpt.gateway.shared.api.response.OapiMediaUploadResponse;
import com.alibaba.xxpt.gateway.shared.client.http.ExecutableClient;
import com.alibaba.xxpt.gateway.shared.client.http.GetClient;
import com.alibaba.xxpt.gateway.shared.client.http.IntelligentPostClient;
import com.alibaba.xxpt.gateway.shared.client.http.PostClient;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
@@ -184,10 +187,25 @@
        return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark));
    }
    @ApiOperation(value = "通讯录递归")
    @ApiOperation(value = "获取视频")
    @GetMapping("/getVideo/{mediaId}")
    public CommonResult<String> getVideo(@PathVariable String mediaId) {
        String accessToken = getToken();
        //executableClient保证单例
        IntelligentPostClient intelligentPostClient = executableClient.newIntelligentPostClient("/media/upload");
        OapiMediaUploadRequest oapiMediaUploadRequest = new OapiMediaUploadRequest();
        //调用接口凭证
        oapiMediaUploadRequest.setAccess_token(accessToken);
        //媒体文件类型,分别有图片(image)、语音(voice)、普通文件(file)
        oapiMediaUploadRequest.setType("file");
        //orm-data中媒体文件标识,有filename、filelength、content-type等信息
        oapiMediaUploadRequest.setMedia("filename");
        intelligentPostClient.addFile(new File("F:\\视频\\7月29日.mp4"));
        //获取结果
        OapiMediaUploadResponse apiResult = intelligentPostClient.post(oapiMediaUploadRequest);
        MultipartFile file = getDownload(accessToken, mediaId);
        String url = ossService.uploadImages(file);
@@ -201,23 +219,23 @@
            String api = "/media/download";
            GetClient getClient = executableClient.newGetClient(api);
            //设置参数
            getClient.addParameter("access_token", "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJ1c2VySWRcIjozLFwidXNlcm5hbWVcIjpcImFkbWluXCJ9IiwiY3JlYXRlZCI6MTY5NDY2NDE5MjA4MiwiZXhwIjoxNjk1MjY4OTkyfQ.fSc0sEfLhD3pgrguYZ0Q4Tr-0wjZNwY2xnGsaGzN1d4oXMnEoX9MJmDQcwEiZ1uLKZbGQCqUtJciAIvINmNq9w ");
            getClient.addParameter("access_token", access_token);
            getClient.addParameter("media_id", media_id);
            response = getClient.getB();
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            File voice = new File("D:/IMG_4401.MOV");
            OutputStream fos = new FileOutputStream(voice);
            int cache = 10 * 1024;
            byte[] buffer = new byte[cache];
            int ch = 0;
            while ((ch = is.read(buffer)) != -1) {
                fos.write(buffer, 0, ch);
            }
            is.close();
            fos.flush();
            fos.close();
//            File voice = new File("D:/IMG_4401.MOV");
//            OutputStream fos = new FileOutputStream(voice);
//            int cache = 10 * 1024;
//            byte[] buffer = new byte[cache];
//            int ch = 0;
//            while ((ch = is.read(buffer)) != -1) {
//                fos.write(buffer, 0, ch);
//            }
//            is.close();
//            fos.flush();
//            fos.close();
            DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
            String strDate2 = dtf2.format(LocalDateTime.now());