| | |
| | | import com.sandu.ximon.admin.utils.response.*; |
| | | import com.sandu.ximon.dao.domain.LedPlayerEntity; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.http.NameValuePair; |
| | | import org.apache.http.message.BasicNameValuePair; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.net.URISyntaxException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Component("VnnoxAPIUtil") |
| | | @AllArgsConstructor |
| | |
| | | /** |
| | | * 获取token |
| | | */ |
| | | public void getToken () { |
| | | public void getToken() { |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.GET_TOKEN), |
| | | new VnnoxGetTokenRequest().toJson(), |
| | | new CommonHeader(CommonHeader.FORM, false) |
| | | ); |
| | | |
| | | CommonResponse commonResponse = JSON.parseObject(result,CommonResponse.class); |
| | | CommonResponse commonResponse = JSON.parseObject(result, CommonResponse.class); |
| | | VnnoxGetTokenResponse response = new VnnoxGetTokenResponse().parse(commonResponse); |
| | | // 将token保存到redis缓存中 |
| | | redisUtils.set(VnnoxConstant.REDIS_TOKEN_NAME,response.getToken(),(long)(response.getExpire()-30)); |
| | | redisUtils.set(VnnoxConstant.REDIS_TOKEN_NAME, response.getToken(), (long) (response.getExpire() - 30)); |
| | | } |
| | | |
| | | |
| | |
| | | * @param start 从第几条记录开始读取,默认0 |
| | | * @return |
| | | */ |
| | | public VnnoxPlayerListResponse getPlayerList(Integer count, Integer start) { |
| | | public VnnoxPlayerListResponse getPlayerList(Integer count, Integer start, String name) throws URISyntaxException { |
| | | |
| | | List<NameValuePair> urlParameters = new ArrayList<>(); |
| | | urlParameters.add(new BasicNameValuePair("count", count.toString())); |
| | | urlParameters.add(new BasicNameValuePair("start", start.toString())); |
| | | urlParameters.add(new BasicNameValuePair("name", name)); |
| | | |
| | | String result = VnnoxRequestUtil.GetWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.GET_PLAYER_LIST), |
| | | new VnnoxGetPlayerListRequest(count, start).toJson(), |
| | | urlParameters, |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | VnnoxPlayerListResponse response = |
| | | new VnnoxPlayerListResponse().parse(JSON.parseObject(result, CommonResponse.class)); |
| | | return response; |
| | | return new VnnoxPlayerListResponse().parse(JSON.parseObject(result, CommonResponse.class)); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public List<LedPlayerEntity> syncCurrentInfo(List<LedPlayerEntity> list) { |
| | | List<String> playerIds = new ArrayList<>(); |
| | | if (list.isEmpty()) { |
| | | return list; |
| | | } |
| | | |
| | | for (LedPlayerEntity playerEntity : list) { |
| | | playerIds.add(playerEntity.getPlayerId()); |
| | |
| | | return response.getData(); |
| | | } |
| | | |
| | | /** |
| | | * 同步播放 |
| | | */ |
| | | public VnnoxResult syncPlay(List<String> playerId, Integer option) { |
| | | VnnoxBaseRequest request = new VnnoxBaseRequest(); |
| | | request.setPlayerIds(playerId); |
| | | request.setOption(option); |
| | | request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL); |
| | | |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.SIMU_LCAST), |
| | | request.toJson(), |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | |
| | | return response.getData(); |
| | | } |
| | | |
| | | /** |
| | | * NTP_SYNC |
| | | */ |
| | | public VnnoxResult ntpSync(List<String> playerId, boolean enable) { |
| | | // VnnoxBaseRequest request = new VnnoxBaseRequest(); |
| | | // request.setPlayerIds(playerId); |
| | | // request.setEnable(enable); |
| | | // request.setServer("ntp1.aliyun.com"); |
| | | // request.setNoticeUrl(VnnoxConstant.SCREEN_SHOT_NOTIFY_URL); |
| | | Map map = new HashMap(); |
| | | map.put("server", "ntp1.aliyun.com"); |
| | | map.put("enable", enable); |
| | | map.put("noticeUrl", VnnoxConstant.SCREEN_SHOT_NOTIFY_URL); |
| | | map.put("playerIds", playerId); |
| | | String s = JSON.toJSONString(map); |
| | | String result = VnnoxRequestUtil.PostWithHeader( |
| | | VnnoxUrl.getUrl(VnnoxUrl.NTP_SYNC), |
| | | s, |
| | | new CommonHeader(CommonHeader.JSON, true) |
| | | ); |
| | | VnnoxResultResponse response = JSON.parseObject(result, VnnoxResultResponse.class); |
| | | |
| | | return response.getData(); |
| | | } |
| | | |
| | | } |