| | |
| | | package com.qxueyou.scc.stucontroller; |
| | | |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.qxueyou.scc.base.dao.CommonDAO; |
| | | import com.qxueyou.scc.sdk.MTCloud; |
| | | import com.qxueyou.scc.teach.live.model.AccessLog; |
| | | import com.qxueyou.scc.teach.live.utils.RedisCache; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.CrossOrigin; |
| | |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | @Slf4j |
| | | @Api(tags="直播接口-学员端") |
| | | @RestController |
| | | @CrossOrigin |
| | |
| | | |
| | | @Autowired |
| | | MediaLiveDAO dao; |
| | | |
| | | @Autowired |
| | | RedisCache redisCache; |
| | | |
| | | @Autowired |
| | | CommonDAO commonDAO; |
| | | |
| | | private final static short[] PUBLIC_LIVE_STATUS = new short[] { |
| | | MediaVideoLive.STATUS_LIVE_LIVE,MediaVideoLive.STATUS_LIVE_PAUSE, |
| | |
| | | * @return |
| | | */ |
| | | @GetMapping(value = "view") |
| | | public Result view(String couresId,String userId,String userName) throws Exception { |
| | | |
| | | |
| | | public Result view(String couresId,String userId,String userName,String logId) throws Exception { |
| | | AccessLog log=new AccessLog(); |
| | | if(StringUtils.isEmpty(logId)){ |
| | | // String ip = IpUtils.getIpAddr(request); |
| | | // String cityInfo = null; |
| | | // try { |
| | | // cityInfo = IpUtils.getCityInfo(ip); |
| | | // } catch (Exception e) { |
| | | // log.error("获取ip归属地信息失败!"); |
| | | // } |
| | | log.setCourseId(couresId); |
| | | log.setEnterTime(new Date()); |
| | | log.setType("guangxi"); |
| | | log.setName(userName); |
| | | // log.setIp(ip); |
| | | // log.setIpAttribution(cityInfo); |
| | | commonDAO.save(log); |
| | | }else { |
| | | String liveUrl = redisCache.getCacheObject("LIVE_URL" + userId); |
| | | return new Result(true, "success",liveUrl); |
| | | } |
| | | MTCloud client = new MTCloud(); |
| | | |
| | | String userRole = null; |
| | | HashMap<Object,Object> options = new HashMap<Object, Object>(); |
| | | if(userId.equals("")){ |
| | | userId= randomId(); |
| | | } |
| | | if(userName.equals("") || userName==null){ |
| | | userName= "游客"; |
| | | } |
| | | userRole=MTCloud.ROLE_GUEST; |
| | | }else { |
| | | userRole=MTCloud.ROLE_USER; |
| | | } |
| | | String res = client.courseAccess(couresId,userId,userName,userRole, 10000, options); |
| | | |
| | | 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"); |
| | | |
| | | StringBuffer redisLiveUrl = new StringBuffer("LIVE_URL"); |
| | | redisLiveUrl=redisLiveUrl.append(userId); |
| | | redisCache.setCacheObject(redisLiveUrl.toString(),liveUrl,5, TimeUnit.MINUTES); |
| | | return new Result(true, "success",liveUrl); |
| | | } |
| | | |