package com.securityControl.task.util.video; import com.securityControl.common.core.utils.aes.StringHelper; import com.securityControl.common.redis.service.RedisService; import com.securityControl.task.util.AesEncryptUtils; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.HashMap; import java.util.Map; @Component @Slf4j public class TVideoConfigUtil { /** * 登录平台地址 */ public static String IPADDRESS; /** * 平台端口 */ public static String PORT; /** * 账号 */ public static String USER; /** * 账号 */ public static String PASSWORD; /** * 请求地址 */ public static String Q2HTTPURL; public static String EPID ;// 登录平台企业ID public static int BFIX ;// 登录平台是否通过网闸模式 @Resource private RedisService redisService; @Value("${video.ip}") public void setIPADDRESS(String IPADDRESS) { TVideoConfigUtil.IPADDRESS = IPADDRESS; } @Value("${video.port}") public void setPORT(String PORT) { TVideoConfigUtil.PORT = PORT; } @Value("${video.name}") public void setUSER(String USER) { TVideoConfigUtil.USER = USER; } @Value("${video.key}") public void setPASSWORD(String PASSWORD) { TVideoConfigUtil.PASSWORD = PASSWORD; } @Value("${video.url}") public void setQ2HTTPURL(String q2HTTPURL) { TVideoConfigUtil.Q2HTTPURL = q2HTTPURL; } @Value("${video.epid}") public void setEPID(String EPID) { TVideoConfigUtil.EPID = EPID; } @Value("${video.bfix}") public void setBFIX(int BFIX) { TVideoConfigUtil.BFIX = BFIX; } public Map getMaps(){ Map params = new HashMap<>(16); Map map = new HashMap<>(16); try{ String ip= redisService.get("video","ip"); String port= redisService.get("video","port"); String user=redisService.get("video","user"); String key=redisService.get("video","pwd"); String bfix=redisService.get("video","bfix"); String epid=redisService.get("video","epid"); if(StringHelper.isEmpty(ip)){ map.put("address", TVideoConfigUtil.IPADDRESS); }else{ map.put("address",ip); } if(StringHelper.isEmpty(port)){ map.put("port", TVideoConfigUtil.PORT); }else{ map.put("port",port); } if(StringHelper.isEmpty(user)){ map.put("user", TVideoConfigUtil.USER); }else{ map.put("user",user); } if(StringHelper.isEmpty(key)){ map.put("password", TVideoConfigUtil.PASSWORD); }else{ map.put("password",key); } if(StringHelper.isEmpty(epid)){ map.put("epid", TVideoConfigUtil.EPID); }else{ map.put("epid",epid); } if(StringHelper.isEmpty(bfix)){ map.put("fixaddr", TVideoConfigUtil.BFIX); }else{ map.put("fixaddr",Integer.parseInt(bfix)); } String rucan="address="+map.get("address").toString()+"&port="+map.get("port").toString()+ "&user="+map.get("user").toString()+"&epid="+map.get("epid").toString()+ "&password="+map.get("password").toString()+"&fixaddr="+map.get("fixaddr").toString(); String data= AesEncryptUtils.encrypt(rucan, AesEncryptUtils.VIDEO_KEY); params.put("params",data); }catch (Exception e){ map.put("address", TVideoConfigUtil.IPADDRESS); map.put("port", TVideoConfigUtil.PORT); map.put("user", TVideoConfigUtil.USER); map.put("password", TVideoConfigUtil.PASSWORD); map.put("epid", TVideoConfigUtil.EPID); map.put("fixaddr", TVideoConfigUtil.BFIX); String rucan="address="+map.get("address").toString()+"&port="+map.get("port").toString()+ "&user="+map.get("user").toString()+"&epid="+map.get("epid").toString()+ "&password="+map.get("password").toString()+"&fixaddr="+map.get("fixaddr").toString(); String data= AesEncryptUtils.encrypt(rucan, AesEncryptUtils.VIDEO_KEY); params.put("params",data); log.error(e.toString(),e); } return params; } /** * 获取url * @return */ public String getUrl(){ try{ String url=redisService.get("video","url"); if(StringHelper.isEmpty(url)){ return TVideoConfigUtil.Q2HTTPURL; } return url; }catch (Exception e){ log.error(e.toString(),e); return TVideoConfigUtil.Q2HTTPURL; } } public String getConfig(){ try{ String config=redisService.get("video","config"); if(StringHelper.isNotEmpty(config)){ return config; } }catch (Exception e){ log.error(e.toString(),e); } return "bns"; } }