liubing 3 роки тому
батько
коміт
c4a2692b61

+ 27 - 6
common/common-util/src/main/java/com/yihu/jw/util/http/HttpClientUtil.java

@ -595,10 +595,31 @@ public class HttpClientUtil {
        return response;
    }
//    public static void main(String[] args) {
//        MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
//        org.springframework.http.HttpEntity<JSONObject> response = aqgCookieHttp("http://api.aiqiangua.com:8888/api/device/868219010321351",null,HttpMethod.GET,
//                "user=2|1:0|10:1620279813|4:user|16:MTM1NTk0ODUyNzA=|9d8d1403e854d37b551b57c9e53581b2ba7c491ba394a2b3a1b83f4ebc3c2d34");
//        System.out.println(response.getBody().toString());
//    }
    public  org.springframework.http.HttpEntity<JSONObject> assesTokenPostHttp(String url, JSONObject params,HttpMethod method){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType(MediaType.APPLICATION_JSON_VALUE);
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<String> request = new org.springframework.http.HttpEntity<>(params.toString(), headers);
        org.springframework.http.HttpEntity<JSONObject> response = restTemplate.exchange(url, method, request, JSONObject.class);
        return response;
    }
    public  org.springframework.http.HttpEntity<JSONObject> iotAssesTokenPostHttp(String url, MultiValueMap<String, String> params,HttpMethod method){
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType(MediaType.APPLICATION_FORM_URLENCODED_VALUE);
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<MultiValueMap<String, String>> request = new org.springframework.http.HttpEntity<>(params, headers);
        org.springframework.http.HttpEntity<JSONObject> response = restTemplate.exchange(url, method, request, JSONObject.class);
        return response;
    }
    public static void main(String[] args)  {
    }
}

+ 5 - 0
svr/svr-cloud-device/pom.xml

@ -140,6 +140,11 @@
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-ext-jdk16</artifactId>
            <version>1.46</version>
        </dependency>
    </dependencies>

+ 97 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/common/BaseController.java

@ -0,0 +1,97 @@
package com.yihu.jw.care.common;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.util.date.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 *
 */
