Procházet zdrojové kódy

河图视频接口接入

yangyue před 1 rokem
rodič
revize
8beaa3b3ac

+ 4 - 29
pom.xml

@@ -2,6 +2,10 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
+    <packaging>pom</packaging>
+    <modules>
+        <module>video</module>
+    </modules>
     <parent>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-parent</artifactId>
@@ -35,15 +39,6 @@
             <version>1.18.20</version>
         </dependency>
 
-
-        <dependency>
-            <groupId>cn.com.taiji</groupId>
-            <artifactId>apione-http-client</artifactId>
-            <version>1.0.0-SNAPSHOT</version>
-            <scope>system</scope>
-            <systemPath>${basedir}/src/main/resources/lib/apione-http-client-1.0.0-SNAPSHOT.jar</systemPath>
-        </dependency>
-
         <!-- 海康SDK -->
         <dependency>
             <groupId>com.hikvision.ga</groupId>
@@ -79,28 +74,8 @@
             <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
-                <configuration>
-                    <!--fork:设置True,否则可能devtools不会起作用-->
-                    <fork>true</fork>
-                    <!-- 指定该Main Class为全局的唯一入口 -->
-                    <mainClass>cn.com.taiji.dataService.DataServiceApplication</mainClass>
-                    <layout>ZIP</layout>
-                </configuration>
-                <executions>
-                    <execution>
-                        <goals>
-                            <goal>repackage</goal>
-                        </goals>
-                    </execution>
-                </executions>
             </plugin>
         </plugins>
-        <resources>
-            <resource>
-                <directory>src/main/resources</directory>
-                <filtering>true</filtering>
-            </resource>
-        </resources>
     </build>
 
 </project>

+ 0 - 30
src/main/java/cn/com/taiji/dataService/cotroller/TestController.java

