简单测试

This commit is contained in:
shikong 2023-09-08 17:20:08 +08:00
parent 55de64069b
commit 2641b866be
3 changed files with 69 additions and 6 deletions

View File

@ -2,8 +2,8 @@ package cn.skcks.docking.gb28181.wvp.api.video;
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
import cn.skcks.docking.gb28181.wvp.config.SwaggerConfig;
import cn.skcks.docking.gb28181.wvp.service.download.DownloadService;
import cn.skcks.docking.gb28181.wvp.service.video.RecordService;
import cn.skcks.docking.gb28181.wvp.service.wvp.WvpService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
@ -26,7 +26,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
public class VideoController {
private final ZlmMediaConfig config;
private final RecordService recordService;
private final DownloadService downloadService;
private final WvpService wvpService;
@Bean
public GroupedOpenApi videoApi() {
@ -37,9 +37,6 @@ public class VideoController {
@GetMapping(produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@ResponseBody
public void video(HttpServletRequest request, HttpServletResponse response) {
// String url = StringUtils.joinWith("/", config.getUrl(), "live", "test.live.flv");
// log.info("url {}", url);
// recordService.record(request,response,url,15);
downloadService.download(request,response,"http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
wvpService.video(request,response);
}
}

View File

@ -177,6 +177,13 @@
<groupId>io.github.openfeign</groupId>
<artifactId>feign-httpclient</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>32.1.2-jre</version>
</dependency>
</dependencies>
<build>

View File

@ -0,0 +1,59 @@
package cn.skcks.docking.gb28181.wvp.service.wvp;
import cn.hutool.crypto.digest.MD5;
import cn.skcks.docking.gb28181.common.json.JsonResponse;
import cn.skcks.docking.gb28181.wvp.config.WvpProxyConfig;
import cn.skcks.docking.gb28181.wvp.dto.login.WvpLoginReq;
import cn.skcks.docking.gb28181.wvp.dto.login.WvpLoginResp;
import cn.skcks.docking.gb28181.wvp.proxy.WvpProxyClient;
import cn.skcks.docking.gb28181.wvp.service.download.DownloadService;
import com.github.rholder.retry.Retryer;
import com.github.rholder.retry.RetryerBuilder;
import com.github.rholder.retry.StopStrategies;
import com.github.rholder.retry.WaitStrategies;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@Slf4j
@Service
@RequiredArgsConstructor
public class WvpService {
private final WvpProxyClient wvpProxyClient;
private final WvpProxyConfig wvpProxyConfig;
private final DownloadService downloadService;
@SneakyThrows
public void video(HttpServletRequest request, HttpServletResponse response) {
Retryer<JsonResponse<?>> retryer = RetryerBuilder.<JsonResponse<?>>newBuilder()
// 异常就重试
.retryIfException()
// 重试间隔
.withWaitStrategy(WaitStrategies.fixedWait(5, TimeUnit.SECONDS))
// 重试次数
.withStopStrategy(StopStrategies.stopAfterAttempt(5))
.retryIfResult(result -> result == null || (result.getCode() != 0 && result.getCode() != 200))
.build();
String passwdMd5 = MD5.create().digestHex(wvpProxyConfig.getPasswd());
WvpLoginReq loginReq = WvpLoginReq.builder()
.username(wvpProxyConfig.getUser())
.password(passwdMd5)
.build();
retryer.call(()->{
JsonResponse<WvpLoginResp> login = wvpProxyClient.login(loginReq);
String accessToken = login.getData().getAccessToken();
log.info("wvp 登录成功 accessToken => {}", accessToken);
downloadService.download(request,response,"http://192.168.1.241:18979/download/recordTemp/0490d767d94ce20aedce57c862b6bfe9/rtp/59777645.mp4");
return login;
});
}
}