From 573d547728164c0de8b043eaa350f10697b32a0a Mon Sep 17 00:00:00 2001
From: zhanghua <314079846@qq.com>
Date: 星期一, 25 九月 2023 22:11:53 +0800
Subject: [PATCH] 油烟

---
 ycl-platform/src/main/java/com/ycl/controller/dingding/DingController.java |  193 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 189 insertions(+), 4 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 2110dbf..ed4f836 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
@@ -1,29 +1,49 @@
 package com.ycl.controller.dingding;
 
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+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.PostClient;
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+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.DingConfig;
 import com.ycl.controller.BaseController;
 import com.ycl.entity.dingding.DingUserInfo;
 import com.ycl.service.auth.AuthService;
 import com.ycl.service.ding.BookRemarkService;
 import com.ycl.service.ding.DingService;
+import com.ycl.utils.ConstantPropertiesUtils;
 import com.ycl.vo.AddressBookVO;
 import com.ycl.vo.NewAddressBookVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.core.context.SecurityContextHolder;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.Resource;
+import java.io.*;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static com.ycl.common.constant.DingConst.*;
+
 @RestController
 @RequestMapping("/ding")
 @Api(tags = "閽夐拤")
+@Slf4j
 public class DingController extends BaseController {
 
     @Autowired
@@ -46,6 +66,15 @@
     @Autowired
     private BookRemarkService bookRemarkService;
 
+    @Resource
+    private ExecutableClient executableClient;
+
+    @Resource
+    private DingConfig dingConfig;
+
+
+
+
     @ApiOperation(value = "鏍规嵁閽夐拤鎺堟潈鐮佽幏鍙杢oken")
     @GetMapping("/dingLogin")
     public CommonResult<Map> dingLogin(@RequestParam String code) {
@@ -60,11 +89,64 @@
         return CommonResult.success(map);
     }
 
+    @ApiOperation(value = "鏍规嵁閽夐拤鎺堟潈鐮佽幏鍙杍sapiToken")
+    @GetMapping("/dingTicker")
+    public CommonResult<Map> dingTicker() {
+        String accessToken = getToken();
+        String ticket = getTiker(accessToken);
+        HashMap<String, Object> map = new HashMap<>();
+
+        map.put("accessToken", accessToken);
+
+        map.put("ticket", ticket);
+        return CommonResult.success(map);
+    }
+
+    private String getToken() {
+        //璋冪敤API
+        GetClient getTokenClient = executableClient.newGetClient(GET_TOKEN);
+        //璁剧疆鍙傛暟
+        getTokenClient.addParameter("appkey", dingConfig.getAppKey());
+        getTokenClient.addParameter("appsecret", dingConfig.getAppSecret());
+        String apiResult = getTokenClient.get();
+        return parsingResult(apiResult);
+    }
+
+    private String getTiker(String accToken) {
+        //璋冪敤API
+        PostClient postClient = executableClient.newPostClient(GET_TIKER);
+        //璁剧疆鍙傛暟
+        if (ObjectUtil.isNotNull(accToken)) {
+            postClient.addParameter("accessToken", accToken);
+            postClient.addParameter("appkey", dingConfig.getAppKey());
+            postClient.addParameter("appsecret", dingConfig.getAppSecret());
+            String apiResult = postClient.post();
+            return parsingResult(apiResult);
+        }
+        return null;
+    }
+
+    private String parsingResult(String apiResult) {
+        if (ObjectUtil.isNotNull(apiResult)) {
+            JSONObject resJson = JSONObject.parseObject(apiResult);
+            if (resJson.getBoolean("success")) {
+                JSONObject content = resJson.getJSONObject("content");
+                if (content.getBoolean("success")) {
+                    JSONObject dataObj = content.getJSONObject("data");
+                    String accessToken = dataObj.getString("accessToken");
+                    return accessToken;
+                }
+            } else {
+                log.error(resJson.toJSONString());
+            }
+        }
+        return null;
+    }
+
     @ApiOperation(value = "閫氳褰�")
     @GetMapping("/addressBook")
     public CommonResult<List<AddressBookVO>> getAddressBook() {
         AdminUserDetails user = (AdminUserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
-
         return CommonResult.success(dingService.getAddressBook(user.getUserId()));
     }
 
@@ -77,8 +159,6 @@
     }
 
 
-
-
     @ApiOperation(value = "閫氳褰曢�掑綊")
     @GetMapping("/getDddressBook")
     public CommonResult<NewAddressBookVO> getNewAddressBook(@RequestParam("id") Long id) {
@@ -87,7 +167,6 @@
     }
 
 
-
     @ApiOperation(value = "淇敼閫氳褰曞娉�")
     @PutMapping("/remark")
     public CommonResult updateRemark(@RequestParam("userId") Long userId, @RequestParam("remark") String remark) {
@@ -95,5 +174,111 @@
         return CommonResult.success(bookRemarkService.updateRemark(user, userId, remark));
     }
 
+    private String getVideo(String MediaId,MultipartFile file) {
+        CloseableHttpResponse response = null;
+        //璋冪敤API
+        GetClient getClient = executableClient.newGetClient(GET_VIDEO);
+        String token =getToken();
+        //璁剧疆鍙傛暟
+        try {
+            if (ObjectUtil.isNotNull(MediaId)) {
+            getClient.addParameter("accessToken", token);
+            getClient.addParameter("mediaId", MediaId);
+//            String result = getClient.get();
+//            return parsingResult(result);
+            response = getClient.getB();
+            HttpEntity entity = response.getEntity();
+            InputStream is = entity.getContent();
+            File voice = new File("/Users/video/log1.xlsx");
+            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();
+            }
+            if (file == null) {
+                return "涓婁紶瑙嗛涓虹┖";
+            }
+            String endpoint = ConstantPropertiesUtils.END_POINT;
+            String accessKeyId = ConstantPropertiesUtils.ACCESS_KEY_ID;
+            String accessKeySecret = ConstantPropertiesUtils.ACCESS_KEY_SECRET;
+            String bucketName = ConstantPropertiesUtils.BUCKET_NAME;
+
+            // 鍒涘缓OSSClient瀹炰緥
+            OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+            // 鑾峰彇鏂囦欢鐨勫悕绉�
+            String fileName = "sczf/" + file.getOriginalFilename();
+            ObjectMetadata objectMetadata = new ObjectMetadata();
+            objectMetadata.setContentType(getcontentType(fileName.substring(fileName.lastIndexOf("."))));
+            // 璋冪敤oss鐨勬柟娉曞疄鐜伴暱浼�
+            // 绗竴涓弬鏁� bucketName
+            // 绗簩涓弬鏁� 涓婁紶鍒皁ss鐨勬枃浠惰矾寰勫拰鏂囦欢鍚嶇О
+            ossClient.putObject(bucketName, fileName, new ByteArrayInputStream(file.getBytes()), objectMetadata);
+            // 鍏抽棴OSSClient銆�
+            ossClient.shutdown();
+            // 鎶婁笂浼犵殑鏂囦欢璺緞杩斿洖 锛堟墜鍔ㄦ嫾鎺ワ級
+            // 杩欓噷璁剧疆鍥剧墖鏈夋晥鏃堕棿 鎴戣缃簡30骞�
+            Date expiration = new Date(System.currentTimeMillis() + (long) 946080000 * 1000);
+            String url = ossClient.generatePresignedUrl(bucketName, fileName, expiration).toString();
+
+            return url;
+            }catch (Exception e) {
+            e.printStackTrace();
+        }finally {
+            if (response != null) {
+                try {
+                    //鐗瑰埆鎻愰啋锛氶渶瑕佽皟鐢╮esponse鐨刢lose鏂规硶鍏抽棴缃戠粶杩炴帴锛侊紒锛�
+                    response.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return null;
+    }
+    public static String getcontentType(String FilenameExtension) {
+        if (FilenameExtension.equalsIgnoreCase(".mp4")||FilenameExtension.equalsIgnoreCase(".mov")) {
+            return "video/mp4";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".bmp")) {
+            return "image/bmp";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".gif")) {
+            return "image/gif";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".jpeg") ||
+                FilenameExtension.equalsIgnoreCase(".jpg") ||
+                FilenameExtension.equalsIgnoreCase(".png")) {
+            return "image/jpg";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".html")) {
+            return "text/html";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".txt")) {
+            return "text/plain";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".vsd")) {
+            return "application/vnd.visio";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".pptx") ||
+                FilenameExtension.equalsIgnoreCase(".ppt")) {
+            return "application/vnd.ms-powerpoint";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".docx") ||
+                FilenameExtension.equalsIgnoreCase(".doc")) {
+            return "application/msword";
+        }
+        if (FilenameExtension.equalsIgnoreCase(".xml")) {
+            return "text/xml";
+        }
+        return "image/jpg";
+    }
+
+
 
 }

--
Gitblit v1.8.0