@@ -1,30 +0,0 @@
-package cn.com.taiji.dataService.cotroller;
-
-
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
-import org.springframework.web.bind.annotation.RestController;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-
-
-@RestController
-public class TestController {
-
-    public static void main(String[] args) throws ParseException {
-        //闰年的情况
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH");
-        Date date = sdf.parse("2023-03-30 05");
-        DateTime targetTime = DateUtil.offsetMonth(date,-1);
-        Calendar calendar = Calendar.getInstance();
-        calendar.setTime(targetTime);
-        calendar.set(Calendar.DAY_OF_MONTH,calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
-        // calendar.add(Calendar.MONTH,1);
-        Date d2 = calendar.getTime();
-        System.out.println(sdf.format(targetTime)+"加一月:"+sdf.format(d2));
-
-    }
-}

+ 0 - 42
src/main/java/cn/com/taiji/dataService/cotroller/test006.java

@@ -1,42 +0,0 @@
-package cn.com.taiji.dataService.cotroller;
-
-import cn.com.digitalhainan.apione.sdk.ContentBody;
-import cn.com.digitalhainan.apione.sdk.HttpCaller;
-import cn.com.digitalhainan.apione.sdk.HttpParameters;
-import cn.com.digitalhainan.apione.sdk.HttpReturn;
-
-public class test006 {
-    public static void main(String[] args) {
-
-        //换成自己的ak、sk
-        String ak = "替换AK";
-        String sk = "替换SK";
-        String api = "替换API";
-
-        String region = "接口请求区域 INTRA(政务外网),INTER(政务互联网),PUBLIC(公网)";
-
-        String requestUrl = "https://api-one.digitalhainan.com.cn/apione";
-
-        //传参格式,根据不同的参数格式以不同的方式传参。
-        String contentJson = "{\"idNo\":\"460*****15\",\"name\":\"*****\"}";
-        ContentBody contentBody = new ContentBody(contentJson);
-
-        //拼装业务信息
-        HttpParameters parameters = HttpParameters.builder()
-                .api(api)
-                .region(region)
-                // 如果有query参数需要设置
-                //.queryParamsMap(query)
-                // 如果有path参数需要设置
-                //.path(path)
-                .accessKey(ak)
-                .secretKey(sk)
-                .contentBody(contentBody)
-                .requestUrl(requestUrl)
-                .build();
-
-        // 请求服务接口,获取response
-        HttpReturn call = HttpCaller.getInstance().call(parameters);
-        System.out.println(call);
-    }
-}

+ 0 - 43
src/main/java/cn/com/taiji/dataService/model/ProviewFetchingVO.java

@@ -1,43 +0,0 @@
-package cn.com.taiji.dataService.model;
-
-import lombok.Data;
-
-import java.io.Serializable;
-
-/**
- * @Description
- *
- * @Author  yangyue
- * @Date 2021/11/18
- */
-@Data
-public class ProviewFetchingVO implements Serializable {
-
-
-
-    /**
-     * 监控点编号(通用唯一识别码UUID)
-     */
-    private String  cameraIndexCode;
-
-    /**
-     * 码流类型(0-主码流,1-子码流),未填默认为主码流
-     */
-
-    private Integer streamType;
-
-    /**
-     * 协议类型(rtsp-rtsp协议,rtmp-rtmp协议,hls-hLS协议),未填写为rtsp协议
-     */
-    private String  protocol;
-
-    /**
-     * 协议类型( 0-udp,1-tcp),默认为tcp,在protocol设置为rtsp或者rtmp时有效
-     */
-    private Integer transmode;
-
-    /**
-     * 拓展字段(标准协议取流不需要扩展字段信息 )
-     */
-    private String expand;
-}

+ 0 - 20
src/main/java/cn/com/taiji/dataService/service/IProviewFetchingService.java

@@ -1,20 +0,0 @@
-// package cn.com.taiji.dataService.service;
-//
-//
-// import cn.com.taiji.dataService.model.ProviewFetchingVO;
-//
-// /**
-//  * @Description
-//  *
-//  * @Author  yangyue
-//  * @Date 2021/11/18
-//  */
-// public interface IProviewFetchingService {
-//     /**
-//      * 海康视频流地址
-//      * @param pre 海康入参
-//      * @return String
-//      */
-//     String httpsPost(ProviewFetchingVO pre);
-//
-// }

+ 0 - 48
src/main/java/cn/com/taiji/dataService/service/impl/PerviewFetchingServiceImpl.java

@@ -1,48 +0,0 @@
-// package cn.com.taiji.dataService.service.impl;
-//
-//
-// import cn.com.taiji.dataService.model.ProviewFetchingVO;
-// import cn.com.taiji.dataService.service.IProviewFetchingService;
-// 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.stereotype.Service;
-//
-// import java.util.HashMap;
-// import java.util.Map;
-//
-// /**
-//  * @Description
-//  *
-//  * @Author  yangyue
-//  * @Date 2021/11/18
-//  */
-// @Service
-// @Slf4j
-// public class PerviewFetchingServiceImpl implements IProviewFetchingService {
-//
-//     @Override
-//     public String httpsPost(ProviewFetchingVO pre) {
-//
-//         ArtemisConfig.host="74.10.28.97:443";
-//         ArtemisConfig.appKey="26491753";
-//         ArtemisConfig.appSecret="nSWbgqChFBSdGPSnb59i";
-//         final String artemispath = "/artemis";
-//         final String previewurlsapi = artemispath + "/api/video/v1/cameras/previewURLs";
-//
-//         Map<String, String> path = new HashMap<String, String>(2) {
-//             {
-//                 put("https://", previewurlsapi);//根据现场环境部署确认是http还是https
-//             }
-//         };
-//         String contentType = "application/json";
-//         String body = JSON.toJSONString(pre);
-//         // post请求application/json类型参数
-//         String result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null);
-//         log.info(result);
-//         JSONObject jsonObject = JSONObject.parseObject(result);
-//         return jsonObject.getJSONObject("data").getString("url");
-//     }
-// }

+ 0 - 76
src/main/java/cn/com/taiji/dataService/utils/AESUtils.java

@@ -1,76 +0,0 @@
-package cn.com.taiji.dataService.utils;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.crypto.Cipher;
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-import java.util.Base64;
-
-/**
- * Created by Kevin on 2018/6/21.
- */
-public class AESUtils {
-
-    static String iv = "d22b0a851e014f7b";
-
-    private final static Logger logger = LoggerFactory.getLogger(AESUtils.class);
-
-    private final static Base64.Encoder encoder = Base64.getEncoder();
-    private final static Base64.Decoder decoder = Base64.getDecoder();
-
-    private static final String defaultCharset = "UTF-8";
-    private static final String KEY_AES = "AES";
-    public static final String KEY = "8192553d3db81630";
-
-    /**
-     * 加密
-     *
-     * @param data 需要加密的内容
-     * @param key  加密密码
-     * @return
-     */
-    public static String encrypt(String data, String key) {
-        return doAES(data, key, iv.getBytes(), Cipher.ENCRYPT_MODE);
-    }
-
-    /**
-     * 解密
-     *
-     * @param data 待解密内容
-     * @param key  解密密钥
-     * @return
-     */
-    public static String decrypt(String data, String key) {
-        return doAES(data, key, iv.getBytes(), Cipher.DECRYPT_MODE);
-    }
-
-    public static String doAES(String data, String secretKey, byte[] iv, int mode) {
-
-        try {
-            boolean encrypt = mode == Cipher.ENCRYPT_MODE;
-            byte[] content;
-            //true 加密内容 false 解密内容
-            if (encrypt) {
-                content = data.getBytes(defaultCharset);
-            } else {
-                content = decoder.decode(data);
-            }
-
-            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
-            SecretKeySpec skeySpec = new SecretKeySpec(secretKey.getBytes(), KEY_AES);
-            cipher.init(mode, skeySpec, new IvParameterSpec(iv));
-            byte[] result = cipher.doFinal(content);
-            if (encrypt) {
-                return new String(encoder.encode(result));
-            } else {
-                return new String(result, defaultCharset);
-            }
-        } catch (Exception e) {
-            logger.error("aes error:", e);
-        }
-        return null;
-    }
-}
-

+ 0 - 2
src/main/resources/application.yml

@@ -1,2 +0,0 @@
-server:
-  port: 9000

binární
src/main/resources/lib/apione-http-client-1.0.0-SNAPSHOT.jar


+ 90 - 0
video/pom.xml

@@ -0,0 +1,90 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>data-service</artifactId>
+        <groupId>cn.com.taiji</groupId>
+        <version>1.0</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <artifactId>video</artifactId>
+
+    <properties>
+        <maven.compiler.source>8</maven.compiler.source>
+        <maven.compiler.target>8</maven.compiler.target>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-devtools</artifactId>
+            <scope>runtime</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+            <version>1.18.20</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.75</version>
+        </dependency>
+
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.6.6</version>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>utf-8</encoding>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <!--fork:设置True,否则可能devtools不会起作用-->
+                    <fork>true</fork>
+                    <!-- 指定该Main Class为全局的唯一入口 -->
+                    <mainClass>cn.com.taiji.video.VideoApplication</mainClass>
+                    <layout>ZIP</layout>
+                </configuration>
+                <executions>
+                    <execution>
+                        <goals>
+                            <goal>repackage</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+        <resources>
+            <resource>
+                <directory>src/main/resources</directory>
+                <filtering>true</filtering>
+            </resource>
+        </resources>
+    </build>
+
+</project>

+ 3 - 3
src/main/java/cn/com/taiji/dataService/DataServiceApplication.java

@@ -1,13 +1,13 @@
-package cn.com.taiji.dataService;
+package cn.com.taiji.video;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 
 @SpringBootApplication
-public class DataServiceApplication {
+public class VideoApplication {
 
     public static void main(String[] args) {
-        SpringApplication.run(DataServiceApplication.class, args);
+        SpringApplication.run(VideoApplication.class, args);
     }
 
 }

+ 21 - 0
video/src/main/java/cn/com/taiji/video/config/HttpClientConfig.java

@@ -0,0 +1,21 @@
+package cn.com.taiji.video.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * @Description
+ *
+ * @Author  yangyue
+ * @Date 2022/3/22
+ */
+@Configuration
+public class HttpClientConfig {
+
+    @Bean
+    public RestTemplate restTemplate(){
+        return new RestTemplate();
+    }
+
+}

+ 31 - 0
video/src/main/java/cn/com/taiji/video/cotroller/VideoUrlController.java

@@ -0,0 +1,31 @@
+package cn.com.taiji.video.cotroller;
+
+
+import cn.com.taiji.video.service.IVideoUrlService;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import javax.servlet.http.HttpServletResponse;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+
+@RestController
+@RequestMapping("video")
+public class VideoUrlController {
+
+    @Autowired
+    private IVideoUrlService urlService;
+
+    @GetMapping("url")
+    public List<Object> queryUrl(String number) {
+        return urlService.httpsPost(number);
+    }
+}

+ 35 - 0
video/src/main/java/cn/com/taiji/video/model/Token.java

@@ -0,0 +1,35 @@
+package cn.com.taiji.video.model;
+
+import com.alibaba.fastjson.annotation.JSONField;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @Description
+ *
+ * @Author  yangyue
+ * @Date 2021/11/18
+ */
+@Data
+public class Token implements Serializable {
+
+    /**
+     * 获取到的凭证
+     */
+    @JSONField(name = "access_token")
+    private String accessToken;
+
+    /**
+     * 凭证类型
+     */
+    @JSONField(name = "token_type")
+    private Integer tokenType;
+
+    /**
+     * 凭证有效时间
+     */
+    @JSONField(name = "expires_in")
+    private String expiresIn;
+
+}

+ 21 - 0
video/src/main/java/cn/com/taiji/video/service/IVideoUrlService.java

@@ -0,0 +1,21 @@
+package cn.com.taiji.video.service;
+
+
+import java.util.List;
+
+/**
+ * @Description
+ *
+ * @Author  yangyue
+ * @Date 2021/11/18
+ */
+public interface IVideoUrlService {
+
+    /**
+     * 查询视频流地址
+     * @param pre 海康入参
+     * @return List<Object>
+     */
+    List<Object> httpsPost(String pre);
+
+}

+ 71 - 0
video/src/main/java/cn/com/taiji/video/service/impl/VideoUrlServiceImpl.java

@@ -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;
+    }
+}

+ 2 - 0
video/src/main/resources/application.yml

@@ -0,0 +1,2 @@
+server:
+  port: 9009