From 46251c20b66bb1ca05058ae63a92a195e5543b90 Mon Sep 17 00:00:00 2001 From: zhanghua <314079846@qq.com> Date: 星期四, 02 十一月 2023 21:27:37 +0800 Subject: [PATCH] 优化 --- ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java | 96 +++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 83 insertions(+), 13 deletions(-) diff --git a/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java b/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java index de8b669..eeb2a40 100644 --- a/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java +++ b/ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java @@ -2,17 +2,23 @@ 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; +import com.aliyun.oss.common.utils.StringUtils; import com.aliyun.oss.model.ObjectMetadata; import com.ycl.api.CommonResult; import com.ycl.bo.AdminUserDetails; import com.ycl.common.dingding.DingCommon; +import com.ycl.config.DdTest; import com.ycl.config.DingConfig; import com.ycl.controller.BaseController; +import com.ycl.dto.video.OssFileDto; import com.ycl.entity.dingding.DingUserInfo; import com.ycl.service.auth.AuthService; import com.ycl.service.ding.BookRemarkService; @@ -184,10 +190,74 @@ return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark)); } - @ApiOperation(value = "閫氳褰曢�掑綊") + + @PostMapping("/oss/sign") + public CommonResult ossSign(@RequestBody OssFileDto dto) { + + if (StringUtils.isNullOrEmpty(dto.getMediaId()) || StringUtils.isNullOrEmpty(dto.getExtension())) { + return CommonResult.failed("鍙傛暟涓嶈兘涓虹┖锛�"); + } + ExecutableClient executableClient = DdTest.getExecutableClient(); + CloseableHttpResponse response = null; + OSS ossClient = null; + + DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + System.out.println("寮�濮嬭幏鍙�--" + dtf2.format(LocalDateTime.now())); + try { + //浠庨拤閽夎幏鍙栬棰戞祦 + String api = "/media/download"; + GetClient getClient = executableClient.newGetClient(api); + //浠巖edis鑾峰彇token + String token = getToken(); + //璁剧疆鍙傛暟 + getClient.addParameter("access_token", token); + getClient.addParameter("media_id", dto.getMediaId()); + response = getClient.getB(); + HttpEntity entity = response.getEntity(); + InputStream is = entity.getContent(); + +// MultipartFile file = getMultipartFile(is, fileName); + + String url = ossService.uploadImages(is,dto.getExtension()); + return CommonResult.success(url); + } catch (Exception e) { + e.printStackTrace(); + System.out.println(e.getMessage()); + } finally { + if (ossClient != null) { + ossClient.shutdown(); + } + if (response != null) { + try { + response.close(); + } catch (Exception e) { + System.out.println(e); + } + } + } + return null; + } + + @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); + //濯掍綋鏂囦欢绫诲瀷锛屽垎鍒湁鍥剧墖锛坕mage锛夈�佽闊筹紙voice锛夈�佹櫘閫氭枃浠�(file) + oapiMediaUploadRequest.setType("file"); + //orm-data涓獟浣撴枃浠舵爣璇嗭紝鏈塮ilename銆乫ilelength銆乧ontent-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 +271,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()); -- Gitblit v1.8.0