保利威视polyv的Api调用

官方接口文档

https://dev.polyv.net/2017/videoproduct/v-api/v-api-vmanage/v-api-vmanage-info/get-video-msg/

 

我的服务器调用

	// polyv 提供的服务器间的通讯验证
    private String userid = "";
    // polyv 提供的接口调用签名访问的key
    private String secretkey = "";
    
	// 保利威视服务端Api
    /** 获取单个视频信息 */
    public String queryVideoInfoUrl = "http://api.polyv.net/v2/video/" + userid + "/get-video-msg";

    /**
     * 获取签名
     *
     * @param maps 参数集合
     * @param secureKey api接口密钥
     * @return String 签名
     * @throws Exception 异常信息
     */
    private static String getSign(Map<String, String> maps, String secureKey) throws Exception {
        List<String> keys = new ArrayList<>(maps.keySet());
        List<String> tmp = new ArrayList<>();
        Collections.sort(keys);
        for (String key : keys) {
            if (null != maps.get(key) && maps.get(key).length() > 0) {
                tmp.add(key + "=" + maps.get(key));
            }
        }
        String join = String.join("&", tmp) + secureKey;
        return getSha1(join);
    }

    /**
     * 生成SHA1加密
     *
     * @param input 连接的参数名与参数值,并在尾部加上secretKey
     * @return String SHA1加密
     * @throws NoSuchAlgorithmException 异常信息
     */
    private static String getSha1(String input) throws NoSuchAlgorithmException {
        MessageDigest mDigest = MessageDigest.getInstance("SHA1");
        byte[] result = mDigest.digest(input.getBytes(StandardCharsets.UTF_8));
        StringBuilder sb = new StringBuilder();
        for (int b : result) {
            sb.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));
        }
        return sb.toString().toUpperCase();
    }

    /**
     * 时间(00:00:00)转换为秒
     *
     * @param time 时间00:00:00
     * @return Integer 秒数
     */
    private Integer timeConvertSecond(String time) {
        int second = 0;
        String[] split = time.split(":");
        try {
            int hour = Integer.parseInt(split[0]);
            int minute = Integer.parseInt(split[1]);
            second = Integer.parseInt(split[2]);
            if(hour > 0){
                second += hour * 60 * 60;
            }if( minute > 0){
                second += minute * 60;
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return second;
    }

    /**
     * 获取单个视频信息
     *
     * @param vid 视频ID
     * @return VideoInfoModel 视频信息
     */
    public Object queryVideoInfo(String vid) throws Exception {
        // 获取签名
        Map<String, String> params = new HashMap<>();
        long ptime = System.currentTimeMillis();
        params.put("ptime", Long.toString(ptime));
        params.put("vid", vid);
        params.put("format", "json");
        String sign = getSign(params, secretkey);
        // 请求参数
        Map<String, Object> param = new HashMap<>();
        param.put("vid", vid);
        param.put("ptime", Long.toString(ptime));
        param.put("sign", sign);
        param.put("format", "json");
        // 发送请求(huTool)
        String post = HttpUtil.post(queryVideoInfoUrl, param);
        Map<String, Object> mapParam = JSONObject.parseObject(post);
        List list = (List) mapParam.get("data");
        return list.get(0);
    }

    /**
     * 获取单个视频时长
     *
     * @param vid 视频ID
     * @return 秒数
     */
    public JSONObject queryVideoDuration(String vid) throws Exception {
        JSONObject data = (JSONObject) queryVideoInfo(vid);
        String time = (String) data.get("duration");
        Integer second = timeConvertSecond(time);
        JSONObject timeData = new JSONObject();
        timeData.put("duration", time);
        timeData.put("second", second);
        return timeData;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值