|
@@ -0,0 +1,48 @@
|
|
|
+package com.cdf.service.impl;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.cdf.common.RedisUseKey;
|
|
|
+import com.cdf.entity.TencentYun;
|
|
|
+import com.cdf.mapper.ITencentYunMapper;
|
|
|
+import com.cdf.service.ITencentYunService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.tencentyun.TLSSigAPIv2;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author
|
|
|
+ * @since 2022-07-25
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class TencentYunServiceImpl extends ServiceImpl<ITencentYunMapper, TencentYun> implements ITencentYunService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public JSONObject getSign(String userId) {
|
|
|
+ String redisKey = RedisUseKey.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;
|
|
|
+ }
|
|
|
+}
|