派生自 projectDept/qhighschool

111
EricsHu
2023-05-24 58a1078809f129905ae30e676c8705e2a083e2ec
src/main/java/com/qxueyou/scc/stucontroller/StuLiveController.java
@@ -118,23 +118,45 @@
    * @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();
      }
      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;
      }
}