czt
2026-02-26 181252cf8ba494441b1fdb3873da7afa90ff0813
fzzy-igdss-core/src/main/java/com/fzzy/igds/camera/impl/ApiPlayYdQlyService.java
@@ -5,6 +5,7 @@
import com.fzzy.igds.camera.data.*;
import com.fzzy.igds.camera.data.ydqly.YdQlyCamera;
import com.fzzy.igds.camera.data.ydqly.YdQlyDto;
import com.fzzy.igds.camera.data.ydqly.YdQlyNode;
import com.fzzy.igds.camera.data.ydqly.YdQlyResp;
import com.fzzy.igds.constant.CameraPlayType;
import com.fzzy.igds.constant.Constant;
@@ -41,7 +42,6 @@
     */
    private static final String URL_ACCESS_TOKEN = "https://open.qly.cmviot.cn/v3/open/api/token";
    private static final String URL_PLAY_LIVE = "https://open.qly.cmviot.cn/v3/open/api/websdk/live";
    private static final String URL_CAMERA_LIST = "https://open.qly.cmviot.cn/v3/open/api/node/tree";
    @Resource
@@ -79,6 +79,12 @@
        //接口获取播放地址
        YdQlyResp resp = getPlayUrl(cameraMedia, apiCameraDto.getCameraId());
        if("11503".equals(resp.getResultCode()) || "11504".equals(resp.getResultCode())){
            delAccessToken();
            resp = getPlayUrl(cameraMedia, apiCameraDto.getCameraId());
        }
        if(!"000000".equals(resp.getResultCode())){
            return new ApiCameraResp(ApiCameraResp.CODE_ERROR, resp.getResultMsg());
        }
