|
@ -93,7 +93,7 @@ public class BsSgcDfSpPlayService { |
|
|
// 2. 获取令牌
|
|
|
// 2. 获取令牌
|
|
|
String spOauthTokenUrlJson = getToken(dto); |
|
|
String spOauthTokenUrlJson = getToken(dto); |
|
|
JSONObject tokenJson = parseJson(spOauthTokenUrlJson); |
|
|
JSONObject tokenJson = parseJson(spOauthTokenUrlJson); |
|
|
if (tokenJson == null || !isSuccess(tokenJson)) { |
|
|
if (!isSuccess(tokenJson)) { |
|
|
return rest; |
|
|
return rest; |
|
|
} |
|
|
} |
|
|
JSONObject tokenData = tokenJson.getJSONObject("data"); |
|
|
JSONObject tokenData = tokenJson.getJSONObject("data"); |
|
@ -149,31 +149,19 @@ public class BsSgcDfSpPlayService { |
|
|
return JSONObject.parseObject(json); |
|
|
return JSONObject.parseObject(json); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 解析 JSON 字符串为 JSONArray |
|
|
|
|
|
*/ |
|
|
|
|
|
private JSONArray parseJsonArray(Object obj) { |
|
|
|
|
|
if (obj == null) { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
|
|
|
return JSON.parseArray(obj.toString()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 判断接口响应是否成功 |
|
|
* 判断接口响应是否成功 |
|
|
*/ |
|
|
*/ |
|
|
private boolean isSuccess(JSONObject json) { |
|
|
private boolean isSuccess(JSONObject json) { |
|
|
return json != null && Objects.equals(200, json.getIntValue("code")); |
|
|
return json != null && Objects.equals(0, json.getIntValue("code")); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public String getSpPlayUrls(DfSpPlayQueDto dto) { |
|
|
public String getSpPlayUrls(DfSpPlayQueDto dto) { |
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
|
|
|
Map<String, String> uriVariables = new HashMap<>(); |
|
|
Map<String, String> uriVariables = new HashMap<>(); |
|
|
MultiValueMap<String, String> headValues = new LinkedMultiValueMap<>(); |
|
|
MultiValueMap<String, String> headValues = new LinkedMultiValueMap<>(); |
|
|
headValues.put("token", Collections.singletonList(dto.getToken())); |
|
|
headValues.put("token", Collections.singletonList(dto.getToken())); |
|
|
Map<String, String> paramMap = new HashMap<>(); |
|
|
Map<String, String> paramMap = new HashMap<>(); |
|
|
paramMap.put("cameraId", dto.getCameraId()); |
|
|
paramMap.put("cameraId", dto.getCameraId()); |
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
|
|
|
String seqResult2 = null; |
|
|
String seqResult2 = null; |
|
|
try { |
|
|
try { |
|
|
seqResult2 = RestTemplateUtil.postForObjectWithHead(paramMap, headValues, videoUrl + SP_PLAY_URL, String.class, uriVariables); |
|
|
seqResult2 = RestTemplateUtil.postForObjectWithHead(paramMap, headValues, videoUrl + SP_PLAY_URL, String.class, uriVariables); |
|
@ -187,12 +175,11 @@ public class BsSgcDfSpPlayService { |
|
|
public String getToken(DfSpPlayQueDto dto) { |
|
|
public String getToken(DfSpPlayQueDto dto) { |
|
|
dto.setMobile(videoPhone); |
|
|
dto.setMobile(videoPhone); |
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
String token = null; |
|
|
|
|
|
String requestStr = JSONObject.toJSONString(dto); |
|
|
String requestStr = JSONObject.toJSONString(dto); |
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
HttpHeaders headers = new HttpHeaders(); |
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
headers.setContentType(MediaType.APPLICATION_JSON); |
|
|
HttpEntity<String> httpEntity = new HttpEntity<>(requestStr, headers); |
|
|
HttpEntity<String> httpEntity = new HttpEntity<>(requestStr, headers); |
|
|
String seqResult = ""; |
|
|
String seqResult; |
|
|
try { |
|
|
try { |
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(videoUrl + OAUTH_TOKEN, HttpMethod.POST, httpEntity, String.class); |
|
|
ResponseEntity<String> responseEntity = restTemplate.exchange(videoUrl + OAUTH_TOKEN, HttpMethod.POST, httpEntity, String.class); |
|
|
seqResult = responseEntity.getBody(); |
|
|
seqResult = responseEntity.getBody(); |
|
@ -200,6 +187,6 @@ public class BsSgcDfSpPlayService { |
|
|
} catch (Exception e) { |
|
|
} catch (Exception e) { |
|
|
log.warn("请求接口OAUTH_TOKEN返回异常: {}", e.getMessage()); |
|
|
log.warn("请求接口OAUTH_TOKEN返回异常: {}", e.getMessage()); |
|
|
} |
|
|
} |
|
|
return token; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|