From a4cd4c2d98392cd1036f36b96c262878743a7e63 Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期四, 05 九月 2024 19:52:22 +0800
Subject: [PATCH] Merge branch 'master' of http://42.193.1.25:9521/r/sccg_server

---
 ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java |   77 +++++++++++++++++++++++++++++++-------
 1 files changed, 63 insertions(+), 14 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..fcb1d8b 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;
@@ -88,10 +94,12 @@
     @ApiOperation(value = "鏍规嵁閽夐拤鎺堟潈鐮佽幏鍙杢oken")
     @GetMapping("/dingLogin")
     public CommonResult<Map> dingLogin(@RequestParam String code) {
+        log.info("涓�閿櫥褰曞弬鏁癱ode--------------->{}", code);
         HashMap<String, Object> map = new HashMap<>();
         //鑾峰彇鐢ㄦ埛淇℃伅
         DingUserInfo dingUser = dingCommon.getDingUserInfo(code);
         //鎸塪ing鐧诲綍
+        log.info("鐢ㄦ埛淇℃伅------------------->{}", dingUser);
         String token = authService.dingLogin(dingUser);
         map.put("token", token);
         map.put("tokenHead", tokenHead);
@@ -184,7 +192,56 @@
         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();
@@ -201,23 +258,13 @@
             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();
+
             DateTimeFormatter dtf2 = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
 
             String strDate2 = dtf2.format(LocalDateTime.now());
@@ -262,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];

--
Gitblit v1.8.0