608 lines
30 KiB
Java
608 lines
30 KiB
Java
package com.zhgd.xmgl.util;
|
||
|
||
import cn.hutool.http.HttpUtil;
|
||
import com.alibaba.fastjson.JSONArray;
|
||
import com.alibaba.fastjson.JSONObject;
|
||
import com.zhgd.jeecg.common.execption.OpenAlertException;
|
||
import com.zhgd.jeecg.common.util.JSONUtil;
|
||
import lombok.extern.slf4j.Slf4j;
|
||
import org.apache.commons.collections.MapUtils;
|
||
import org.apache.commons.lang3.StringUtils;
|
||
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* @program: wisdomSite
|
||
* @description: 萤石云视频接口
|
||
* @author: Mr.Peng
|
||
* @create: 2020-09-15 09:33
|
||
**/
|
||
@Slf4j
|
||
public class YsVideoUtil {
|
||
private static final String url = "https://open.ys7.com";
|
||
|
||
/**
|
||
* 获取token
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @return
|
||
*/
|
||
public static String getToken(String appKey, String appSecret) {
|
||
String accessToken = null;
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("appKey", appKey);
|
||
param.put("appSecret", appSecret);
|
||
String result = HttpUtil.post(url + "/api/lapp/token/get", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
Map<String, Object> map = JSONUtil.readValueToMap(object.get("data").toString());
|
||
accessToken = MapUtils.getString(map, "accessToken");
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("10017".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyNotExist"));
|
||
} else if ("10030".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("keyAndSecretMatchErr"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
return accessToken;
|
||
}
|
||
|
||
/**
|
||
* 添加设备
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial 设备序列号,存在英文字母的设备序列号,字母需为大写
|
||
* @param validateCode 设备验证码,设备机身上的六位大写字母
|
||
* @return
|
||
*/
|
||
public static boolean addVideo(String appKey, String appSecret, String deviceSerial, String validateCode, String accessToken) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
validateCode = validateCode.toUpperCase();
|
||
if (StringUtils.isEmpty(accessToken)) {
|
||
accessToken = getToken(appKey, appSecret);
|
||
}
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
param.put("validateCode", validateCode);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/add", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
boolean falg = openVideo(accessToken, deviceSerial);
|
||
if (falg) {
|
||
return true;
|
||
} else {
|
||
return false;
|
||
}
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20007".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotOnlineErr"));
|
||
} else if ("20010".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devVerificationErr"));
|
||
} else if ("20011".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devAddErr"));
|
||
} else if ("20013".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devOtherAddErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20017".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devOwnAddErr"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
public static boolean openVideo(String accessToken, String deviceSerial) {
|
||
boolean temp = false;
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("source", deviceSerial + ":1");
|
||
String result = HttpUtil.post(url + "/api/lapp/live/video/open", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
JSONArray jsonArray = object.getJSONArray("data");
|
||
Map<String, Object> map = JSONUtil.readValueToMap(jsonArray.get(0).toString());
|
||
code = MapUtils.getString(map, "ret");
|
||
if ("200".equals(code) || "60062".equals(code)) {
|
||
temp = true;
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10004".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("userNotExist"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("10017".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyNotExist"));
|
||
} else if ("10026".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevVersionLimitErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20007".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotOnlineErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20018".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("UserNotDevErr"));
|
||
} else if ("20032".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("userChannelNotExist"));
|
||
} else if ("60020".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("commandNotSupportErr"));
|
||
} else if ("60061".equals(code)) {
|
||
//throw new OpenAlertException(MessageUtil.get("devOwnAddErr"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
return temp;
|
||
}
|
||
|
||
/**
|
||
* 删除设备
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial 设备序列号,存在英文字母的设备序列号,字母需为大写
|
||
* @return
|
||
*/
|
||
public static boolean deleteVideo(String appKey, String appSecret, String deviceSerial, String accessToken) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
if (StringUtils.isEmpty(accessToken)) {
|
||
accessToken = getToken(appKey, appSecret);
|
||
}
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/delete", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
return true;
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20017".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devOwnAddErr"));
|
||
} else if ("20018".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("UserNotDevErr"));
|
||
} else if ("20031".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("closeClientErr"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 设备抓拍图片
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial 设备序列号,存在英文字母的设备序列号,字母需为大写
|
||
* @return
|
||
*/
|
||
public static String videoCapture(String appKey, String appSecret, String deviceSerial) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
String accessToken = getToken(appKey, appSecret);
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
//通道号,IPC设备填写1
|
||
param.put("channelNo", 1);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/capture", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
Map<String, Object> map = JSONUtil.readValueToMap(object.get("data").toString());
|
||
return MapUtils.getString(map, "picUrl");
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("10051".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("capturePermErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20006".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("NetworkErr"));
|
||
} else if ("20007".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotOnlineErr"));
|
||
} else if ("20008".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devResponseTimeOutErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20032".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("userChannelNotExist"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else if ("60017".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevCaptureFail"));
|
||
} else if ("60020".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("commandNotSupportErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 开始云台控制
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial 设备序列号,存在英文字母的设备序列号,字母需为大写
|
||
* @param direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距
|
||
* @param speed 云台速度:0-慢,1-适中,2-快,海康设备参数不可为0
|
||
* @return
|
||
*/
|
||
public static boolean videoStartPtz(String appKey, String appSecret, String deviceSerial, int direction, int speed) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
String accessToken = getToken(appKey, appSecret);
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
//通道号,IPC设备填写1
|
||
param.put("channelNo", 1);
|
||
param.put("direction", direction);
|
||
param.put("speed", speed);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/ptz/start", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
return true;
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20006".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("NetworkErr"));
|
||
} else if ("20007".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotOnlineErr"));
|
||
} else if ("20008".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devResponseTimeOutErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20032".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("userChannelNotExist"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else if ("60000".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevNotSupportPtzErr"));
|
||
} else if ("60001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("UserNotPermPtzErr"));
|
||
} else if ("60002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevPtzUpperLimitErr"));
|
||
} else if ("60003".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevPtzLowerLimitErr"));
|
||
} else if ("60004".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevPtzLeftLimitErr"));
|
||
} else if ("60005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevPtzRightLimitErr"));
|
||
} else if ("60006".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("ptzOperationFail"));
|
||
} else if ("60009".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("callPresetErr"));
|
||
} else if ("60020".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("commandNotSupportErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 停止云台控制
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial 设备序列号,存在英文字母的设备序列号,字母需为大写
|
||
* @param direction 操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距
|
||
* @return
|
||
*/
|
||
public static boolean videoStopPtz(String appKey, String appSecret, String deviceSerial, int direction) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
String accessToken = getToken(appKey, appSecret);
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
//通道号,IPC设备填写1
|
||
param.put("channelNo", 1);
|
||
param.put("direction", direction);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/ptz/stop", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
return true;
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20006".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("NetworkErr"));
|
||
} else if ("20007".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotOnlineErr"));
|
||
} else if ("20008".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devResponseTimeOutErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20032".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("userChannelNotExist"));
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else if ("60000".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevNotSupportPtzErr"));
|
||
} else if ("60001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("UserNotPermPtzErr"));
|
||
} else if ("60006".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("ptzOperationFail"));
|
||
} else if ("60009".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("callPresetErr"));
|
||
} else if ("60020".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("commandNotSupportErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取指定有效期的直播地址(该接口适用于已经开通过直播的用户)
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial
|
||
* @return
|
||
*/
|
||
public static Map<String, Object> getVideoUrl(String appKey, String appSecret, String deviceSerial, String accessToken) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
if (StringUtils.isEmpty(accessToken)) {
|
||
accessToken = getToken(appKey, appSecret);
|
||
}
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
//通道号,IPC设备填写1
|
||
param.put("channelNo", 1);
|
||
String result = HttpUtil.post(url + "/api/lapp/live/address/limited", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
Map<String, Object> map = JSONUtil.readValueToMap(object.get("data").toString());
|
||
return map;
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("10026".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("DevVersionLimitErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20007".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotOnlineErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20018".equals(code)) {
|
||
//throw new OpenAlertException(MessageUtil.get("UserNotDevErr"));
|
||
Map<String, Object> map = new HashMap<>(16);
|
||
return map;
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else if ("60060".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("addressBindErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
|
||
public static Map<String, Object> getVideoInfo(String appKey, String appSecret, String deviceSerial, String accessToken) {
|
||
deviceSerial = deviceSerial.toUpperCase();
|
||
if (StringUtils.isEmpty(accessToken)) {
|
||
accessToken = getToken(appKey, appSecret);
|
||
}
|
||
if (StringUtils.isNotEmpty(accessToken)) {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/info", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
Map<String, Object> map = JSONUtil.readValueToMap(object.get("data").toString());
|
||
return map;
|
||
} else if ("10001".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("paramErr"));
|
||
} else if ("10002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
} else if ("10005".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("appKeyErr"));
|
||
} else if ("20002".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devNotExistErr"));
|
||
} else if ("20014".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("devIllegalErr"));
|
||
} else if ("20018".equals(code)) {
|
||
//throw new OpenAlertException(MessageUtil.get("UserNotDevErr"));
|
||
Map<String, Object> map = new HashMap<>(16);
|
||
return map;
|
||
} else if ("49999".equals(code)) {
|
||
throw new OpenAlertException(MessageUtil.get("datadErr"));
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("failErr"));
|
||
}
|
||
|
||
} else {
|
||
throw new OpenAlertException(MessageUtil.get("tokenErr"));
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取监控状态,1在线,2离线
|
||
*
|
||
* @param appKey
|
||
* @param appSecret
|
||
* @param deviceSerial
|
||
* @param accessToken
|
||
* @return
|
||
*/
|
||
public static Integer getVideoStatus(String appKey, String appSecret, String deviceSerial, String accessToken) {
|
||
Integer status = 2;
|
||
try {
|
||
Map<String, Object> param = new HashMap<>(16);
|
||
param.put("accessToken", accessToken);
|
||
param.put("deviceSerial", deviceSerial);
|
||
String result = HttpUtil.post(url + "/api/lapp/device/info", param);
|
||
log.info(result);
|
||
if (result != null && result.length() > 0) {
|
||
JSONObject object = JSONObject.parseObject(result);
|
||
String code = String.valueOf(object.get("code").toString());
|
||
if ("200".equals(code)) {
|
||
Map<String, Object> map = JSONUtil.readValueToMap(object.get("data").toString());
|
||
if (map != null && map.containsKey("status") && "1".equals(MapUtils.getString(map, "status"))) {
|
||
status = 1;
|
||
}
|
||
}
|
||
}
|
||
} catch (Exception e) {
|
||
log.error("error:", e);
|
||
}
|
||
return status;
|
||
}
|
||
|
||
public static void main(String[] args) {
|
||
//String token=getToken("66b4fc1d6703468c8ee93b2919a3f20b","0a5836c68a7edabcc78e6a18f05bb317");
|
||
//log.info(token);
|
||
//boolean temp=addVideo("66b4fc1d6703468c8ee93b2919a3f20b","0a5836c68a7edabcc78e6a18f05bb317","C86695622","123456");
|
||
//log.info(temp);
|
||
//boolean a=openVideo("at.089ukfri42yxx6tc8yv5bnt231ybe6su-7p1yfgy6g8-1te4sjf-jz2mhxpul","C83204981");
|
||
//log.info(a);
|
||
Map<String, Object> a = getVideoInfo("66b4fc1d6703468c8ee93b2919a3f20b", "0a5836c68a7edabcc78e6a18f05bb317", "C83204981", null);
|
||
log.info(cn.hutool.json.JSONUtil.toJsonStr(a));
|
||
|
||
|
||
}
|
||
}
|