派生自 projectDept/qhighschool

EricsHu
2023-05-29 cc70ac05f3fcca3b85f7860e7404bb2bfc4429a6
src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
@@ -7,6 +7,7 @@
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;
@@ -28,6 +29,7 @@
@Api(tags="直播接口-学员端")
@RestController
@CrossOrigin
@RequestMapping(value = "/stu/live")
public class StuLiveController {
   
@@ -118,23 +120,48 @@
    * @return
    */
   @GetMapping(value = "view")
   public Result view(String couresId) throws Exception {
   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, ClientUtils.getUserId(), ClientUtils.getUserName(), MTCloud.ROLE_USER, 10000, options);
      String res = client.courseAccess(couresId,userId,userName, MTCloud.ROLE_USER, 10000, options);
      JSONObject jsonObject = JSON.parseObject(res);
      JSONObject data = jsonObject.getJSONObject("data");
      String liveUrl = (String) data.get("liveUrl");
      if(jsonObject.getString("code").equals("0")){
         JSONObject data = jsonObject.getJSONObject("data");
      System.out.println(liveUrl);
         String liveUrl = (String) data.get("liveUrl");
      return new Result(true, "success",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;
      }
}