|
@ -17,11 +17,12 @@ import org.springframework.http.HttpHeaders; |
|
|
import org.springframework.http.HttpMethod; |
|
|
import org.springframework.http.HttpMethod; |
|
|
import org.springframework.http.MediaType; |
|
|
import org.springframework.http.MediaType; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
import org.springframework.http.ResponseEntity; |
|
|
|
|
|
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
import org.springframework.util.LinkedMultiValueMap; |
|
|
import org.springframework.util.MultiValueMap; |
|
|
import org.springframework.util.MultiValueMap; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.web.client.RestClientException; |
|
|
import org.springframework.web.client.ResourceAccessException; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
import org.springframework.web.client.RestTemplate; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
@ -120,10 +121,10 @@ public class BsSgcDfSpPlayService { |
|
|
DfSpPlayQueDto dfSpPlayQueDto = new DfSpPlayQueDto(); |
|
|
DfSpPlayQueDto dfSpPlayQueDto = new DfSpPlayQueDto(); |
|
|
dfSpPlayQueDto.setCameraId(cameraId); |
|
|
dfSpPlayQueDto.setCameraId(cameraId); |
|
|
DfSpPlayDto play = play(dfSpPlayQueDto); |
|
|
DfSpPlayDto play = play(dfSpPlayQueDto); |
|
|
if (!Objects.isNull(play)) { |
|
|
if (null != play) { |
|
|
dfSpPlayGridDto.getUrlsMapList().add(play.getUrlsMap()); |
|
|
dfSpPlayGridDto.getUrlsMapList().add(play.getUrlsMap()); |
|
|
} |
|
|
} |
|
|
} catch (RestClientException e) { |
|
|
} catch (Exception e) { |
|
|
log.error("请求失败: {}", e.getMessage()); |
|
|
log.error("请求失败: {}", e.getMessage()); |
|
|
} |
|
|
} |
|
|
}, executor); |
|
|
}, executor); |
|
@ -135,25 +136,28 @@ public class BsSgcDfSpPlayService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public DfSpPlayDto play(DfSpPlayQueDto dto) { |
|
|
public DfSpPlayDto play(DfSpPlayQueDto dto) { |
|
|
DfSpPlayDto rest = new DfSpPlayDto(); |
|
|
|
|
|
try { |
|
|
try { |
|
|
// 2. 获取令牌
|
|
|
// 2. 获取令牌
|
|
|
String spOauthTokenUrlJson = getToken(dto); |
|
|
String spOauthTokenUrlJson = getToken(dto); |
|
|
JSONObject tokenJson = parseJson(spOauthTokenUrlJson); |
|
|
JSONObject tokenJson = parseJson(spOauthTokenUrlJson); |
|
|
if (!isSuccess(tokenJson)) { |
|
|
if (!isSuccess(tokenJson)) { |
|
|
log.error("获取令牌失败,{}", tokenJson); |
|
|
log.error("获取令牌失败,{}", tokenJson); |
|
|
return rest; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
JSONObject tokenData = tokenJson.getJSONObject("data"); |
|
|
JSONObject tokenData = tokenJson.getJSONObject("data"); |
|
|
if (tokenData == null) { |
|
|
if (tokenData == null) { |
|
|
log.error("令牌数据为空"); |
|
|
log.error("令牌数据为空"); |
|
|
return rest; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
String token = String.valueOf(tokenData.get("token")); |
|
|
String token = String.valueOf(tokenData.get("token")); |
|
|
dto.setToken(token); |
|
|
dto.setToken(token); |
|
|
// 3. 调用第三方接口获取播放地址
|
|
|
// 3. 调用第三方接口获取播放地址
|
|
|
String playOauthTokenUrlJson = getSpPlayUrls(dto); |
|
|
String playOauthTokenUrlJson = getSpPlayUrls(dto); |
|
|
|
|
|
if (null == playOauthTokenUrlJson) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
VideoInfo videoInfo = JSON.parseObject(playOauthTokenUrlJson, VideoInfo.class); |
|
|
VideoInfo videoInfo = JSON.parseObject(playOauthTokenUrlJson, VideoInfo.class); |
|
|
|
|
|
DfSpPlayDto rest = new DfSpPlayDto(); |
|
|
if (videoInfo.isSuccess()) { |
|
|
if (videoInfo.isSuccess()) { |
|
|
videoInfo.getData().getUrls().setCameraId(dto.getCameraId()); |
|
|
videoInfo.getData().getUrls().setCameraId(dto.getCameraId()); |
|
|
rest.setUrlsMap(videoInfo.getData().getUrls()); |
|
|
rest.setUrlsMap(videoInfo.getData().getUrls()); |
|
@ -162,7 +166,7 @@ public class BsSgcDfSpPlayService { |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("playError: {}", e.getMessage(), e); |
|
|
log.error("playError: {}", e.getMessage(), e); |
|
|
} |
|
|
} |
|
|
return rest; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Data |
|
|
@Data |
|
@ -216,9 +220,20 @@ public class BsSgcDfSpPlayService { |
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
headers.addAll(headValues); |
|
|
headers.addAll(headValues); |
|
|
HttpEntity<?> requestEntity = new HttpEntity(paramMap, headers); |
|
|
HttpEntity<?> requestEntity = new HttpEntity(paramMap, headers); |
|
|
|
|
|
// 创建带超时的RequestFactory
|
|
|
|
|
|
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(); |
|
|
|
|
|
// 3.5秒
|
|
|
|
|
|
factory.setConnectTimeout(3500); |
|
|
|
|
|
// 3.5秒
|
|
|
|
|
|
factory.setReadTimeout(3500); |
|
|
|
|
|
// 创建临时RestTemplate
|
|
|
|
|
|
RestTemplate tempTemplate = new RestTemplate(factory); |
|
|
try { |
|
|
try { |
|
|
seqResult2 = restTemplate.postForObject(videoUrl + SP_PLAY_URL, requestEntity, String.class, uriVariables); |
|
|
seqResult2 = tempTemplate.postForObject(videoUrl + SP_PLAY_URL, requestEntity, String.class, uriVariables); |
|
|
log.info("获取播放地址响应SP_PLAY_URL: {}", JSONObject.toJSONString(seqResult2)); |
|
|
log.info("获取播放地址响应SP_PLAY_URL: {}", JSONObject.toJSONString(seqResult2)); |
|
|
|
|
|
} catch (ResourceAccessException e) { |
|
|
|
|
|
log.error("获取播放地址超时(3.5秒):{}", e.getMessage()); |
|
|
|
|
|
return null; |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.error("请求接口SP_PLAY_URL返回异常: {}", e.getMessage()); |
|
|
log.error("请求接口SP_PLAY_URL返回异常: {}", e.getMessage()); |
|
|
} |
|
|
} |
|
|