|
@ -5,9 +5,11 @@ import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
import com.epmet.commons.tools.exception.EpmetException; |
|
|
|
|
|
import com.epmet.commons.tools.redis.RedisUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
|
|
|
import com.epmet.plugin.commons.redis.RedisKeys; |
|
|
import com.epmet.plugin.power.config.HikCloudProperties; |
|
|
import com.epmet.plugin.power.config.HikCloudProperties; |
|
|
import com.epmet.plugin.power.dto.hik.form.HikAuthorityFormDTO; |
|
|
import com.epmet.plugin.power.dto.hik.form.HikAuthorityFormDTO; |
|
|
import com.epmet.plugin.power.dto.hik.form.HikPersonFormDTO; |
|
|
import com.epmet.plugin.power.dto.hik.form.HikPersonFormDTO; |
|
@ -32,6 +34,9 @@ public class HkDeviceUtil { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private HikCloudProperties hikCloudProperties; |
|
|
private HikCloudProperties hikCloudProperties; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private RedisUtils redisUtils; |
|
|
|
|
|
|
|
|
private final String GET_ACCESS_TOKEN = "/oauth/token"; |
|
|
private final String GET_ACCESS_TOKEN = "/oauth/token"; |
|
|
private final String GET_DEVICES = "/api/v1/estate/devices"; |
|
|
private final String GET_DEVICES = "/api/v1/estate/devices"; |
|
|
private final String SEND_PERSON = "/api/v1/estate/system/person"; |
|
|
private final String SEND_PERSON = "/api/v1/estate/system/person"; |
|
@ -48,6 +53,12 @@ public class HkDeviceUtil { |
|
|
* @date 2022/5/20 16:40 |
|
|
* @date 2022/5/20 16:40 |
|
|
*/ |
|
|
*/ |
|
|
public String getAccessToken() { |
|
|
public String getAccessToken() { |
|
|
|
|
|
String key = RedisKeys.getHikTokenKey(); |
|
|
|
|
|
Object obj = redisUtils.get(key); |
|
|
|
|
|
if (null != obj) { |
|
|
|
|
|
return (String) obj; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
String url = hikCloudProperties.getUrl().concat(GET_ACCESS_TOKEN); |
|
|
String url = hikCloudProperties.getUrl().concat(GET_ACCESS_TOKEN); |
|
|
Map<String, Object> paramsMap = new HashMap<>(8); |
|
|
Map<String, Object> paramsMap = new HashMap<>(8); |
|
|
paramsMap.put("client_id", hikCloudProperties.getClient()); |
|
|
paramsMap.put("client_id", hikCloudProperties.getClient()); |
|
@ -65,6 +76,8 @@ public class HkDeviceUtil { |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "AccessToken获取失败"); |
|
|
throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "AccessToken获取失败"); |
|
|
} |
|
|
} |
|
|
String accessToken = "Bearer ".concat(toResult.get("access_token").toString()); |
|
|
String accessToken = "Bearer ".concat(toResult.get("access_token").toString()); |
|
|
|
|
|
|
|
|
|
|
|
redisUtils.set(key, accessToken, RedisUtils.HOUR_ONE_EXPIRE); |
|
|
return accessToken; |
|
|
return accessToken; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|