大华接口对接
parent
d5a23f9768
commit
83d0b39672
2
pom.xml
2
pom.xml
|
|
@ -42,6 +42,8 @@
|
|||
<version>1.0.13.15</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,11 @@
|
|||
<groupId>com.jjb.saas</groupId>
|
||||
<artifactId>jjb-saas-framework-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dahuatech.icc</groupId>
|
||||
<artifactId>java-sdk-oauth</artifactId>
|
||||
<version>1.0.13.15</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
spring:
|
||||
config:
|
||||
import:
|
||||
# - classpath:nacos.yml
|
||||
- classpath:prodnacos.yml
|
||||
- classpath:nacos.yml
|
||||
# - classpath:prodnacos.yml
|
||||
- classpath:sdk.yml
|
||||
- classpath:swagger.yml
|
||||
# - classpath:ds.yml
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@ message:
|
|||
# 大华平台配置
|
||||
dahua:
|
||||
oauth:
|
||||
host: 192.168.1.100
|
||||
client-id: your-client-id
|
||||
client-secret: your-secret
|
||||
username: admin
|
||||
password: 123456
|
||||
host: 123.183.159.35
|
||||
client-id: 123.183.159.35
|
||||
client-secret: 4edfdcd2-67e6-41db-a1ae-b98d47a70266
|
||||
username: system
|
||||
password: zcloud88888
|
||||
http: false
|
||||
port: 443
|
||||
port: 4443
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package com.zcloud.primeport.web;
|
||||
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.zcloud.primeport.api.DaHuaServiceI;
|
||||
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Api(tags = "大华平台对接")
|
||||
@RequestMapping("/${application.gateway}/dahua")
|
||||
@RestController
|
||||
public class DaHuaController {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DaHuaServiceI daHuaService;
|
||||
|
||||
@ApiOperation("同步人员到大华平台-新增")
|
||||
@PostMapping("/person/sync")
|
||||
public SingleResponse<Boolean> syncPerson(@Validated @RequestBody DaHuaPersonSyncCmd cmd) {
|
||||
|
||||
if (daHuaService == null) {
|
||||
throw new RuntimeException("大华服务未配置");
|
||||
}
|
||||
return daHuaService.syncPerson(cmd);
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,10 @@
|
|||
<groupId>com.zcloud.primeport</groupId>
|
||||
<artifactId>web-infrastructure</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zcloud.primeport</groupId>
|
||||
<artifactId>web-domain</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.zcloud.primeport.service;
|
||||
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.zcloud.primeport.api.DaHuaServiceI;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class DaHuaServiceImpl implements DaHuaServiceI {
|
||||
|
||||
@Autowired(required = false)
|
||||
private DaHuaGateway daHuaGateway;
|
||||
|
||||
@Override
|
||||
public SingleResponse<Boolean> syncPerson(DaHuaPersonSyncCmd cmd) {
|
||||
if (daHuaGateway == null) {
|
||||
throw new RuntimeException("大华服务未配置");
|
||||
}
|
||||
Boolean result = daHuaGateway.syncPerson(cmd);
|
||||
return SingleResponse.of(result);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
package com.zcloud.primeport.api;
|
||||
|
||||
import com.alibaba.cola.dto.SingleResponse;
|
||||
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
||||
|
||||
public interface DaHuaServiceI {
|
||||
|
||||
SingleResponse<Boolean> syncPerson(DaHuaPersonSyncCmd cmd);
|
||||
}
|
||||
|
|
@ -23,27 +23,27 @@ public class ThreadPoolAsyncConfig {
|
|||
public static String namePrefix;
|
||||
public static Integer keepAliveSeconds;
|
||||
|
||||
@Value("${archives.async.pool.maxPoolSize}")
|
||||
@Value("${archives.async.pool.maxPoolSize:10}")
|
||||
public void setMaxPoolSize(Integer maxPoolSizeProperties) {
|
||||
maxPoolSize = maxPoolSizeProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.corePoolSize}")
|
||||
@Value("${archives.async.pool.corePoolSize:5}")
|
||||
public void setCorePoolSize(Integer corePoolSizeProperties) {
|
||||
corePoolSize = corePoolSizeProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.queueCapacity}")
|
||||
@Value("${archives.async.pool.queueCapacity:100}")
|
||||
public void setQueueCapacity(Integer queueCapacityProperties) {
|
||||
queueCapacity = queueCapacityProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.namePrefix}")
|
||||
@Value("${archives.async.pool.namePrefix:async-}")
|
||||
public void setNamePrefix(String namePrefixProperties) {
|
||||
namePrefix = namePrefixProperties;
|
||||
}
|
||||
|
||||
@Value("${archives.async.pool.keepAliveSeconds}")
|
||||
@Value("${archives.async.pool.keepAliveSeconds:60}")
|
||||
public void setKeepAliveSeconds(Integer keepAliveSecondsProperties) {
|
||||
keepAliveSeconds = keepAliveSecondsProperties;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,26 +0,0 @@
|
|||
package com.zcloud.primeport.domain.config;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Date: 2026/7/2
|
||||
* @User: tianxinlei
|
||||
*/
|
||||
@Component
|
||||
@Getter
|
||||
@Setter
|
||||
@ConfigurationProperties(prefix = "dahua.oauth")
|
||||
public class DaHuaOauthProperties {
|
||||
private String host;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean http;
|
||||
private String port;
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
package com.zcloud.primeport.domain.config;
|
||||
|
||||
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @Date: 2026/7/2
|
||||
* @User: tianxinlei
|
||||
*/
|
||||
@Configuration
|
||||
public class DaHuaSdkConfig {
|
||||
|
||||
private final DaHuaOauthProperties dahuaOauthProperties;
|
||||
|
||||
// 构造注入配置属性
|
||||
public DaHuaSdkConfig(DaHuaOauthProperties dahuaOauthProperties) {
|
||||
this.dahuaOauthProperties = dahuaOauthProperties;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public OauthConfigUserPwdInfo daHuaOauthConfig() {
|
||||
return new OauthConfigUserPwdInfo(
|
||||
dahuaOauthProperties.getHost(),
|
||||
dahuaOauthProperties.getClientId(),
|
||||
dahuaOauthProperties.getClientSecret(),
|
||||
dahuaOauthProperties.getUsername(),
|
||||
dahuaOauthProperties.getPassword(),
|
||||
dahuaOauthProperties.isHttp(),
|
||||
dahuaOauthProperties.getPort()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
package com.zcloud.primeport.domain.gateway;
|
||||
|
||||
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
||||
|
||||
public interface DaHuaGateway {
|
||||
|
||||
Boolean syncPerson(DaHuaPersonSyncCmd cmd);
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
package com.zcloud.primeport.domain.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class DaHuaPersonSyncCmd {
|
||||
|
||||
private String service;
|
||||
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
private String code;
|
||||
|
||||
private Integer paperType;
|
||||
|
||||
private String paperNumber;
|
||||
|
||||
private String paperAddress;
|
||||
|
||||
private Long departmentId;
|
||||
|
||||
private Integer personType;
|
||||
|
||||
private Integer availableTimes;
|
||||
|
||||
private String phone;
|
||||
|
||||
private String email;
|
||||
|
||||
private Integer age;
|
||||
|
||||
private String birthday;
|
||||
|
||||
private Integer sex;
|
||||
|
||||
private String country;
|
||||
|
||||
private Integer nation;
|
||||
|
||||
private String nationName;
|
||||
|
||||
private String selfCode;
|
||||
|
||||
private String ownerCode;
|
||||
|
||||
private String validStartTime;
|
||||
|
||||
private String validEndTime;
|
||||
|
||||
private String password;
|
||||
|
||||
private String passwordKey;
|
||||
|
||||
private List<DepartmentItem> departmentList;
|
||||
|
||||
private List<PersonBiosignature> personBiosignatures;
|
||||
|
||||
private Object fieldExt;
|
||||
|
||||
@Data
|
||||
public static class DepartmentItem {
|
||||
private Long departmentId;
|
||||
private Long departmentType;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class PersonBiosignature {
|
||||
private Integer type;
|
||||
private Integer index;
|
||||
private String path;
|
||||
private String base64Data;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.zcloud.primeport.dahua.api;
|
||||
|
||||
import com.dahuatech.icc.exception.ClientException;
|
||||
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
|
||||
import com.zcloud.primeport.dahua.client.DaHuaApiClient;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@ConditionalOnBean(DaHuaApiClient.class)
|
||||
public class DaHuaPersonApi {
|
||||
|
||||
@Resource
|
||||
private DaHuaApiClient daHuaApiClient;
|
||||
|
||||
private static final String PERSON_ADD_URL = "/evo-apigw/evo-brm/1.2.0/person/subsystem/add";
|
||||
|
||||
public GeneralResponse addPerson(Map<String, Object> body) throws ClientException {
|
||||
String token = daHuaApiClient.getToken();
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Authorization", "bearer " + token);
|
||||
return daHuaApiClient.postJson(PERSON_ADD_URL, body, headers);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,79 @@
|
|||
package com.zcloud.primeport.dahua.client;
|
||||
|
||||
import com.dahuatech.hutool.http.Method;
|
||||
import com.dahuatech.icc.exception.ClientException;
|
||||
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
|
||||
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
|
||||
import com.dahuatech.icc.oauth.utils.HttpUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DaHuaApiClient {
|
||||
|
||||
private final OauthConfigUserPwdInfo oauthConfig;
|
||||
|
||||
public DaHuaApiClient(OauthConfigUserPwdInfo oauthConfig) {
|
||||
this.oauthConfig = oauthConfig;
|
||||
oauthConfig.getHttpConfigInfo().setReadTimeout(-1L);
|
||||
oauthConfig.getHttpConfigInfo().setConnectionTimeout(-1L);
|
||||
}
|
||||
|
||||
public DaHuaApiClient(String host, String clientId, String clientSecret, String username, String password, boolean isHttp, String port) {
|
||||
this.oauthConfig = new OauthConfigUserPwdInfo(host, clientId, clientSecret, username, password, isHttp, port);
|
||||
oauthConfig.getHttpConfigInfo().setReadTimeout(-1L);
|
||||
oauthConfig.getHttpConfigInfo().setConnectionTimeout(-1L);
|
||||
}
|
||||
|
||||
public GeneralResponse postJson(String path, Map<String, Object> body) throws ClientException {
|
||||
return HttpUtils.executeJson(path, body, null, Method.POST, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse postJson(String path, Map<String, Object> body, Map<String, String> headers) throws ClientException {
|
||||
return HttpUtils.executeJson(path, body, headers, Method.POST, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse getForm(String path) throws ClientException {
|
||||
return HttpUtils.executeForm(path, null, null, Method.GET, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse getForm(String path, Map<String, Object> params) throws ClientException {
|
||||
return HttpUtils.executeForm(path, params, null, Method.GET, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse getForm(String path, Map<String, Object> params, Map<String, String> headers) throws ClientException {
|
||||
return HttpUtils.executeForm(path, params, headers, Method.GET, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse putJson(String path, Map<String, Object> body) throws ClientException {
|
||||
return HttpUtils.executeJson(path, body, null, Method.PUT, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse putJson(String path, Map<String, Object> body, Map<String, String> headers) throws ClientException {
|
||||
return HttpUtils.executeJson(path, body, headers, Method.PUT, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse deleteForm(String path) throws ClientException {
|
||||
return HttpUtils.executeForm(path, null, null, Method.DELETE, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public GeneralResponse deleteForm(String path, Map<String, Object> params) throws ClientException {
|
||||
return HttpUtils.executeForm(path, params, null, Method.DELETE, oauthConfig, GeneralResponse.class);
|
||||
}
|
||||
|
||||
public String getToken() throws ClientException {
|
||||
return HttpUtils.getToken(oauthConfig).getAccess_token();
|
||||
}
|
||||
|
||||
public void setReadTimeout(Long timeout) {
|
||||
oauthConfig.getHttpConfigInfo().setReadTimeout(timeout);
|
||||
}
|
||||
|
||||
public void setConnectionTimeout(Long timeout) {
|
||||
oauthConfig.getHttpConfigInfo().setConnectionTimeout(timeout);
|
||||
}
|
||||
|
||||
public OauthConfigUserPwdInfo getOauthConfig() {
|
||||
return oauthConfig;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
package com.zcloud.primeport.dahua.config;
|
||||
|
||||
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
|
||||
import com.zcloud.primeport.dahua.client.DaHuaApiClient;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties(DaHuaProperties.class)
|
||||
@ConditionalOnProperty(prefix = "dahua.oauth", name = "host")
|
||||
public class DaHuaAutoConfig {
|
||||
|
||||
@Bean("dahuaApiOauthConfig")
|
||||
public OauthConfigUserPwdInfo dahuaApiOauthConfig(DaHuaProperties properties) {
|
||||
OauthConfigUserPwdInfo config = new OauthConfigUserPwdInfo(
|
||||
properties.getHost(),
|
||||
properties.getClientId(),
|
||||
properties.getClientSecret(),
|
||||
properties.getUsername(),
|
||||
properties.getPassword(),
|
||||
properties.isHttp(),
|
||||
properties.getPort()
|
||||
);
|
||||
config.getHttpConfigInfo().setReadTimeout(properties.getReadTimeout());
|
||||
config.getHttpConfigInfo().setConnectionTimeout(properties.getConnectionTimeout());
|
||||
return config;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DaHuaApiClient daHuaApiClient(@Qualifier("dahuaApiOauthConfig") OauthConfigUserPwdInfo oauthConfig) {
|
||||
return new DaHuaApiClient(oauthConfig);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package com.zcloud.primeport.dahua.config;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "dahua.oauth")
|
||||
public class DaHuaProperties {
|
||||
|
||||
private String host;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String username;
|
||||
private String password;
|
||||
private boolean http = false;
|
||||
private String port = "4443";
|
||||
private Long readTimeout = -1L;
|
||||
private Long connectionTimeout = -1L;
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.zcloud.primeport.gatewayimpl;
|
||||
|
||||
import com.dahuatech.icc.exception.ClientException;
|
||||
import com.dahuatech.icc.oauth.model.v202010.GeneralResponse;
|
||||
import com.zcloud.primeport.dahua.api.DaHuaPersonApi;
|
||||
import com.zcloud.primeport.domain.gateway.DaHuaGateway;
|
||||
import com.zcloud.primeport.domain.model.DaHuaPersonSyncCmd;
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
@ConditionalOnBean(DaHuaPersonApi.class)
|
||||
public class DaHuaGatewayImpl implements DaHuaGateway {
|
||||
|
||||
private final DaHuaPersonApi daHuaPersonApi;
|
||||
|
||||
@Override
|
||||
public Boolean syncPerson(DaHuaPersonSyncCmd cmd) {
|
||||
Map<String, Object> body = convertToMap(cmd);
|
||||
try {
|
||||
GeneralResponse response = daHuaPersonApi.addPerson(body);
|
||||
return response != null && "0".equals(response.getCode());
|
||||
} catch (ClientException e) {
|
||||
throw new RuntimeException("同步人员到大华平台失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Object> convertToMap(DaHuaPersonSyncCmd cmd) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
try {
|
||||
Field[] fields = cmd.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
Object value = field.get(cmd);
|
||||
if (value != null) {
|
||||
map.put(field.getName(), value);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("转换请求参数失败", e);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
package com.zcloud.primeport.plan.mjDevice;
|
||||
|
||||
import com.dahuatech.icc.oauth.model.v202010.OauthConfigUserPwdInfo;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
|
|
@ -9,11 +11,12 @@ import org.springframework.stereotype.Component;
|
|||
* @User: tianxinlei
|
||||
*/
|
||||
@Component
|
||||
@ConditionalOnBean(name = "dahuaApiOauthConfig")
|
||||
public class DaHuaSdkUtil {
|
||||
|
||||
private final OauthConfigUserPwdInfo oauthConfig;
|
||||
|
||||
public DaHuaSdkUtil(OauthConfigUserPwdInfo oauthConfig) {
|
||||
public DaHuaSdkUtil(@Qualifier("dahuaApiOauthConfig") OauthConfigUserPwdInfo oauthConfig) {
|
||||
this.oauthConfig = oauthConfig;
|
||||
}
|
||||
|
||||
|
|
@ -33,4 +36,4 @@ public class DaHuaSdkUtil {
|
|||
}
|
||||
|
||||
// 其他设备查询、回放、抓拍等业务方法
|
||||
}
|
||||
}
|
||||
|
|
@ -35,26 +35,26 @@ public class OauthUtil {
|
|||
|
||||
// private final String publicKeyUrl = "https://192.168.42.194/evo-apigw/evo-oauth/1.0.0/oauth/public-key";
|
||||
|
||||
@Value("${icc.clientId}")
|
||||
@Value("${icc.clientId:}")
|
||||
private String clientId;
|
||||
@Value("${icc.publicKeyUrl}")
|
||||
@Value("${icc.publicKeyUrl:}")
|
||||
private String publicKeyUrl;
|
||||
@Value("${icc.clientSecret}")
|
||||
@Value("${icc.clientSecret:}")
|
||||
private String clientSecret;
|
||||
@Value("${icc.username}")
|
||||
@Value("${icc.username:}")
|
||||
private String username;
|
||||
@Value("${icc.password}")
|
||||
@Value("${icc.password:}")
|
||||
private String password;
|
||||
|
||||
@Value("${icc.url}")
|
||||
@Value("${icc.url:}")
|
||||
private String iccUrl;
|
||||
@Value("${icc.request.getGenerateIdUrl}")
|
||||
@Value("${icc.request.getGenerateIdUrl:}")
|
||||
private String iccGenerateIdUrl;
|
||||
@Value("${icc.request.getGenerateIdListUrl}")
|
||||
@Value("${icc.request.getGenerateIdListUrl:}")
|
||||
private String iccGenerateIdListUrl;
|
||||
@Value("${icc.request.imgInspectUrl}")
|
||||
@Value("${icc.request.imgInspectUrl:}")
|
||||
private String iccImgInspectUrl;
|
||||
@Value("${icc.request.getDepartmentIdUrl}")
|
||||
@Value("${icc.request.getDepartmentIdUrl:}")
|
||||
private String iccDepartmentIdUrl;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ import javax.annotation.Resource;
|
|||
*/
|
||||
@Component
|
||||
public class OneLevelCarUtil {
|
||||
@Value("${kmmj.dockflag}")
|
||||
@Value("${kmmj.dockflag:0}")
|
||||
private Integer dockFlag;
|
||||
@Value("${oneLevelCar.prefix}")
|
||||
@Value("${oneLevelCar.prefix:}")
|
||||
private String prefix;
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.zcloud.primeport.dahua.config.DaHuaAutoConfig
|
||||
|
|
@ -0,0 +1,74 @@
|
|||
package com.zcloud.primeport.dahua.client;
|
||||
|
||||
import com.dahuatech.icc.exception.ClientException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DaHuaApiClientTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("========== DaHuaApiClient 测试 ==========");
|
||||
|
||||
String host = "123.183.159.35";
|
||||
String clientId = "123.183.159.35";
|
||||
String clientSecret = "4edfdcd2-67e6-41db-a1ae-b98d47a70266";
|
||||
String username = "system";
|
||||
String password = "zcloud88888";
|
||||
boolean isHttp = false;
|
||||
String port = "4443";
|
||||
|
||||
// host: 123.183.159.35
|
||||
// client-id: 123.183.159.35
|
||||
// client-secret: 4edfdcd2-67e6-41db-a1ae-b98d47a70266
|
||||
// username: system
|
||||
// password: zcloud88888
|
||||
// http: false
|
||||
// port: 4443
|
||||
|
||||
|
||||
if (isPlaceholder(host) || isPlaceholder(clientId) || isPlaceholder(clientSecret)) {
|
||||
System.err.println("错误: 请先修改测试类中的配置参数为真实的大华平台凭证!");
|
||||
System.err.println("配置位置: DaHuaApiClientTest.java 第13-19行");
|
||||
System.err.println("需要填写: host, clientId, clientSecret, username, password");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
DaHuaApiClient client = new DaHuaApiClient(host, clientId, clientSecret, username, password, isHttp, port);
|
||||
|
||||
System.out.println("1. 测试获取 Token...");
|
||||
String token = client.getToken();
|
||||
System.out.println(" Token 获取成功!");
|
||||
System.out.println( token);
|
||||
|
||||
System.out.println("\n2. 测试 POST JSON 请求...");
|
||||
Map<String, Object> body = new HashMap<>();
|
||||
body.put("testKey", "testValue");
|
||||
try {
|
||||
client.postJson("/evo-apigw/evo-brm/1.2.0/device/subsystem/page", body);
|
||||
System.out.println(" POST 请求调用成功!");
|
||||
} catch (ClientException e) {
|
||||
System.out.println(" POST 请求返回错误(预期,因为接口不存在): " + e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("\n3. 测试 GET 请求...");
|
||||
try {
|
||||
client.getForm("/evo-apigw/evo-brm/1.0.0/device/1");
|
||||
System.out.println(" GET 请求调用成功!");
|
||||
} catch (ClientException e) {
|
||||
System.out.println(" GET 请求返回错误(预期,因为接口不存在): " + e.getMessage());
|
||||
}
|
||||
|
||||
System.out.println("\n========== 测试完成 ==========");
|
||||
|
||||
} catch (ClientException e) {
|
||||
System.err.println("测试失败: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPlaceholder(String value) {
|
||||
return value == null || value.contains("your-") || value.contains("平台") || value.contains("凭证") || value.contains("用户名") || value.contains("密码");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
package com.zcloud.primeport.dahua.config;
|
||||
|
||||
import com.zcloud.primeport.dahua.client.DaHuaApiClient;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@SpringBootTest(classes = DaHuaAutoConfigTest.TestConfig.class)
|
||||
public class DaHuaAutoConfigTest {
|
||||
|
||||
@Resource
|
||||
private DaHuaApiClient daHuaApiClient;
|
||||
|
||||
@Resource
|
||||
private DaHuaProperties daHuaProperties;
|
||||
|
||||
@Test
|
||||
public void testDaHuaApiClientBeanExists() {
|
||||
assertThat(daHuaApiClient).isNotNull();
|
||||
System.out.println("✅ DaHuaApiClient Bean 注入成功");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDaHuaPropertiesBinding() {
|
||||
assertThat(daHuaProperties.getHost()).isEqualTo("123.183.159.35");
|
||||
assertThat(daHuaProperties.getClientId()).isEqualTo("123.183.159.35");
|
||||
assertThat(daHuaProperties.getClientSecret()).isEqualTo("4edfdcd2-67e6-41db-a1ae-b98d47a70266");
|
||||
assertThat(daHuaProperties.getUsername()).isEqualTo("system");
|
||||
assertThat(daHuaProperties.getPassword()).isEqualTo("zcloud88888");
|
||||
assertThat(daHuaProperties.isHttp()).isFalse();
|
||||
assertThat(daHuaProperties.getPort()).isEqualTo("4443");
|
||||
System.out.println("✅ DaHuaProperties 配置绑定成功");
|
||||
System.out.println(" host: " + daHuaProperties.getHost());
|
||||
System.out.println(" clientId: " + daHuaProperties.getClientId());
|
||||
System.out.println(" username: " + daHuaProperties.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOauthConfigInitialized() {
|
||||
assertThat(daHuaApiClient.getOauthConfig()).isNotNull();
|
||||
// OauthConfigUserPwdInfo 是SDK内部类,不暴露getHost,配置绑定已通过DaHuaProperties验证
|
||||
System.out.println("✅ OauthConfigUserPwdInfo 初始化成功");
|
||||
System.out.println(" host: " + daHuaProperties.getHost());
|
||||
System.out.println(" username: " + daHuaProperties.getUsername());
|
||||
}
|
||||
|
||||
@EnableConfigurationProperties(DaHuaProperties.class)
|
||||
@Import(DaHuaAutoConfig.class)
|
||||
public static class TestConfig {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
dahua:
|
||||
host: 123.183.159.35
|
||||
client-id: 123.183.159.35
|
||||
client-secret: 4edfdcd2-67e6-41db-a1ae-b98d47a70266
|
||||
username: system
|
||||
password: zcloud88888
|
||||
http: false
|
||||
port: 4443
|
||||
|
||||
Loading…
Reference in New Issue