diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/feign/IgnoreHttpsSSLClient.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/feign/IgnoreHttpsSSLClient.java new file mode 100644 index 0000000..07ddac0 --- /dev/null +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/feign/IgnoreHttpsSSLClient.java @@ -0,0 +1,41 @@ +package cn.skcks.docking.gb28181.media.feign; + +import feign.Client; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.security.cert.CertificateException; +import java.security.cert.X509Certificate; + +@Configuration +public class IgnoreHttpsSSLClient { + @Bean + @ConditionalOnMissingBean + public Client feignClient() { + try { + SSLContext ctx = SSLContext.getInstance("SSL"); + X509TrustManager tm = new X509TrustManager() { + @Override + public void checkClientTrusted(X509Certificate[] chain,String authType) throws CertificateException { + } + + @Override + public void checkServerTrusted(X509Certificate[] chain,String authType) throws CertificateException { + } + + @Override + public X509Certificate[] getAcceptedIssuers() { + return null; + } + }; + ctx.init(null, new TrustManager[]{tm}, null); + return new Client.Default(ctx.getSocketFactory(), (hostname, session) -> true); + } catch (Exception e) { + return null; + } + } +} \ No newline at end of file diff --git a/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/feign/IgnoreSSLFeignClientConfig.java b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/feign/IgnoreSSLFeignClientConfig.java new file mode 100644 index 0000000..17f12c1 --- /dev/null +++ b/zlmediakit-service/src/main/java/cn/skcks/docking/gb28181/media/feign/IgnoreSSLFeignClientConfig.java @@ -0,0 +1,15 @@ +package cn.skcks.docking.gb28181.media.feign; + +import feign.Client; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.context.annotation.Bean; + +public class IgnoreSSLFeignClientConfig { + + // 加载自定义Client + @Bean + @ConditionalOnBean(IgnoreHttpsSSLClient.class) + public Client generateClient(IgnoreHttpsSSLClient ignoreHttpsSSLClient) { + return ignoreHttpsSSLClient.feignClient(); + } +} \ No newline at end of file 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 index 4ee1e44..0ff458d 100644 --- 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 @@ -8,6 +8,7 @@ import cn.skcks.docking.gb28181.media.dto.response.ZlmResponse; import cn.skcks.docking.gb28181.media.dto.rtp.*; import cn.skcks.docking.gb28181.media.dto.snap.Snap; import cn.skcks.docking.gb28181.media.dto.version.VersionResp; +import cn.skcks.docking.gb28181.media.feign.IgnoreSSLFeignClientConfig; import org.springframework.cloud.openfeign.FeignClient; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -17,7 +18,7 @@ import org.springframework.web.bind.annotation.RequestParam; import java.util.List; -@FeignClient(name="zlmMediaServerProxy", url = "${media.url}") +@FeignClient(name="zlmMediaServerProxy", url = "${media.url}", configuration = IgnoreSSLFeignClientConfig.class) public interface ZlmMediaHttpClient { @GetMapping("/index/api/getApiList") ZlmResponse> getApiList(@RequestParam String secret);