New file |
| | |
| | | package com.ycl.feign; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.hikvision.artemis.sdk.ArtemisHttpUtil; |
| | | import com.hikvision.artemis.sdk.config.ArtemisConfig; |
| | | import com.ycl.platform.domain.param.HK.FaceDetectParam; |
| | | import com.ycl.utils.DateUtils; |
| | | import constant.ApiConstants; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author:xp |
| | | * @date:2024/8/12 11:47 |
| | | */ |
| | | @Slf4j |
| | | public class HkApiUtil { |
| | | |
| | | |
| | | /** |
| | | * 调用海康接口 |
| | | * |
| | | * @param apiUrl 接口地址:/api/dqd/service/rs/v2/data/faceDetect/query |
| | | * @param params 请求参数 |
| | | * @param resultType 响应结果接收类 |
| | | * @return 调用结果 |
| | | */ |
| | | public static <T> String sendAPI(String apiUrl, Object params, Class<T> resultType) { |
| | | |
| | | // STEP1:设置平台参数,根据实际情况,设置host appkey appsecret 三个参数. |
| | | ArtemisConfig.host = "51.92.65.49"; // 平台的ip端口 |
| | | ArtemisConfig.appKey = "29555942"; // 密钥appkey |
| | | ArtemisConfig.appSecret = "t9U7tCplCyYHzQPPL7cH";// 密钥appSecret |
| | | |
| | | // STEP2:设置OpenAPI接口的上下文 |
| | | final String ARTEMIS_PATH = "/artemis"; |
| | | |
| | | // STEP3:设置接口的URI地址 |
| | | final String previewURLsApi = ARTEMIS_PATH + apiUrl; |
| | | Map<String, String> path = new HashMap<String, String>(2) { |
| | | { |
| | | put("https://", previewURLsApi); |
| | | } |
| | | }; |
| | | |
| | | // STEP4:设置参数提交方式 |
| | | String contentType = "application/json"; |
| | | |
| | | // STEP5:组装请求参数 |
| | | String body = JSON.toJSONString(params); |
| | | log.info("请求参数:{}",body); |
| | | |
| | | // STEP6:调用接口 |
| | | String result = null;// post请求application/json类型参数 |
| | | try { |
| | | result = ArtemisHttpUtil.doPostStringArtemis(path, body, null, null, contentType , null); |
| | | } catch (Exception e) { |
| | | log.error("接口:【{}】,调用失败"); |
| | | e.printStackTrace(); |
| | | } |
| | | HkApiUtil.getDataList(JSONObject.parseObject(result), resultType); |
| | | return result; |
| | | } |
| | | |
| | | //解析数据 |
| | | private static <T> List<T> getDataList(JSONObject jsonObject, Class<T> resultClass) { |
| | | if (jsonObject != null && ApiConstants.HKSuccessCode.equals(jsonObject.getString("code"))) { |
| | | log.info("数据格式"+jsonObject); |
| | | JSONObject data = jsonObject.getJSONObject("data"); |
| | | if (data == null) { |
| | | return null; |
| | | } |
| | | List<T> list = data.getList("list", resultClass); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | return list; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | } |
| | | |