package org.jeecg.modules.flow.controller.delete;
import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson.JSONObject;
import com.xkcoding.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class LiveQingTest {
static final String api = "http://192.168.70.158:28000";
static final String deviceId = "15WbDL1SR123";
private static String login() {
String username = "admin", password = SecureUtil.md5("mima"), token = "";
try {
String result = HttpUtil.get(api + "/api/v1/login?username=" + username + "&password=" + password);
log.info(result);
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getInteger("code") == 200) {
JSONObject dataJson = jsonObject.getJSONObject("data");
token = dataJson.getString("token");
}
} catch (Exception exception) {
log.error(exception.getLocalizedMessage());
}
return token;
}
private static String getDeviceState(String deviceId) {
String type = null;
String result = HttpUtil.get(api + "/api/v1/live/state?id=" + deviceId);
log.info(result);
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getInteger("code") == 200) {
JSONObject dataJson = jsonObject.getJSONObject("data");
type = dataJson.getString("type");
}
return type;
}
private static JSONObject getLiveList(String token, String state) {
String result = HttpUtil.get(api + "/api/v1/live/list?state=" + state + "&start=0&limit=100&token=" + token);
log.info(result);
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.getInteger("code") == 200) {
JSONObject dataJson = jsonObject.getJSONObject("data");
log.info(dataJson.toJSONString());
return dataJson;
}
return null;
}
private static String getM3u8Url(String deviceId, String starttime, String endtime) {
String videoUrl = api + "/api/v1/record/video/hls/" + deviceId + "/" + starttime + "/" + endtime + "/video.m3u8";
String result = HttpUtil.get(videoUrl);
log.info(videoUrl);
return videoUrl;
}
private static String getMp4Url(String deviceId, String starttime, String endtime) {
System.out.println(DateUtil.now());
String videoUrl = api + "/api/v1/record/video/play/" + deviceId + "/" + starttime + "/" + endtime + "/video.mp4";
String result = HttpUtil.get(videoUrl);
log.info(videoUrl);
System.out.println(DateUtil.now());
return videoUrl;
}
public static void main(String[] args) {
try {
String starttime = "20240322154500", endtime = "20240322154600";
String mpuUrl = getMp4Url(deviceId, starttime, endtime);
} catch (Exception e) {
log.error(e.getMessage());
}
}
}
``