Browse Source

腾讯云配置

lyhzzz 2 years ago
parent
commit
77c2294e48

+ 5 - 1
pom.xml

@@ -116,7 +116,11 @@
             <version>3.10.3</version>
         </dependency>
 
-
+        <dependency>
+            <groupId>com.github.tencentyun</groupId>
+            <artifactId>tls-sig-api-v2</artifactId>
+            <version>2.0</version>
+        </dependency>
 
     </dependencies>
 

+ 2 - 0
src/main/java/com/fdkankan/tk/common/util/RedisKeyUtil.java

@@ -3,4 +3,6 @@ package com.fdkankan.tk.common.util;
 public class RedisKeyUtil {
 
     public  static  String AccessToken = "take-look:app_id:";
+    public final static String TENCENT_YUN_KEY = "take-look:tencent:";
+
 }

+ 35 - 0
src/main/java/com/fdkankan/tk/controller/TencentYunController.java

@@ -0,0 +1,35 @@
+package com.fdkankan.tk.controller;
+
+
+import com.fdkankan.tk.common.ResultData;
+import com.fdkankan.tk.service.ITencentYunService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author 
+ * @since 2022-09-27
+ */
+@RestController
+@RequestMapping("/tencentYun")
+public class TencentYunController {
+
+    @Autowired
+    ITencentYunService tencentYunService;
+
+
+    @GetMapping("/getSign")
+    public ResultData getSign(@RequestParam(required = false) String userId){
+        return ResultData.ok(tencentYunService.getSign(userId));
+
+    }
+}
+

+ 63 - 0
src/main/java/com/fdkankan/tk/entity/TencentYun.java

@@ -0,0 +1,63 @@
+package com.fdkankan.tk.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableLogic;
+import com.baomidou.mybatisplus.annotation.TableName;
+import java.io.Serializable;
+import java.util.Date;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author 
+ * @since 2022-09-27
+ */
+@Getter
+@Setter
+@TableName("t_tencent_yun")
+public class TencentYun implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 腾讯云相关
+     */
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @TableField("appid")
+    private Integer appid;
+
+    @TableField("sdk_appid")
+    private Integer sdkAppid;
+
+    @TableField("secretkey")
+    private String secretkey;
+
+    @TableField("bizid")
+    private Integer bizid;
+
+    @TableField("create_time")
+    private String createTime;
+
+    @TableField("update_time")
+    private String updateTime;
+
+    @TableField("tb_status")
+    @TableLogic
+    private Integer tbStatus;
+
+    /**
+     * 过期时间
+     */
+    @TableField("ex_time")
+    private Integer exTime;
+
+
+}

+ 1 - 1
src/main/java/com/fdkankan/tk/generate/AutoGenerate.java

@@ -18,7 +18,7 @@ public class AutoGenerate {
         String path =System.getProperty("user.dir") ;
 
         generate(path,"tk", getTables(new String[]{
-                "t_wx_config",
+                "t_tencent_yun",
         }));
 
 //        generate(path,"goods", getTables(new String[]{

+ 18 - 0
src/main/java/com/fdkankan/tk/mapper/ITencentYunMapper.java

@@ -0,0 +1,18 @@
+package com.fdkankan.tk.mapper;
+
+import com.fdkankan.tk.entity.TencentYun;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author 
+ * @since 2022-09-27
+ */
+@Mapper
+public interface ITencentYunMapper extends BaseMapper<TencentYun> {
+
+}

+ 18 - 0
src/main/java/com/fdkankan/tk/service/ITencentYunService.java

@@ -0,0 +1,18 @@
+package com.fdkankan.tk.service;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.tk.entity.TencentYun;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author 
+ * @since 2022-09-27
+ */
+public interface ITencentYunService extends IService<TencentYun> {
+
+    JSONObject getSign(String userId);
+}

+ 48 - 0
src/main/java/com/fdkankan/tk/service/impl/TencentYunServiceImpl.java

@@ -0,0 +1,48 @@
+package com.fdkankan.tk.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.tk.common.util.RedisKeyUtil;
+import com.fdkankan.tk.entity.TencentYun;
+import com.fdkankan.tk.mapper.ITencentYunMapper;
+import com.fdkankan.tk.service.ITencentYunService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.tencentyun.TLSSigAPIv2;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author 
+ * @since 2022-09-27
+ */
+@Service
+public class TencentYunServiceImpl extends ServiceImpl<ITencentYunMapper, TencentYun> implements ITencentYunService {
+
+    @Autowired
+    RedisUtil redisUtil;
+
+    @Override
+    public JSONObject getSign(String userId) {
+        String redisKey = RedisKeyUtil.TENCENT_YUN_KEY + userId;
+        if (!redisUtil.hasKey(redisKey)) {
+            TencentYun tencentYun = this.getById(1);
+
+            TLSSigAPIv2 api = new TLSSigAPIv2(tencentYun.getSdkAppid(), tencentYun.getSecretkey());
+            String sign = api.genUserSig(userId, tencentYun.getExTime() );
+
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("sdkAppId",tencentYun.getSdkAppid());
+            jsonObject.put("expire",tencentYun.getExTime());
+            jsonObject.put("sign",sign);
+            redisUtil.set(redisKey ,jsonObject.toJSONString(),tencentYun.getExTime() - 60);
+            return jsonObject;
+        }
+        JSONObject jsonObject = JSONObject.parseObject(redisUtil.get(redisKey));
+        jsonObject.put("expire",redisUtil.getExpire(redisKey));
+        return jsonObject;
+    }
+}

+ 5 - 0
src/main/resources/mapper/tk/TencentYunMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.fdkankan.tk.mapper.ITencentYunMapper">
+
+</mapper>