From f6c19ce9e8ec6ccbcc9f6eaa3d168b27bba214eb Mon Sep 17 00:00:00 2001 From: EricsHu <hrr145632> Date: 星期二, 06 六月 2023 15:17:31 +0800 Subject: [PATCH] 资源,直播,考试 --- src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java | 69 +++++++++++++++++++++++++--------- 1 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java b/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java index 0e76919..481c30d 100644 --- a/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java +++ b/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java @@ -1,13 +1,13 @@ package com.qxueyou.scc.stucontroller; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.qxueyou.scc.sdk.MTCloud; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @@ -29,6 +29,7 @@ @Api(tags="鐩存挱鎺ュ彛-瀛﹀憳绔�") @RestController +@CrossOrigin @RequestMapping(value = "/stu/live") public class StuLiveController { @@ -115,22 +116,52 @@ /** * 鏌ョ湅鐩存挱鏄庣粏 - * @param liveId 鐩存挱id + * @param couresId 鐩存挱id * @return */ @GetMapping(value = "view") - public Result view(String liveId) { - - MediaVideoLive live = liveService.read(liveId); - - return new Result(true, "success", CollectionUtils.newObjectMap( - "startTime",live.getStartTime(), - "endTime",live.getEndTime(), - "name",live.getName(), - "hlsPullUrl",live.getHlsPullUrl(), - "imgPath",live.getPreviewImgUrl(), - "chatroomId",dao.getChatRoomId(liveId), - "remark",live.getRemark() - )); + public Result view(String couresId,String userId,String userName) throws Exception { + + + MTCloud client = new MTCloud(); + + HashMap<Object,Object> options = new HashMap<Object, Object>(); + if(userId.equals("")){ + userId= randomId(); + } + if(userName.equals("") || userName==null){ + userName= "娓稿"; + } + + String res = client.courseAccess(couresId,userId,userName, MTCloud.ROLE_USER, 10000, options); + JSONObject jsonObject = JSON.parseObject(res); + + + if(jsonObject.getString("code").equals("0")){ + JSONObject data = jsonObject.getJSONObject("data"); + + String liveUrl = (String) data.get("liveUrl"); + + return new Result(true, "success",liveUrl); + } + + return new Result(false, jsonObject.getString("msg")); } + + public String randomId() { + Random random=new Random(); + String str=""; + for (int i = 0; i <12; i++) { + if(i==0){ + //棣栦綅涓嶈兘涓�0涓旀暟瀛楀彇鍊煎尯闂翠负 [1,9] + str+=(random.nextInt(9)+1); + }else{ + //鍏朵綑浣嶇殑鏁板瓧鐨勫彇鍊煎尯闂翠负 [0,9] + str+=random.nextInt(10); + } + } + return str; + } + + } -- Gitblit v1.8.0