@@ -101,17 +107,24 @@
        //查询库区流媒体配置,获取库区节点
        CameraMedia cameraMedia = cameraMediaService.getByDeptId(apiCameraDto.getDeptId(), apiCameraDto.getCompanyId());
        if(null == cameraMedia || StringUtils.isEmpty(cameraMedia.getYdStoreId())){
            log.error("获取摄像头信息失败,库区节点未配置!");
            log.error("同步失败,库区节点未配置,请到库区配置->流媒体配置!");
            return null;
        }
        String str = getCameraList(cameraMedia);
        if(null== str){
            log.error("获取摄像头信息失败,库区节点未配置!");
        //接口获取播放地址
        YdQlyResp resp = getCameraList(cameraMedia);
        if("11503".equals(resp.getResultCode()) || "11504".equals(resp.getResultCode())){
            delAccessToken();
            resp = getCameraList(cameraMedia);
        }
        if(!"000000".equals(resp.getResultCode())){
            return null;
        }
        YdQlyDto ydQlyDto = JSONObject.parseObject(str, YdQlyDto.class);
        YdQlyDto ydQlyDto = JSONObject.parseObject(resp.getData(), YdQlyDto.class);
        if(null== ydQlyDto || null == ydQlyDto.getDevice()){
            log.error("获取摄像头信息失败,库区节点未配置!");
@@ -129,12 +142,21 @@
            camera.setSn(dto.getDeviceId());
            camera.setName(dto.getDeviceName());
            camera.setType("01");
            camera.setOrderNum(null);
            camera.setPlayType(CameraPlayType.PLAY_TYPE_YD_QLY.getCode());
            cameraService.pullUpdateCamera(camera);
        }
        return listCamera;
    }
    /**
     * 清除token
     */
    private void delAccessToken() {
        //请清除token
        String key = RedisConst.buildKey(ContextUtil.getCompanyId(), Constant.KEY_ACCESS_TOKEN_YD_QLY);
        redisCache.deleteObject(key);
    }
    /**
     * 获取accessToken
@@ -247,7 +269,7 @@
            String jsonString = JSONObject.toJSONString(herderParams);
            // 4. RSA签名
            byte[] keyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
            byte[] keyBytes = Base64.getDecoder().decode(cameraMedia.getYdRsa());
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
            PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
@@ -275,7 +297,7 @@
     * @param cameraMedia
     * @return
     */
    private String getCameraList(CameraMedia cameraMedia) {
    private YdQlyResp getCameraList(CameraMedia cameraMedia) {
        try {
            String timestamp = String.valueOf(System.currentTimeMillis());
@@ -302,7 +324,7 @@
            String jsonString = JSONObject.toJSONString(herderParams);
            // 4. RSA签名
            byte[] keyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
            byte[] keyBytes = Base64.getDecoder().decode(cameraMedia.getYdRsa());
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
            PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
@@ -318,43 +340,27 @@
            String response = HttpUtils.doPost(URL_CAMERA_LIST, herderParams, requestBodyStr);
            YdQlyResp ydQlyResp = JSONObject.parseObject(response, YdQlyResp.class);
            if(!"000000".equals(ydQlyResp.getResultCode())){
                return null;
            }
            return ydQlyResp.getData();
            return ydQlyResp;
        } catch (Exception e) {
            return null;
        }
    }
    private static final String TOKEN = "eyJhbGciOiJIUzI1NiJ9.eyJwcm9mZXNzaW9uIjoxLCJhcHBpZCI6ImUwYTFhNDIwZjU1YTRmOWRiYTBkNjM4MmRmNTlkYjY2Iiwib3BlcmF0b3JUeXBlIjoxLCJvcGVyYXRvciI6ImUwYTFhNDIwZjU1YTRmOWRiYTBkNjM4MmRmNTlkYjY2IiwianRpIjoiMjE4Nzk0MzMzMTE4NDM1NzM4NyIsImlhdCI6MTc2NzYxMDM3Mywic3ViIjoiZTBhMWE0MjBmNTVhNGY5ZGJhMGQ2MzgyZGY1OWRiNjYiLCJleHAiOjE3NjgyMTUxNzN9.Tot-yYsNLbY9YH2AYgV_Fggb7PCNrUR0PDi0Ear1s5w";
    private static final String APP_ID = "e0a1a420f55a4f9dba0d6382df59db66";
    private static final String SECRET = "OuLsvFL9nqxeeltu";
    private static final String URL = "https://open.qly.cmviot.cn/v3/open/api/token";
    private static final String URL_PLAY = "https://open.qly.cmviot.cn/v3/open/api/websdk/live";
    private static final String URL_LIST = "https://open.qly.cmviot.cn/v3/open/api/node/tree";
    private static final String PRIVATE_KEY = "MIICdQIBADANBgkqhkiG9w0BAQEFAASCAl8wggJbAgEAAoGBAI7iA0WASV8pekjHVcsYV3ycZR2/+XK7O6BZpybAw/cauEzHRKsrDknErFxdNFca1OlVbPljBOfXjIrhS1CpAWez3Ff2+XaAaFE3fFer9LTxQ5GMXJSIAGQ4ntq/7y57ucwdVjL9+4B4WT8Yfea1DLa/fv+I0Gm7haVQj75JVYhBAgMBAAECgYAfvBs16JRjSncaiwuHHFTyHFppDSZ+UQ+hQchaVx4vWAPvKaMa0WlPARu3OAxT/GWlnY+ipFeGlt1kSz3LIH5rERYd5sNPOFmK7Nzih1VK6r/y1XobM4cLqLrP2UW2c3V36A77xz1xpaa9CP5l6gFjYAdZ1vnGS7HyjolWvzjUAQJBAMB6OTwrHcxOUJiLRJSK697LMIziBi1p5cR4NdSoQjQ4/enUqzAalwi6ZODuGSYai5VKhH9xkxFASWMT8waTOxECQQC+CbWK4Igx8Uh5qPpBIiFuA6ReAuFoRDMvKlzPUi8FGFkvF/CDx5IUFvYUd7FFX4l6Wtu5vf+VF3OydmzFr5oxAkB96Xa3nZ0IodKnd7ONWLOkM1e3UcSowLXGKL1OOCPW9dFkvfKerUZQN172pctd2c+mAfFbTXjfuCZJ4isBCh+BAkA8+ZiKaujIPYbnolRJuc3IItsGXx47+kYCCDGnQ9NaaymSdrfxUIOKdqOWhaEXhUPzQlvmCRSMne29gUn9VA7BAkBLvhtfSuANFSDt942GAY0Q25bJBM01yrRjtTEVCnGDxztexksPKaWGnJxk0Zk0xp4PkJCZvVuxFZ1Dw7F9yg6X";
    public static void main(String[] args) {
//        String accessToken = getAccessTokenTest();
//        System.out.println("accessToken: " + accessToken);
//        String playUrl = getPlayUrlTest();
//        System.out.println("playUrl: " + playUrl);
        String cameraList = getCameraListTest();
        System.out.println("cameraList: " + cameraList);
    }
    private static String getCameraListTest() {
    /**
     * 获取监控所在节点编码
     * @param cameraMedia
     * @return
     */
    public List<YdQlyNode> getNodeId(CameraMedia cameraMedia) {
        try {
            String timestamp = String.valueOf(System.currentTimeMillis());
            JSONObject requestBody = new JSONObject();
            requestBody.put("queryType", 0);
            requestBody.put("nodeId", "1346024619493187584");
            if(StringUtils.isNotBlank(cameraMedia.getYdStoreId())){
                requestBody.put("nodeId", cameraMedia.getYdStoreId());
            }
            String requestBodyStr = requestBody.toString();
@@ -362,16 +368,17 @@
            String md5 = DigestUtils.md5Hex(String.valueOf(requestBody));
            // 3. 构建签名字符串
            Map signParams = new LinkedHashMap();
            signParams.put("appid", APP_ID);
            signParams.put("md5", md5);
            signParams.put("timestamp", timestamp);
            signParams.put("token", TOKEN);
            signParams.put("version", "1.0.0");
            String jsonString = JSONObject.toJSONString(signParams);
            LinkedHashMap<String, String> herderParams = new LinkedHashMap<>();
            herderParams.put("appid", cameraMedia.getYdAppKey());
            herderParams.put("md5", md5);
            herderParams.put("timestamp", timestamp);
            herderParams.put("token", getAccessToken(cameraMedia));
            herderParams.put("version", "1.0.0");
            String jsonString = JSONObject.toJSONString(herderParams);
            // 4. RSA签名
            byte[] keyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
            byte[] keyBytes = Base64.getDecoder().decode(cameraMedia.getYdRsa());
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
            PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
@@ -380,128 +387,44 @@
            signature.update(jsonString.getBytes("UTF-8"));
            String signatureString = Base64.getEncoder().encodeToString(signature.sign());
            LinkedHashMap<String, String> herderParams = new LinkedHashMap<>();
            herderParams.put("content-type", "application/json");
            herderParams.put("appid", APP_ID);
            herderParams.put("md5", md5);
            herderParams.put("timestamp", timestamp);
            herderParams.put("token", TOKEN);
            herderParams.put("version", "1.0.0");
            herderParams.put("signature", signatureString);
            herderParams.put("content-type", "application/json");
            // 5. 发送请求
            String response = HttpUtils.doPost(URL_LIST, herderParams, requestBodyStr);
            String response = HttpUtils.doPost(URL_CAMERA_LIST, herderParams, requestBodyStr);
            return response;
            YdQlyResp resp = JSONObject.parseObject(response, YdQlyResp.class);
            if(!"000000".equals(resp.getResultCode())){
                return null;
            }
            YdQlyDto ydQlyDto = JSONObject.parseObject(resp.getData(), YdQlyDto.class);
            if(null == ydQlyDto || null == ydQlyDto.getNode() || ydQlyDto.getNode().isEmpty()){
                return null;
            }
            return ydQlyDto.getNode();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    private static String getPlayUrlTest() {
        try {
    /**
     * 获取所有节点
     * @param cameraMedia
     */
    public void getAllNodeId(CameraMedia cameraMedia) {
            String timestamp = String.valueOf(System.currentTimeMillis());
            JSONObject requestBody = new JSONObject();
            requestBody.put("deviceId", "gb_26236371771319266195");
            String requestBodyStr = requestBody.toString();
            // 2. 计算请求体MD5
            String md5 = DigestUtils.md5Hex(String.valueOf(requestBody));
            // 3. 构建签名字符串
            Map signParams = new LinkedHashMap();
            signParams.put("appid", APP_ID);
            signParams.put("md5", md5);
            signParams.put("timestamp", timestamp);
            signParams.put("token", TOKEN);
            signParams.put("version", "1.0.0");
            String jsonString = JSONObject.toJSONString(signParams);
            // 4. RSA签名
            byte[] keyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
            PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
            Signature signature = Signature.getInstance("SHA1WithRSA");
            signature.initSign(priKey);
            signature.update(jsonString.getBytes("UTF-8"));
            String signatureString = Base64.getEncoder().encodeToString(signature.sign());
            LinkedHashMap<String, String> herderParams = new LinkedHashMap<>();
            herderParams.put("content-type", "application/json");
            herderParams.put("appid", APP_ID);
            herderParams.put("md5", md5);
            herderParams.put("timestamp", timestamp);
            herderParams.put("token", TOKEN);
            herderParams.put("version", "1.0.0");
            herderParams.put("signature", signatureString);
            // 5. 发送请求
            String response = HttpUtils.doPost(URL_PLAY, herderParams, requestBodyStr);
            return response;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
    private static String getAccessTokenTest() {
        try {
            String timestamp = String.valueOf(System.currentTimeMillis());
            String sig =  Hex.encodeHexString(MessageDigest.getInstance("MD5").digest(StringUtils.getBytes(APP_ID+SECRET,"UTF-8")));
            JSONObject requestBody = new JSONObject();
            requestBody.put("operatorType", 1);
            requestBody.put("sig", sig);
            String requestBodyStr = requestBody.toString();
            // 2. 计算请求体MD5
            String md5 = DigestUtils.md5Hex(String.valueOf(requestBody));
            // 3. 构建签名字符串
            Map signParams = new LinkedHashMap();
            signParams.put("appid", APP_ID);
            signParams.put("md5", md5);
            signParams.put("timestamp", timestamp);
            signParams.put("version", "1.0.0");
            String jsonString = JSONObject.toJSONString(signParams);
            // 4. RSA签名
            byte[] keyBytes = Base64.getDecoder().decode(PRIVATE_KEY);
            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);
            PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(keySpec);
            Signature signature = Signature.getInstance("SHA1WithRSA");
            signature.initSign(priKey);
            signature.update(jsonString.getBytes("UTF-8"));
            String signatureString = Base64.getEncoder().encodeToString(signature.sign());
            LinkedHashMap<String, String> herderParams = new LinkedHashMap<>();
            herderParams.put("content-type", "application/json");
            herderParams.put("appid", APP_ID);
            herderParams.put("md5", md5);
            herderParams.put("timestamp", timestamp);
            herderParams.put("version", "1.0.0");
            herderParams.put("signature", signatureString);
            // 5. 发送请求
            String response = HttpUtils.doPost(URL, herderParams, requestBodyStr);
            return response;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        List<YdQlyNode> nodeList = this.getNodeId(cameraMedia);
        if(null != nodeList && !nodeList.isEmpty()){
            for (YdQlyNode node : nodeList) {
                if(node.getHasChild() == 1){
                    cameraMedia.setYdStoreId(node.getNodeId());
                    this.getAllNodeId(cameraMedia);
                }else {
                    ContextUtil.nodeList.add(node);
                }
            }
        }
    }
}