1
zhanghua
2024-12-20 2078aee230bc109d66da296da8b7f24377befa1b
ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java
@@ -94,10 +94,12 @@
    @ApiOperation(value = "根据钉钉授权码获取token")
    @GetMapping("/dingLogin")
    public CommonResult<Map> dingLogin(@RequestParam String code) {
        log.info("一键登录参数code--------------->{}", code);
        HashMap<String, Object> map = new HashMap<>();
        //获取用户信息
        DingUserInfo dingUser = dingCommon.getDingUserInfo(code);
        //按ding登录
        log.info("用户信息------------------->{}", dingUser);
        String token = authService.dingLogin(dingUser);
        map.put("token", token);
        map.put("tokenHead", tokenHead);
@@ -219,7 +221,7 @@
//            MultipartFile file = getMultipartFile(is, fileName);
            String url = ossService.uploadImages(is,dto.getExtension());
            String url = ossService.uploadImages(is, dto.getExtension(),0);
            return CommonResult.success(url);
        } catch (Exception e) {
            e.printStackTrace();
@@ -244,21 +246,6 @@
    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);
        return CommonResult.success(url);
@@ -277,17 +264,7 @@
            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();
            DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
            String strDate2 = dtf2.format(LocalDateTime.now());
@@ -332,7 +309,9 @@
     */
    public FileItem createFileItem(InputStream inputStream, String fileName) {
        FileItemFactory factory = new DiskFileItemFactory(16, null);
        String textFieldName = "file";
        DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String strDate2 = dtf2.format(LocalDateTime.now());
        String textFieldName = strDate2 + RandomUtils.generateRandomInt(4);
        FileItem item = factory.createItem(textFieldName, MediaType.MULTIPART_FORM_DATA_VALUE, true, fileName);
        int bytesRead = 0;
        byte[] buffer = new byte[8192];