xuhy
2026-03-11 f2935d61940b9a156c1bfd99e8f82ebb7fe1370b
监控修改
1个文件已添加
3个文件已修改
118 ■■■■■ 已修改文件
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/MonitorController.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/monitor/DevicePlayerQuery.java 106 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-prod.yml 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/resources/application-test.yml 1 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/MonitorController.java
@@ -4,6 +4,7 @@
import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.query.DevicePageListQuery;
import com.ruoyi.web.controller.tool.monitor.DeviceLiveQuery;
import com.ruoyi.web.controller.tool.monitor.DevicePlayerQuery;
import com.ruoyi.web.controller.tool.monitor.DeviceQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@@ -20,6 +21,8 @@
    private DeviceQuery deviceQuery;
    @Autowired
    private DeviceLiveQuery deviceLiveQuery;
    @Autowired
    private DevicePlayerQuery devicePlayerQuery;
    @ApiOperation(value = "获取监控设备分页列表")
    @PostMapping("/devicePageList")
@@ -35,4 +38,11 @@
        return R.ok(deviceLiveUrl);
    }
    @ApiOperation(value = "获取视频播放操作链接")
    @GetMapping("/getPlayerUrlByDeviceId")
    public R<JSONObject> getPlayerUrlByDeviceId(@RequestParam String deviceId) {
        JSONObject deviceLiveUrl = devicePlayerQuery.getDevicePlayerList(deviceId);
        return R.ok(deviceLiveUrl);
    }
}
ruoyi-admin/src/main/java/com/ruoyi/web/controller/tool/monitor/DevicePlayerQuery.java
New file
@@ -0,0 +1,106 @@
package com.ruoyi.web.controller.tool.monitor;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.redis.service.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.LinkedHashMap;
import java.util.Map;
/**
 * 设备获取摄像机视频播放 WebSDK 链接封装
 */
@Slf4j
@Component
public class DevicePlayerQuery {
    @Value("${qianliyan.config.appId}")
    private String appId;
    @Value("${qianliyan.config.devicePlayerUrl}")
    private String devicePlayerUrl;
    @Value("${qianliyan.config.privateKey}")
    private String privateKey;
    private static final String TOKEN_KEY = "token_key:";
    @Autowired
    private RedisService redisService;
    @Autowired
    private TokenFetcher tokenFetcher;
    public JSONObject getDevicePlayerList(String deviceId) {
        try {
            String token = redisService.getCacheObject(TOKEN_KEY);
            if(!org.springframework.util.StringUtils.hasLength(token)){
                token = tokenFetcher.getToken();
            }
            String timestamp = String.valueOf(System.currentTimeMillis());
            JSONObject requestBody = new JSONObject();
            requestBody.put("deviceId", deviceId);
            String requestBodyStr = requestBody.toString();
            // 2. 计算请求体MD5
            String md5 = DigestUtils.md5Hex(String.valueOf(requestBody));
            // 3. 构建签名字符串
            Map signParams = new LinkedHashMap();
            signParams.put("appid", appId);
            signParams.put("md5", md5);
            signParams.put("timestamp", timestamp);
            signParams.put("token", token);
            signParams.put("version", "1.0.0");
            String jsonString = JSONUtil.toJsonStr(signParams);
            // 4. RSA签名
            byte[] keyBytes = Base64.getDecoder().decode(privateKey);
            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());
            // 5. 发送请求
            String response = HttpRequest.post(devicePlayerUrl)
                    .header("content-type", "application/json")
                    .header("appid", appId)
                    .header("md5", md5)
                    .header("timestamp", timestamp)
                    .header("version", "1.0.0")
                    .header("signature", signatureString)
                    .header("token", token)
                    .body(requestBodyStr)
                    .execute().body();
            System.err.println("Response: " + response);
            JSONObject jsonObject = JSONObject.parseObject(response);
            if ("000000".equals(jsonObject.getString("resultCode"))) {
                log.info("获取摄像机视频播放成功");
                JSONObject data = jsonObject.getJSONObject("data");
                return data;
            } else {
                log.error("获取摄像机视频播放失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("expiresIn", 0);
        jsonObject1.put("url", "");
        return jsonObject1;
    }
}
ruoyi-admin/src/main/resources/application-prod.yml
@@ -234,3 +234,4 @@
    deviceUrl: https://open.qly.cmviot.cn/v3/open/api/device/list
    deviceThumbnailUrl: https://open.qly.cmviot.cn/v3/open/api/camera/thumbnail/realtime
    deviceLiveUrl: https://open.qly.cmviot.cn/v3/open/api/websdk/live
    devicePlayerUrl: https://open.qly.cmviot.cn/v3/open/api/websdk/player
ruoyi-admin/src/main/resources/application-test.yml
@@ -227,3 +227,4 @@
    deviceUrl: https://open.qly.cmviot.cn/v3/open/api/device/list
    deviceThumbnailUrl: https://open.qly.cmviot.cn/v3/open/api/camera/thumbnail/realtime
    deviceLiveUrl: https://open.qly.cmviot.cn/v3/open/api/websdk/live
    devicePlayerUrl: https://open.qly.cmviot.cn/v3/open/api/websdk/player