From 13e13d59858f7159dabfa4981f62818405491e0d Mon Sep 17 00:00:00 2001 From: EricsHu <hrr145632> Date: 星期四, 15 六月 2023 16:40:16 +0800 Subject: [PATCH] 1 --- src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java | 91 ++++++++++++++++++++++++++++++--------------- 1 files changed, 61 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java b/src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java index 58aa137..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; @@ -27,8 +27,9 @@ import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -@Api(tags="直播接口-学员端") +@Api(tags="鐩存挱鎺ュ彛-瀛﹀憳绔�") @RestController +@CrossOrigin @RequestMapping(value = "/stu/live") public class StuLiveController { @@ -47,14 +48,14 @@ }; /** - * 获取直播列表 - * @param classId 班级id + * 鑾峰彇鐩存挱鍒楄〃 + * @param classId 鐝骇id * @return */ - @ApiOperation(value = "获取直播列表", notes = "") + @ApiOperation(value = "鑾峰彇鐩存挱鍒楄〃", notes = "") @ApiImplicitParams({ - @ApiImplicitParam(name = "classId", value = "班级id", required = true, paramType="query", dataType = "String"), - @ApiImplicitParam(name = "status", value = "直播状态(2正在直播,5直播中的暂停状态,9停止直播,3回放)", required = true, paramType="query", dataType = "String"), + @ApiImplicitParam(name = "classId", value = "鐝骇id", required = true, paramType="query", dataType = "String"), + @ApiImplicitParam(name = "status", value = "鐩存挱鐘舵�侊紙2姝e湪鐩存挱锛�5鐩存挱涓殑鏆傚仠鐘舵�侊紝9鍋滄鐩存挱锛�3鍥炴斁锛�", required = true, paramType="query", dataType = "String"), }) @GetMapping(value = "list") public Result list(String classId, Short status) { @@ -81,7 +82,7 @@ "previewImgUrl","imgPath" )); - //添加聊天室id + //娣诲姞鑱婂ぉ瀹d if(lst!=null && lst.size()>0){ for(Map<String,Object> map:lst) { map.put("chatroomId", dao.getChatRoomId((String)map.get("videoLiveId"))); @@ -92,17 +93,17 @@ } /** - * 获取直播id + * 鑾峰彇鐩存挱id * @param classId * @return */ private List<String> getLiveIdLst(String classId) { List<String> liveIds = new ArrayList<String>(5); - //获取班级列表及班级所在直播列表 + //鑾峰彇鐝骇鍒楄〃鍙婄彮绾ф墍鍦ㄧ洿鎾垪琛� if(StringUtils.isNotEmpty(classId)) { liveIds = dao.getClassLives(classId); - }else { //查询学员所在的全部班级 + }else { //鏌ヨ瀛﹀憳鎵�鍦ㄧ殑鍏ㄩ儴鐝骇 List<ClsClass> clsLst = classService.listMyClass(); Set<String> ids = new HashSet<String>(); for(ClsClass cls:clsLst) { @@ -114,23 +115,53 @@ } /** - * 查看直播明细 - * @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