|
|
@@ -0,0 +1,58 @@
|
|
|
+package biz.kq;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 统一读取海康网关连接参数,避免业务服务各自复制一套配置解析逻辑。
|
|
|
+ */
|
|
|
+public final class HkConnU {
|
|
|
+
|
|
|
+ private static final String CFG_HOST = "hk.host";
|
|
|
+ private static final String CFG_PORT = "hk.port";
|
|
|
+ private static final String CFG_APP_KEY = "hk.appKey";
|
|
|
+ private static final String CFG_APP_SECRET = "hk.appSecret";
|
|
|
+
|
|
|
+ private HkConnU() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Map<String, Object> makeHkConnParm() {
|
|
|
+ String host = rdCfg(CFG_HOST, "HK_HOST");
|
|
|
+ String appKey = rdCfg(CFG_APP_KEY, "HK_APP_KEY");
|
|
|
+ String appSecret = rdCfg(CFG_APP_SECRET, "HK_APP_SECRET");
|
|
|
+ if (StringUtils.isAnyBlank(host, appKey, appSecret))
|
|
|
+ return HkKqServ.makeDefaultHkConnParm();
|
|
|
+
|
|
|
+ Map<String, Object> queryParm = new LinkedHashMap<>();
|
|
|
+ queryParm.put("host", host);
|
|
|
+ queryParm.put("port", rdIntCfg(CFG_PORT, "HK_PORT", 443));
|
|
|
+ queryParm.put("appKey", appKey);
|
|
|
+ queryParm.put("appSecret", appSecret);
|
|
|
+ return queryParm;
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int rdIntCfg(String propName, String envName, int defVal) {
|
|
|
+ String cfgVal = rdCfg(propName, envName);
|
|
|
+ if (StringUtils.isBlank(cfgVal))
|
|
|
+ return defVal;
|
|
|
+ try {
|
|
|
+ return Integer.parseInt(StringUtils.trim(cfgVal));
|
|
|
+ } catch (Exception ignored) {
|
|
|
+ return defVal;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String rdCfg(String propName, String envName) {
|
|
|
+ String value = System.getProperty(propName);
|
|
|
+ if (StringUtils.isNotBlank(value))
|
|
|
+ return StringUtils.trim(value);
|
|
|
+ if (StringUtils.isNotBlank(envName)) {
|
|
|
+ value = System.getenv(envName);
|
|
|
+ if (StringUtils.isNotBlank(value))
|
|
|
+ return StringUtils.trim(value);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|