package com.zy.common.utils;
|
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONObject;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
|
@Component
|
public class HikUtils {
|
|
@Value("${zyHikUrl}")
|
private String hikUrl;
|
|
public void startPic(String ip, String filename) {
|
try {
|
if (hikUrl == null || "".equals(hikUrl)) {
|
News.error("hikUrl配置为空,无法进行拍摄");
|
return;
|
}
|
if (ip == null || "".equals(ip)) {
|
News.error("IP地址为空,无法进行拍摄");
|
return;
|
}
|
if (filename == null || "".equals(filename)) {
|
News.error("文件名为空,无法进行拍摄");
|
return;
|
}
|
HashMap<String, Object> data = new HashMap<>();
|
data.put("ip", ip);
|
data.put("filename", filename);
|
|
String response = new HttpHandler.Builder()
|
.setUri(hikUrl)
|
.setPath("/capture")
|
.setJson(JSON.toJSONString(data))
|
.build()
|
.doPost();
|
if (response == null || "".equals(response)) {
|
News.error("请求接口失败,返回值为空");
|
return;
|
}
|
JSONObject jsonObject = JSON.parseObject(response);
|
if (jsonObject == null) {
|
News.error("解析响应失败,返回值不是有效的JSON");
|
return;
|
}
|
Boolean success = jsonObject.getBoolean("success");
|
if (success != null && success) {
|
News.error("请求接口成功!!!url:{};request:{};response:{}", hikUrl + "/capture", JSON.toJSONString(data), response);
|
} else {
|
News.error("请求接口失败!!!url:{};request:{};response:{}", hikUrl + "/capture", JSON.toJSONString(data), response);
|
}
|
} catch (Exception e) {
|
News.error("拍摄失败:{}", e.getMessage());
|
e.printStackTrace();
|
}
|
}
|
|
}
|