diff --git a/pom.xml b/pom.xml
index 484fed3..c69a264 100644
--- a/pom.xml
+++ b/pom.xml
@@ -34,6 +34,7 @@
17
3.1.2
+ 2022.0.3
1.5.3.Final
@@ -135,6 +136,14 @@
springdoc-openapi-starter-webmvc-ui
${springdoc.version}
+
+
+ org.springframework.cloud
+ spring-cloud-dependencies
+ ${spring-cloud.version}
+ pom
+ import
+
diff --git a/zlmediakit-service/pom.xml b/zlmediakit-service/pom.xml
index f39755f..5227c5b 100644
--- a/zlmediakit-service/pom.xml
+++ b/zlmediakit-service/pom.xml
@@ -34,10 +34,10 @@
org.springframework.boot
spring-boot-starter-web
-
+
- org.springframework.boot
- spring-boot-starter-webflux
+ org.springframework.cloud
+ spring-cloud-starter-openfeign
diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ApiConfig.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ApiConfig.java
index 8c63b3d..92378b0 100644
--- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ApiConfig.java
+++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ApiConfig.java
@@ -1,11 +1,17 @@
package cn.skcks.docking.gb28181.media.dto.config;
+import feign.Param;
import lombok.Data;
@Data
public class ApiConfig {
+ @Param("api.apiDebug")
private Integer apiDebug;
+
+ @Param("api.secret")
private String secret;
+ @Param("api.defaultSnap")
private String defaultSnap;
+ @Param("api.snapRoot")
private String snapRoot;
}
diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ServerConfig.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ServerConfig.java
index 2837ffe..973158f 100644
--- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ServerConfig.java
+++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/config/ServerConfig.java
@@ -4,6 +4,7 @@ package cn.skcks.docking.gb28181.media.dto.config;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import lombok.Data;
+
@Data
public class ServerConfig {
@JsonUnwrapped(prefix = "api.")
diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/response/ZlmResponse.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/response/ZlmResponse.java
index 2ecfa06..0dd3cea 100644
--- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/response/ZlmResponse.java
+++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/dto/response/ZlmResponse.java
@@ -3,6 +3,7 @@ package cn.skcks.docking.gb28181.media.dto.response;
import cn.skcks.docking.gb28181.common.json.JsonResponse;
import cn.skcks.docking.gb28181.common.json.JsonUtils;
import cn.skcks.docking.gb28181.media.dto.status.ResponseStatus;
+import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
@@ -26,6 +27,7 @@ public class ZlmResponse {
return JsonUtils.toJson(this);
}
+ @JsonIgnore
public JsonResponse getJsonResponse(){
return ZlmResponseConvertor.INSTANCE.toJsonResponse(this);
}
diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java
new file mode 100644
index 0000000..620ba12
--- /dev/null
+++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpClient.java
@@ -0,0 +1,29 @@
+package cn.skcks.docking.gb28181.media.proxy;
+
+import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
+import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.cloud.openfeign.SpringQueryMap;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.service.annotation.HttpExchange;
+
+import java.util.List;
+import java.util.Map;
+
+@FeignClient(name="zlmMediaServerProxy",url = "${media.url}")
+@HttpExchange
+public interface ZlmMediaHttpClient {
+ @GetMapping("/index/api/getApiList")
+ ZlmResponse> getApiList(@RequestParam String secret);
+
+ @GetMapping("/index/api/getServerConfig")
+ ZlmResponse> getServerConfig(@RequestParam String secret);
+
+ @GetMapping("/index/api/getServerConfig")
+ ResponseEntity getServerConfigResponseEntity(@RequestParam String secret);
+
+ @GetMapping("/index/api/setServerConfig")
+ String setServerConfig(@RequestParam String secret, @SpringQueryMap Map config);
+}
diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpService.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpService.java
index 39e195e..4c5c1c7 100644
--- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpService.java
+++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmMediaHttpService.java
@@ -1,20 +1,36 @@
package cn.skcks.docking.gb28181.media.proxy;
+import cn.skcks.docking.gb28181.common.json.JsonUtils;
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
+import com.fasterxml.jackson.core.type.TypeReference;
+import lombok.Builder;
import org.springframework.http.ResponseEntity;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.service.annotation.GetExchange;
-import org.springframework.web.service.annotation.HttpExchange;
import java.util.List;
+import java.util.Map;
-@HttpExchange
-public interface ZlmMediaHttpService {
+@Builder
+public class ZlmMediaHttpService {
+ private String secret;
+ private ZlmMediaHttpClient exchange;
- @GetExchange("/index/api/getServerConfig")
- ZlmResponse> getServerConfig(@RequestParam String secret);
+ public ZlmResponse> getApiList() {
+ return exchange.getApiList(secret);
+ }
- @GetExchange("/index/api/getServerConfig")
- ResponseEntity getServerConfigResponseEntity(@RequestParam String secret);
+
+ public ZlmResponse> getServerConfig() {
+ return exchange.getServerConfig(secret);
+ }
+
+
+ public ResponseEntity getServerConfigResponseEntity() {
+ return exchange.getServerConfigResponseEntity(secret);
+ }
+
+ public String setServerConfig(ServerConfig config){
+ Map map = JsonUtils.mapper.convertValue(config, new TypeReference<>() {});
+ return exchange.setServerConfig(secret, map);
+ }
}
diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmProxy.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmProxy.java
index 7d7bd87..a375242 100644
--- a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmProxy.java
+++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/proxy/ZlmProxy.java
@@ -2,30 +2,20 @@ package cn.skcks.docking.gb28181.media.proxy;
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
import lombok.RequiredArgsConstructor;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
-import org.springframework.web.reactive.function.client.WebClient;
-import org.springframework.web.reactive.function.client.support.WebClientAdapter;
-import org.springframework.web.service.invoker.HttpServiceProxyFactory;
@RequiredArgsConstructor
@Component
public class ZlmProxy {
private final ZlmMediaConfig mediaConfig;
+ private final ZlmMediaHttpClient exchange;
@Bean
- public WebClient zlmClient() {
- return WebClient.builder()
- .baseUrl(mediaConfig.getUrl())
+ public ZlmMediaHttpService zlMediaHttpService(){
+ return ZlmMediaHttpService.builder()
+ .secret(mediaConfig.getSecret())
+ .exchange(exchange)
.build();
}
-
- @Bean
- public ZlmMediaHttpService zlMediaHttpService(@Qualifier("zlmClient") WebClient zlmClient){
- HttpServiceProxyFactory proxyFactory =
- HttpServiceProxyFactory.builder(WebClientAdapter.forClient(zlmClient))
- .build();
- return proxyFactory.createClient(ZlmMediaHttpService.class);
- }
}
diff --git a/zlmediakit-service/src/main/resources/application.yml b/zlmediakit-service/src/main/resources/application.yml
index 45a0fb7..77429eb 100644
--- a/zlmediakit-service/src/main/resources/application.yml
+++ b/zlmediakit-service/src/main/resources/application.yml
@@ -3,5 +3,6 @@ project:
media:
url: 'http://10.10.10.200:5080'
+# url: 'http://10.10.10.200:12580/anything/'
id: amrWMKmbKqoBjRQ9
secret: 4155cca6-2f9f-11ee-85e6-8de4ce2e7333
diff --git a/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/MediaTestApplication.java b/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/MediaTestApplication.java
index c2bbe89..d38a009 100644
--- a/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/MediaTestApplication.java
+++ b/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/MediaTestApplication.java
@@ -3,7 +3,9 @@ package cn.skcks.docking.gb28181;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.cloud.openfeign.EnableFeignClients;
+@EnableFeignClients
@SpringBootApplication
public class MediaTestApplication {
public static void main(String[] args) {
diff --git a/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java b/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java
index 78c9b9a..aa06858 100644
--- a/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java
+++ b/zlmediakit-service/src/test/java/cn/skcks/docking/gb28181/test/MediaServiceTest.java
@@ -4,11 +4,15 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.date.ZoneUtil;
import cn.skcks.docking.gb28181.common.json.JsonResponse;
+import cn.skcks.docking.gb28181.common.json.JsonUtils;
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
+import cn.skcks.docking.gb28181.media.dto.config.ApiConfig;
import cn.skcks.docking.gb28181.media.dto.config.ServerConfig;
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse;
import cn.skcks.docking.gb28181.media.dto.response.ZlmResponseConvertor;
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaHttpService;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
@@ -30,27 +34,9 @@ import java.util.*;
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@ExtendWith(SpringExtension.class)
public class MediaServiceTest {
- @Autowired
- private ZlmMediaConfig config;
-
@Autowired
private ZlmMediaHttpService zlMediaHttpService;
- @Test
- void context(){
- String secret = config.getSecret();
- ResponseEntity entity = zlMediaHttpService.getServerConfigResponseEntity(secret);
- log.info("{}", entity.getBody());
-
- ZlmResponse> test = zlMediaHttpService.getServerConfig(secret);
- JsonResponse> jsonResponse = test.getJsonResponse();
- log.info("{}", jsonResponse);
-
- ZlmResponse> zlmResponse = ZlmResponseConvertor.INSTANCE.toZlmResponse(jsonResponse);
- log.info("{}", zlmResponse);
- log.info("{}", zlmResponse.getCode().getMsg());
- }
-
@Test
void test(){
long unix = 1692346604L;
@@ -64,4 +50,30 @@ public class MediaServiceTest {
log.info("{}", LocalDateTimeUtil.of(instant, TimeZone.getTimeZone("GMT+8")));
log.info("{}", LocalDateTime.ofEpochSecond(unix, 0, ZoneOffset.ofHours(8)));
}
+
+ @Test
+ void context(){
+ ResponseEntity entity = zlMediaHttpService.getServerConfigResponseEntity();
+ log.info("{}", entity.getBody());
+
+ ZlmResponse> test = zlMediaHttpService.getServerConfig();
+ JsonResponse> jsonResponse = test.getJsonResponse();
+ log.info("{}", jsonResponse);
+
+ ZlmResponse> zlmResponse = ZlmResponseConvertor.INSTANCE.toZlmResponse(jsonResponse);
+ log.info("{}", zlmResponse);
+ log.info("{}", zlmResponse.getCode().getMsg());
+ }
+
+ @Test
+ void testApi(){
+ log.info("{}",zlMediaHttpService.getApiList());
+ }
+
+ @Test
+ void httpBinTest(){
+ ZlmResponse> resp = zlMediaHttpService.getServerConfig();
+ ServerConfig config = resp.getData().get(0);
+ log.info("{}", zlMediaHttpService.setServerConfig(config));
+ }
}