public class BaseController {
    private static Logger logger = LoggerFactory.getLogger("error_logger");
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @return
     */
    public String error(int code, String msg) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("code", code);
            map.put("msg", msg);
            map.put("success", false);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 接口处理成功
     * @return
     */
    public String success() {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("code", 200);
            map.put("success", true);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    public String write(int code, String msg) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("code", code);
            map.put("msg", msg);
            map.put("success", true);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    /**
     * 返回接口处理结果
     *
     * @param code  结果码,成功为200
     * @param msg   结果提示信息
     * @param value 结果数据
     * @return
     */
    public String write(int code, String msg, String key, Object value) {
        try {
            Map<Object, Object> map = new HashMap<Object, Object>();
            ObjectMapper mapper = new ObjectMapper();
            map.put("code", code);
            map.put("msg", msg);
            map.put(key, value);
            return mapper.writeValueAsString(map);
        } catch (Exception e) {
            error(e);
            return error(-1, "服务器异常,请稍候再试!");
        }
    }
    public void error(Exception e) {
        logger.error(DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm:ss")+":"+getClass().getName() + ":", e.getMessage());
        e.printStackTrace();
    }
}

+ 77 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/config/YsConfig.java

@ -0,0 +1,77 @@
package com.yihu.jw.care.config;
/**
 * Created by Bing on 2021/6/1.
 * 萤石摄像头配置
 */
public class YsConfig {
    //文档地址 https://www.yuque.com/u1400669/kb/lmfp6u
    public static final String AppKey="43e44c2071114743925eda34088045f8";
    public static final String Secret="82051725cf0547208f8bc8ae2bff1323";
    public static final String baseUrl = "https://esopen.ys7.com";
    public static final String iotBaseUrl = "https://open.ys7.com";
   //saas平台 https://www.yuque.com/u1400669/kb/wdvi3b#9ZP70
    public static final String saasAssesToken =baseUrl+ "/api/user/open-app/auth/gettoken";
    //开放平台  https://open.ys7.com/doc/zh/book/index/user.html
    public static final String iotAssesToken =baseUrl+ "/api/user/component-open/sso/oauth2/getEZAccessToken";
    //获取通道列表
    public static final String surveillanceWayList =baseUrl+ "/api/resource/open-app/surveillance/camera/list/page";
    //获取通道信息(通道默认为1)
    public static final String surveillanceWay =baseUrl+ "/api/resource/open-app/surveillance/camera/info";
    //获取设备直播解密id(不清楚作用)
    public static final String surveillanceWayAddress = baseUrl+ "/api/resource/open-app/live/address/get";
    //获取设备有效直播地址
    public static final String getDeviceLiveAddress = iotBaseUrl+ "/api/lapp/live/address/limited";
    //设备视频加解密开关
    public static final String deviceEncrypt = baseUrl+ "/api/resource/device/encrypt/switch";
    //跌倒检测功能查询、设置(立即检测!判断是否有跌倒通过推送消息)
    public static final String deviceFailConfig = iotBaseUrl + "/api/route/device/devconfig/keyValue/{0}/{1}/op";
    //云台控制
    public static final String ptzStart = iotBaseUrl +"/api/lapp/device/ptz/start";
    //云台停止
    public static final String ptzStop = iotBaseUrl +"/api/lapp/device/ptz/stop";
    /**
     * 录像相关
     */
    //获取录像accessKey、上传录像地址
    public static final String videoKey = baseUrl +"/seastart/vod/token";
    //上传录像上传地址通过videoKey接口获取
    public static final String videoUpload = "https://seastart.ss.bscstorage.com";
    //录像列表
    public static final String videoList = baseUrl +"/seastart/vod/list";
    //录像详情
    public static final String videoDetail = baseUrl +"/seastart/vod/get";
    //批量获取录像详情
    public static final String videoDetailList = baseUrl +"/seastart/vod";
    public static final String redisKey = "ysAssesToken";
    public static final String iotRedisKey = "iotYsAssesToken";
    public static final String secretKey = "secretKey"; //设备的解密秘钥  通过iotAssesToken接口获取的
    public static final String msgDataKey = "HZADP68PNSNVZ4UW"; //消息解密密钥
}

+ 254 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/endpoint/YsDeviceController.java

@ -0,0 +1,254 @@
package com.yihu.jw.care.endpoint;
import com.alibaba.fastjson.JSON;
import com.yihu.jw.care.common.BaseController;
import com.yihu.jw.care.service.YsDeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
 * Created by Bing on 2021/6/1.
 */
@RestController
@RequestMapping("ys/device")
@Api(value = "萤石设备设备相关服务", description = "设备相关服务")
public class YsDeviceController  extends BaseController {
    private static org.slf4j.Logger logger = LoggerFactory.getLogger(YsDeviceController.class);
    @Autowired
    private YsDeviceService ysDeviceService;
    @ApiOperation("萤石摄像机消息通知数据接收")
    @RequestMapping(value = "pushdata", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String pushdata(
            HttpServletRequest request) {
        try {
            StringBuilder sb = new StringBuilder();
            BufferedReader in=new BufferedReader(new InputStreamReader(request.getInputStream(),"UTF-8"));
            String line = null;
            while ((line = in.readLine()) != null) {
                sb.append(line);
            }
            return write(200,"查询成功","data",ysDeviceService.pushdata(sb.toString(),request));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("摄像机通道详情")
    @RequestMapping(value = "surveillanceWay", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String surveillanceWay(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String deviceSerial,
            @ApiParam(name="channelNo",required = false,value="设备通道号,默认为1")
            @RequestParam(value = "channelNo",required = false,defaultValue = "1") Integer channelNo,
            @ApiParam(name="isTrust",required = false,value="是否托管设备:0-非托管,1-托管,默认0")
            @RequestParam(value = "isTrust",required = false,defaultValue = "0") Integer isTrust,
            HttpServletRequest request) {
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("萤石摄像机获取通道详情,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.surveillanceWay(deviceSerial,channelNo,isTrust,request));
        } catch (Exception e) {
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("获取摄像头直播加密Id")
    @RequestMapping(value = "surveillanceWayAddress", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String surveillanceWayAddress(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String[] deviceSerial,
            @ApiParam(name="channelNo",required = false,value="设备通道号,默认为1")
            @RequestParam(value = "channelNo",required = false,defaultValue = "1") Integer channelNo,
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("萤石摄像机获取直播加密Id,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.surveillanceWayAddress(deviceSerial,channelNo,request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("跌倒检测")
    @RequestMapping(value = "deviceFailConfig", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String surveillanceWayAddress(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String deviceSerial,
            @ApiParam(name="type",required = false,value="0-人或车检测,1-人形检测,2-车检测,3-画面变化检测,4-人脸检测,5-智能人体检测,6-宠物检测,7-跌倒检测")
            @RequestParam(value = "type",required = false) Integer type,
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("跌倒检测,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.deviceFailConfig(deviceSerial,type,request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("视频加解密")
    @RequestMapping(value = "deviceEncrypt", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String deviceEncrypt(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String deviceSerial,
            @ApiParam(name="isEncrypt",required = true,value="0-关闭,1-开启")
            @RequestParam(value = "isEncrypt",required = true) Integer isEncrypt,
            @ApiParam(name="validateCode",required = false,value="设备验证码,当isEncrypt=0时,需要传递此参数")
            @RequestParam(value = "validateCode",required = false) String validateCode,
            HttpServletRequest request){
        try {
            if (0==isEncrypt&& StringUtils.isBlank(validateCode)){
                return error(-1,"参数错误");
            }
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("视频加解密开关,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.deviceEncrypt(deviceSerial,isEncrypt,validateCode,request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("设备有效直播地址")
    @RequestMapping(value = "getDeviceLiveAddress", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String getDeviceLiveAddress(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String deviceSerial,
            @ApiParam(name="channelNo",required = true,value="通道号,IPC设备填1")
            @RequestParam(value = "channelNo",required = true) Integer channelNo,
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("获取设备有效直播地址,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.getDeviceLiveAddress(deviceSerial,channelNo,request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("设备云台控制开始")//操作后都需要调用停止接口 才会停止转动
    @RequestMapping(value = "ptzStart", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String ptzStart(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String deviceSerial,
            @ApiParam(name="channelNo",required = true,value="通道号,IPC设备填1")
            @RequestParam(value = "channelNo",required = true) Integer channelNo,
            @ApiParam(name="direction",required = true,value="0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距")
            @RequestParam(value = "direction",required = true) Integer direction,
            @ApiParam(name="speed",required = true,value="云台速度:0-慢,1-适中,2-快,海康设备参数不可为0")
            @RequestParam(value = "speed",required = true) Integer speed,
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("设备云台控制开始,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.ptzStart(deviceSerial,channelNo,direction,speed,request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("设备云台控制结束")
    @RequestMapping(value = "ptzStop", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String ptzStop(
            @ApiParam(name="deviceSerial",required = true,value="设备序列号")
            @RequestParam(value = "deviceSerial",required = true) String deviceSerial,
            @ApiParam(name="channelNo",required = true,value="通道号,IPC设备填1")
            @RequestParam(value = "channelNo",required = true) Integer channelNo,
            @ApiParam(name="direction",required = true,value="0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距")
            @RequestParam(value = "direction",required = true) Integer direction,
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("设备云台控制结束,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.ptzStop(deviceSerial,channelNo,direction,request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("获取录像accessToken")
    @RequestMapping(value = "getVideoKey", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String getVideoKey(
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("获取录像accessToken,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.getVideoKey(request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("上传录像")
    @RequestMapping(value = "videoUpload", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String videoUpload(
            HttpServletRequest request,
            @ApiParam(value = "文件", required = true)
            @RequestParam(value = "file", required = true) MultipartFile file){
        try {
            String originalFilename = file.getOriginalFilename();
            InputStream inputStream = file.getInputStream();
            return write(200,"查询成功","data",ysDeviceService.videoUpload(request));
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
    @ApiOperation("查询录像列表")
    @RequestMapping(value = "videoList", produces = "application/x-www-form-urlencoded;charset=UTF-8", method = {RequestMethod.POST,RequestMethod.GET})
    public String videoList(
            HttpServletRequest request){
        try {
            String paraString = JSON.toJSONString(request.getParameterMap());
            logger.info("查询录像列表,请求参数:\n"+paraString);
            return write(200,"查询成功","data",ysDeviceService.videoList());
        }catch (Exception e){
            e.printStackTrace();
            return error(-1,"error");
        }
    }
}

Різницю між файлами не показано, бо вона завелика
+ 532 - 0
svr/svr-cloud-device/src/main/java/com/yihu/jw/care/service/YsDeviceService.java