商汤接口对接
This commit is contained in:
parent
d4894d4767
commit
a41d0a0b7e
|
@ -5,6 +5,10 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.SocketAddress;
|
||||
|
||||
@Configuration
|
||||
public class RestClient {
|
||||
|
||||
|
@ -16,9 +20,9 @@ public class RestClient {
|
|||
requestFactory.setReadTimeout(30000);
|
||||
requestFactory.setOutputStreaming(false);
|
||||
|
||||
// SocketAddress address = new InetSocketAddress("127.0.0.1", 8888);
|
||||
// Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
|
||||
// requestFactory.setProxy(proxy);
|
||||
/*SocketAddress address = new InetSocketAddress("15.2.23.141", 8888);
|
||||
Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
|
||||
requestFactory.setProxy(proxy);*/
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
restTemplate.setRequestFactory(requestFactory);
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.hisense.monitormanage.entity.*;
|
|||
import com.hisense.monitormanage.mapper.*;
|
||||
import com.hisense.monitormanage.service.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
@ -267,26 +268,6 @@ public class Controller {
|
|||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅任务下发接口
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("subscribe")
|
||||
public JSONObject subscribe(){
|
||||
return monitorService.subscribe();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 事件模板分页查询接口
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("tamplate")
|
||||
public JSONObject tamplate(){
|
||||
return monitorService.template();
|
||||
|
||||
}
|
||||
|
||||
//查询视频点播巡检结果,只取异常的
|
||||
// @RequestMapping("listChannelPlayStates")
|
||||
// public Result listChannelPlayStates(
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
package com.hisense.monitormanage.controller;
|
||||
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hisense.monitormanage.entity.Result;
|
||||
import com.hisense.monitormanage.service.ShangTangService;
|
||||
import org.omg.CORBA.Request;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("STapi/project")
|
||||
public class ShangTangController {
|
||||
|
||||
@Autowired
|
||||
private ShangTangService shangTangService;
|
||||
|
||||
/**
|
||||
* 订阅任务下发接口
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("subscribe")
|
||||
public JSONObject subscribe(){
|
||||
return shangTangService.subscribe();
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅任务下发接口
|
||||
* @param request
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping("receive")
|
||||
public Result receive(HttpServletRequest request) throws IOException {
|
||||
ServletInputStream ris = request.getInputStream();
|
||||
StringBuilder content = new StringBuilder();
|
||||
byte[] b = new byte[1024];
|
||||
int lens = -1;
|
||||
while ((lens = ris.read(b)) > 0) {
|
||||
content.append(new String(b, 0, lens));
|
||||
}
|
||||
String strcont = content.toString();// 内容
|
||||
|
||||
System.out.println(strcont);
|
||||
return Result.success(strcont);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 事件模板分页查询接口
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("tamplate")
|
||||
public JSONObject tamplate(){
|
||||
return shangTangService.template();
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -455,77 +455,6 @@ public class MonitorService {
|
|||
}
|
||||
}
|
||||
|
||||
//1.登录
|
||||
//2.获取token
|
||||
public String shangtangToken () {
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/tenant/token";
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("ksUserName","hisense");
|
||||
map.put("ksUserPassWord","Admin@2022");
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.postForEntity(url,map,JSONObject.class);
|
||||
JSONObject body = responseEntity.getBody();
|
||||
JSONObject data = body.getJSONObject("data");
|
||||
String token = data.getString("token");
|
||||
return token;
|
||||
} catch (Exception e) {
|
||||
log.info("[shangtangToken] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//订阅任务下发接口
|
||||
public JSONObject subscribe(){
|
||||
String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/subscribe";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
|
||||
headers.add("token", token);
|
||||
headers.add("tid","default");
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("callBackUrl","http://15.2.23.205:7009/api/project/subscribe");
|
||||
// map.put("certPubKey","");
|
||||
map.put("subscribeType",1);
|
||||
// map.put("taskId","serial");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url,HttpMethod.POST,new HttpEntity<>(map,headers),JSONObject.class);
|
||||
JSONObject body = responseEntity.getBody();
|
||||
return body;
|
||||
}catch (Exception e){
|
||||
log.info( "[subscribe] exception:{}",e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//事件模板分页查询接口
|
||||
public JSONObject template(){
|
||||
//String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("token","506eaf5d5d4a4cddb18f0370d906e22f");
|
||||
headers.add("tid","default");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url,HttpMethod.GET,new HttpEntity<>(headers),JSONObject.class);
|
||||
JSONObject jsonObject = responseEntity.getBody();
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
log.info("[template] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//查询视频点播巡检结果
|
||||
@Scheduled(cron="0 5 6 * * ?")
|
||||
public Result listChannelPlayStates(){
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
package com.hisense.monitormanage.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Log4j2
|
||||
public class ShangTangService {
|
||||
|
||||
@Autowired
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
//1.登录
|
||||
//2.获取token
|
||||
public String shangtangToken () {
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/tenant/token";
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("accessKey","a1ddCV7z7Jhv0SBGx5O3hblO");
|
||||
map.put("secretKey","glIixzORLgoFJz0VdF1aXICR");
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.postForEntity(url,map,JSONObject.class);
|
||||
JSONObject body = responseEntity.getBody();
|
||||
JSONObject data = body.getJSONObject("data");
|
||||
String token = data.getString("token");
|
||||
log.info("get token:{}", body.toJSONString());
|
||||
return token;
|
||||
} catch (Exception e) {
|
||||
log.info("[shangtangToken] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//订阅任务下发接口
|
||||
public JSONObject subscribe(){
|
||||
String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/subscribe";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
headers.add("token", token);
|
||||
headers.add("tid","default");
|
||||
|
||||
Map<String,Object> map = new HashMap<>();
|
||||
map.put("callBackUrl","http://15.2.23.205:7009/STapi/project/receive");
|
||||
// map.put("certPubKey","");
|
||||
map.put("subscribeType",3);
|
||||
// map.put("taskId","serial");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
HttpEntity<String> entity = new HttpEntity<>(JSONObject.toJSONString(map), headers);
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url, HttpMethod.POST,entity,JSONObject.class);
|
||||
JSONObject body = responseEntity.getBody();
|
||||
return body;
|
||||
}catch (Exception e){
|
||||
log.info( "[subscribe] exception:{}",e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//事件模板分页查询接口
|
||||
public JSONObject template(){
|
||||
String token = this.shangtangToken();
|
||||
String url = "http://10.132.191.54:10270/whale-open-api/scenario/event/template?pageNum=1&pageSize=1000";
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add("token",token);
|
||||
headers.add("tid","default");
|
||||
|
||||
ResponseEntity<JSONObject> responseEntity;
|
||||
try {
|
||||
responseEntity = restTemplate.exchange(url,HttpMethod.GET,new HttpEntity<>(headers),JSONObject.class);
|
||||
JSONObject jsonObject = responseEntity.getBody();
|
||||
return jsonObject;
|
||||
} catch (Exception e) {
|
||||
log.info("[template] exception:{}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue