LAPTOP-KB9HII50\70708 2 роки тому
батько
коміт
18ea852600

+ 4 - 7
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/config/YsConfig.java

@ -17,7 +17,7 @@ public class YsConfig {
     * 目前为多个账号 监控设备与账号绑定关系表ys_device、dm_ys_config
     * 目前为多个账号 监控设备与账号绑定关系表ys_device、dm_ys_config
     * mobile:13559485270 pwd:zjxl123456*
     * mobile:13559485270 pwd:zjxl123456*
     * mobile:15659713528 pwd:woaini123a*
     * mobile:15659713528 pwd:woaini123a*
     *
     * mobile:18770887864 pwd:123456a.
     * pc端 https://es.ys7.com/ys/login
     * pc端 https://es.ys7.com/ys/login
     * 开放平台 https://auth.ys7.com/signIn?from=392f743db8514040b395&r=5019066229&returnUrl=https://open.ys7.com/cn/s/index&host=open.ys7.com
     * 开放平台 https://auth.ys7.com/signIn?from=392f743db8514040b395&r=5019066229&returnUrl=https://open.ys7.com/cn/s/index&host=open.ys7.com
     */
     */
@ -54,8 +54,7 @@ public class YsConfig {
    public static final String getDeviceLiveAddress = iotBaseUrl+ "/api/lapp/live/address/limited";
    public static final String getDeviceLiveAddress = iotBaseUrl+ "/api/lapp/live/address/limited";
    //获取设备有效直播地址(对讲)
    //获取设备有效直播地址(对讲)
//    public static final String getDeviceLiveAddress2 = iotBaseUrl+ "/api/lapp/v2/live/address/get";
    public static final String getDeviceLiveAddress2 = iotBaseUrl+ "/";
    public static final String getDeviceLiveAddress2 = iotBaseUrl+ "/api/lapp/v2/live/address/get";
    //设备视频加解密开关
    //设备视频加解密开关
    public static final String deviceEncrypt = baseUrl+ "/api/resource/device/encrypt/switch";
    public static final String deviceEncrypt = baseUrl+ "/api/resource/device/encrypt/switch";
@ -82,12 +81,10 @@ public class YsConfig {
    public static final String deviceVideoTimeList = iotBaseUrl + "/api/lapp/video/by/time";
    public static final String deviceVideoTimeList = iotBaseUrl + "/api/lapp/video/by/time";
    //根据时间获取录像地址//仅rtmp格式
    //根据时间获取录像地址//仅rtmp格式
//    public static final String deviceVideoUrlByTime = iotBaseUrl + "/api/lapp/v2/live/address/get";
    public static final String deviceVideoUrlByTime = iotBaseUrl + "/";
    public static final String deviceVideoUrlByTime = iotBaseUrl + "/api/lapp/v2/live/address/get";
    //录像地址 多格式
    //录像地址 多格式
//    public static final String videoList2 = iotBaseUrl +"/api/lapp/v2/live/address/get";
    public static final String videoList2 = iotBaseUrl +"/";
    public static final String videoList2 = iotBaseUrl +"/api/lapp/v2/live/address/get";
    //全天录像
    //全天录像
    public static final String fullDayVideo = iotBaseUrl +"/api/lapp/device/fullday/record/switch/set";
    public static final String fullDayVideo = iotBaseUrl +"/api/lapp/device/fullday/record/switch/set";

+ 31 - 19
svr/svr-cloud-care/src/main/java/com/yihu/jw/care/service/device/YsDeviceService.java

@ -91,42 +91,54 @@ public class YsDeviceService {
     * @return
     * @return
     * @throws Exception
     * @throws Exception
     */
     */
    public String getIotAccessToken(String deviceSn) throws Exception {
    public synchronized String getIotAccessToken(String deviceSn) throws Exception {
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        YsConfigDo YSCONFIGDO = ysConfig.getConfig(deviceSn);
        if(redisTemplate.hasKey(YSCONFIGDO.getIotAccessTokenKey())){
        if(redisTemplate.hasKey(YSCONFIGDO.getIotAccessTokenKey())){
            return redisTemplate.opsForValue().get(YSCONFIGDO.getIotAccessTokenKey());
            return redisTemplate.opsForValue().get(YSCONFIGDO.getIotAccessTokenKey());
        }
        }
        JSONObject responseBody = null;
        JSONObject responseBody = null;
        String assToken = null;
        if (1==YSCONFIGDO.getConfigId()||2==YSCONFIGDO.getConfigId()){//兼容智居平台设备,后续全部迁移可删除改代码
        if (1==YSCONFIGDO.getConfigId()||2==YSCONFIGDO.getConfigId()){//兼容智居平台设备,后续全部迁移可删除改代码
            JSONObject param = new JSONObject();
            JSONObject param = new JSONObject();
            param.put("accessToken",getAccessToken(deviceSn));
            param.put("accessToken",getAccessToken(deviceSn));
            HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
            HttpEntity<JSONObject> response = httpClientUtil.assesTokenPostHttp(YsConfig.iotAssesToken,param, HttpMethod.POST);
            responseBody = response.getBody();
            responseBody = response.getBody();
            if (responseBody.getInteger("code")==200){
                assToken = responseBody.getJSONObject("data").getString("ezOpenAccessToken");
                Long expireTime = responseBody.getJSONObject("data").getLong("expireTime");//token有效截止日期
                Long nowTime = System.currentTimeMillis();
                expireTime = expireTime-nowTime;
                redisTemplate.opsForValue().set(YSCONFIGDO.getIotAccessTokenKey(),assToken,expireTime, TimeUnit.MILLISECONDS);
                //设备解密密钥
                String secretKey = responseBody.getJSONObject("data").getString("secretKey");
                redisTemplate.opsForValue().set(YSCONFIGDO.getSecretKey(),secretKey,expireTime, TimeUnit.MILLISECONDS);
            }else {
                throw new Exception("获取token失败");
            }
        }else {
        }else {
            MultiValueMap<String, String> params =  new LinkedMultiValueMap<>();;
            MultiValueMap<String, String> params =  new LinkedMultiValueMap<>();;
            params.add("appKey",getIotAccessToken(YSCONFIGDO.getAppKey()));
            params.add("appSecret",getIotAccessToken(YSCONFIGDO.getAppSecret()));
            params.add("appKey",YSCONFIGDO.getAppKey());
            params.add("appSecret",YSCONFIGDO.getAppSecret());
            HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.iotAssesToken2,params, HttpMethod.POST);
            HttpEntity<JSONObject> response = httpClientUtil.iotAssesTokenPostHttp(YsConfig.iotAssesToken2,params, HttpMethod.POST);
            responseBody = response.getBody();
            responseBody = response.getBody();
            if (responseBody.getInteger("code")==200){
                assToken = responseBody.getJSONObject("data").getString("accessToken");
                Long expireTime = responseBody.getJSONObject("data").getLong("expireTime");//token有效截止日期
                Long nowTime = System.currentTimeMillis();
                expireTime = expireTime-nowTime;
                redisTemplate.opsForValue().set(YSCONFIGDO.getIotAccessTokenKey(),assToken,expireTime, TimeUnit.MILLISECONDS);
                //设备解密密钥
//                String secretKey = responseBody.getJSONObject("data").getString("secretKey");
//                redisTemplate.opsForValue().set(YSCONFIGDO.getSecretKey(),secretKey,expireTime, TimeUnit.MILLISECONDS);
            }else {
                throw new Exception("获取token失败");
            }
        }
        }
        String assToken = null;
        if (responseBody.getInteger("code")==200){
            assToken = responseBody.getJSONObject("data").getString("ezOpenAccessToken");
            Long expireTime = responseBody.getJSONObject("data").getLong("expireTime");//token有效截止日期
            Long nowTime = System.currentTimeMillis();
            expireTime = expireTime-nowTime;
            redisTemplate.opsForValue().set(YSCONFIGDO.getIotAccessTokenKey(),assToken,expireTime, TimeUnit.MILLISECONDS);
            //设备解密密钥
            String secretKey = responseBody.getJSONObject("data").getString("secretKey");
            redisTemplate.opsForValue().set(YSCONFIGDO.getSecretKey(),secretKey,expireTime, TimeUnit.MILLISECONDS);
//            Long ss= redisTemplate.getExpire(YsConfig.iotRedisKey);
//            System.out.println(expireTime+"---"+ss);
        }else {
            throw new Exception("获取token失败");
        }
        return assToken;
        return assToken;
    }
    }