lyhzzz 2 лет назад
Родитель
Сommit
cf919c4fa6

+ 3 - 0
src/main/java/com/fdkankan/tk/common/ResultCode.java

@@ -31,6 +31,9 @@ public enum ResultCode {
     FD_USER_NOT_EXIST(8001,"账号不存在,请核对后输入!"),
     ROOM_PER_ERROR(8005,"不能授权给本人!"),
 
+    TENCENT_YUN_EMPTY(9001,"音视频未配置!"),
+    TENCENT_YUN_ERROR(9002,"音视频有多配置!"),
+
 
     ;
     public int code;

+ 2 - 2
src/main/java/com/fdkankan/tk/controller/TestController.java

@@ -28,11 +28,11 @@ import java.util.concurrent.ExecutorService;
 public class TestController {
 
     @Autowired
-    RestTemplateLive restTemplateLive;
+    LiveClient liveClient;
 
     @GetMapping("/test")
     public ResultData test(@RequestParam(required = false) String roomId){
-        JSONObject jsonObject = restTemplateLive.getDanmaku(roomId);
+        JSONObject jsonObject = liveClient.getDanmaku(roomId);
         if(jsonObject != null && jsonObject.getInteger("code") ==0){
             JSONArray data = jsonObject.getJSONArray("data");
             if(data.size() >0){

+ 12 - 1
src/main/java/com/fdkankan/tk/service/impl/TencentYunServiceImpl.java

@@ -2,8 +2,10 @@ package com.fdkankan.tk.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.fdkankan.redis.util.RedisUtil;
+import com.fdkankan.tk.common.ResultCode;
 import com.fdkankan.tk.common.util.RedisKeyUtil;
 import com.fdkankan.tk.entity.TencentYun;
+import com.fdkankan.tk.exception.BusinessException;
 import com.fdkankan.tk.mapper.ITencentYunMapper;
 import com.fdkankan.tk.service.ITencentYunService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -11,6 +13,8 @@ import com.tencentyun.TLSSigAPIv2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.List;
+
 /**
  * <p>
  *  服务实现类
@@ -29,7 +33,14 @@ public class TencentYunServiceImpl extends ServiceImpl<ITencentYunMapper, Tencen
     public JSONObject getSign(String userId) {
         String redisKey = RedisKeyUtil.TENCENT_YUN_KEY + userId;
         if (!redisUtil.hasKey(redisKey)) {
-            TencentYun tencentYun = this.getById(1);
+            List<TencentYun> list = this.list();
+            if(list == null || list.size() <=0){
+                throw new BusinessException(ResultCode.TENCENT_YUN_EMPTY);
+            }
+            if(list.size() >1){
+                throw new BusinessException(ResultCode.TENCENT_YUN_ERROR);
+            }
+            TencentYun tencentYun = list.get(0);
 
             TLSSigAPIv2 api = new TLSSigAPIv2(tencentYun.getSdkAppid(), tencentYun.getSecretkey());
             String sign = api.genUserSig(userId, tencentYun.getExTime() );