|
@@ -0,0 +1,71 @@
|
|
|
+package cn.com.taiji.video.service.impl;
|
|
|
+
|
|
|
+
|
|
|
+import cn.com.taiji.video.model.Token;
|
|
|
+import cn.com.taiji.video.service.IVideoUrlService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.hikvision.artemis.sdk.ArtemisHttpUtil;
|
|
|
+import com.hikvision.artemis.sdk.config.ArtemisConfig;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @Description
|
|
|
+ *
|
|
|
+ * @Author yangyue
|
|
|
+ * @Date 2021/11/18
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class VideoUrlServiceImpl implements IVideoUrlService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ String url = "http://10.110.80.31:8888";
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Object> httpsPost(String deviceids) {
|
|
|
+ MultiValueMap<String,String> params = new LinkedMultiValueMap<>();
|
|
|
+ params.add("client_id","5f1bf9b33df94328a559dfed33bf3605");
|
|
|
+ params.add("client_secret","970f78a3c2704aa2be402933e558f371");
|
|
|
+ params.add("grant_type","client_credentials");
|
|
|
+
|
|
|
+ String tokenUrl = url + "/tglserver/token";
|
|
|
+ log.info(tokenUrl);
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
|
|
|
+ HttpEntity httpEntity = new HttpEntity(params,headers);
|
|
|
+ ResponseEntity<Map> result2 = restTemplate.postForEntity(tokenUrl, httpEntity, Map.class);
|
|
|
+ log.info(result2.getBody().toString());
|
|
|
+ String token = result2.getBody().get("token_type") + " " + result2.getBody().get("access_token");
|
|
|
+ log.info(token);
|
|
|
+
|
|
|
+ //登录接口
|
|
|
+ String deviceUrl = url + "/api/CommonApi/GeMonitorListByDeviceId?client_id=5f1bf9b33df94328a559dfed33bf3605&deviceids="+deviceids;
|
|
|
+
|
|
|
+ headers.clear();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
|
|
|
+ headers.add("Authorization", token);
|
|
|
+ HttpEntity reqEntity = new HttpEntity(headers);
|
|
|
+ log.info(deviceUrl);
|
|
|
+ ResponseEntity<List> mainServiceEntity = restTemplate.exchange(deviceUrl, HttpMethod.GET, reqEntity,List.class);
|
|
|
+ log.info(JSON.toJSONString(mainServiceEntity.getBody()));
|
|
|
+ // return mainServiceEntity.getBody();
|
|
|
+ List<Object> datas = (List<Object>) mainServiceEntity.getBody();
|
|
|
+ if (null == datas || datas.size() == 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ return datas;
|
|
|
+ }
|
|
|
+}
|