Polyv Help Center

Help Center

Quick Start

Updated: 2026-03-18 14:08:21

Prerequisites

Before installing and using the Polyv Video-on-Demand Java SDK, ensure the B-end has the following environment:

Dingtalk_20210402101606

1. Add Maven Dependency

Add the following dependency to the project's POM file:

Note: Due to network restrictions of the Maven Central Repository, the Alibaba Cloud Maven proxy repository may fail to find dependencies. It is recommended to use the central repository: https://repo1.maven.org/maven2/

<dependency>
    <groupId>net.polyv</groupId>
    <artifactId>polyv-java-vod-sdk</artifactId>
    <version>2.2.8</version>
</dependency> 

Note: To eliminate verbose Java code, the SDK uses the Lombok framework. Please configure Lombok support in IntelliJ or Eclipse.

<dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>1.18.16</version>
</dependency>

2. Initialize the System

Before executing test code, the B-end needs to initialize system configuration, including userId and secretKey. If you do not have this information, please refer to the Prerequisites section. The initialization example code is as follows, choose one:

   /**
     * 初始化配置,请配置自己的账号信息
     */
    public static void initPolyvVod(){
        String userId = "xxx";
        String secretKey = "xxx";
        VodGlobalConfig.init(userId, secretKey);
        log.debug("--初始化完成--");
    }
     /**
     * 初始化配置并初始化 HTTP CLIENT 连接池超时时间和最大连接数配置,请配置自己的账号信息
     */
    public static void initPolyvVod(){
        String userId = "xxx";
        String secretKey = "xxx";
        Integer timeOut = 20000;  //HTTP CLIENT 连接池超时时间
        Integer maxClientNum = 100;  //HTTP CLIENT 最大连接数      
        VodGlobalConfig.init(userId, secretKey, timeOut, maxClientNum);
        log.debug("--初始化完成--");
    }
     /**
     * 初始化配置并初始化 HTTP CLIENT 代理信息,一般使用在正式服务器不能连接外网,必须通过代理连接,请配置自己的账号信息
     */
    public static void initPolyvVod(){
        String userId = "xxx";
        String appSecret = "xxx";        
        String hostName = '127.0.0.1';  //代理的ip
        int port = 8888;  //代理的端口      
        String scheme = 'http';  //  代理的协议    
        VodGlobalConfig.init(userId,  appSecret,  hostName,  port,  scheme);
        log.debug("--初始化完成--");
    }

The above code is typically configured in a global initialization that runs once when the system starts. If using the Spring framework, refer to the following:

package net.polyv.vod.config;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import lombok.extern.slf4j.Slf4j;

/**
 * 默认启动配置类
 * @author: thomas
 **/
@Slf4j
@Component
public class StartupListener implements ApplicationContextAware {
    
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        String userId = "xxx";
        String secretKey = "xxx";
        VodGlobalConfig.init(userId, secretKey);
        log.debug("--初始化完成--");
    }
    
    
}

3. Execute Test Code

Test retrieving user space and traffic information. The unit test code is as follows:

package net.polyv.vod.v1.service;

import java.util.Calendar;

import org.junit.Assert;

import com.alibaba.fastjson.JSON;

import lombok.extern.slf4j.Slf4j;
import net.polyv.common.v1.exception.PloyvSdkException;
import net.polyv.vod.v1.config.VodGlobalConfig;
import net.polyv.vod.v1.entity.account.VodAccountSpaceDataRequest;
import net.polyv.vod.v1.entity.account.VodAccountSpaceDataResponse;
import net.polyv.vod.v1.service.account.impl.VodAccountServiceImpl;
import net.polyv.vod.v1.util.VodSignUtil;

/**
 * @author: sadboy
 **/
@Slf4j
public class VodVideoDemo {

  /**
   * 调用demo,必须处理PloyvSdkException。
   *
   * 参数合法性校验:SDK采用自定义验证框架对输入参数进行校验,如有参数不合格,将抛出PloyvSdkException异常,exception的message
   * 包括具体校验不通过的字段信息,此异常是运行时异常,必须捕获处理相关业务逻辑;
   *
   * 解析返回数据:解析返回数据,如SDK调用正常成功,将封装响应对象,正常返回,如服务器返回错误信息,SDK将将抛出PloyvSdkException异常,exception的message
   * 包括具体服务器执行错误信息,此异常是运行时异常,必须捕获处理相关业务逻辑;
   * @param args
   */
  public static void main(String[] args) {
    String userId = "xxx";
    String secretKey = "xxx";
    VodGlobalConfig.init(userId, secretKey);
    log.debug("--初始化完成--");
    try {
      Calendar instance = Calendar.getInstance();
      instance.set(2020, 10, 13);
      VodAccountSpaceDataRequest vodAccountSpaceDataRequest = new VodAccountSpaceDataRequest();
      VodAccountSpaceDataResponse vodAccountSpaceDataResponse;
      vodAccountSpaceDataRequest.setDate(instance.getTime());
      vodAccountSpaceDataResponse = new VodAccountServiceImpl().getAccountSpaceFlow(vodAccountSpaceDataRequest);
      Assert.assertNotNull(vodAccountSpaceDataResponse);
      if (vodAccountSpaceDataResponse != null) {
        log.debug("测试获取用户空间及流量情况成功,{}", JSON.toJSONString(vodAccountSpaceDataResponse));
      }
    } catch (PloyvSdkException e) {
      //参数校验不合格 或者 请求服务器端500错误,错误信息见PloyvSdkException.getMessage()
      log.error(e.getMessage(), e);
      // 异常返回做B端异常的业务逻辑,记录log 或者 上报到ETL 或者回滚事务
    } catch (Exception e) {
      log.error("SDK调用异常", e);
    }
  }

}

After executing the code, the console should output the following key information, indicating successful integration:

2021-04-02 11:31:46:670 +0800 [main] DEBUG net.polyv.common.v1.base.HttpUtil - http 请求 url: https://api.polyv.net/v2/user/1b448be323/main , 请求参数: {"date":"2020-11-13","requestId":"f8a5283094714cb58d9aeefa5e00b1b0","sign":"216C1386579861008123892F76C83E28A8D7564E","ptime":"1617334306444"}
2021-04-02 11:31:47:320 +0800 [main] DEBUG net.polyv.common.v1.base.HttpUtil - HTTP请求耗时分析,请求URL: https://api.polyv.net/v2/user/1b448be323/main , 请求头信息:[{"elements":[{"name":"application/x-www-form-urlencoded","parameterCount":1,"parameters":[{"name":"charset","value":"UTF-8"}]}],"name":"Content-type","value":"application/x-www-form-urlencoded; charset=UTF-8"},{"elements":[{"name":"1b448be323","parameterCount":0,"parameters":[]}],"name":"java-sdk-user-id","value":"1b448be323"},{"elements":[{"name":"JAVA_VOD_SDK","parameterCount":0,"parameters":[]}],"name":"User-Agent","value":"JAVA_VOD_SDK"},{"elements":[{"name":"JAVA_VOD_SDK","parameterCount":0,"parameters":[]}],"name":"source","value":"JAVA_VOD_SDK"},{"elements":[{"name":"1.0.25","parameterCount":0,"parameters":[]}],"name":"version","value":"1.0.25"}] ,   耗时: 556 ms
2021-04-02 11:31:47:322 +0800 [main] DEBUG net.polyv.common.v1.base.HttpUtil - http 请求结果: {"code":200,"status":"success","message":"success","data":{"videoCount":43,"totalFlow":21474836480,"usedSpace":0,"usedFlow":0,"totalSpace":21474836480,"userId":"1b448be323","email":"sdk-demo@polyv.net"}}
2021-04-02 11:31:47:367 +0800 [main] DEBUG net.polyv.vod.v1.service.VodVideoDemo - 测试获取用户空间及流量情况成功,{"email":"sdk-demo@polyv.net","totalFlow":21474836480,"totalSpace":21474836480,"usedFlow":0,"usedSpace":0,"userId":"1b448be323"}

At this point, the B-end has completed the installation and configuration of the Polyv Video-on-Demand Java SDK and can use the VOD SDK for other feature development and testing. If you encounter any issues during the B-end integration process, directly use online customer service to contact after-sales technical support. Please provide the runtime environment, operation steps, error feedback, and contact information simultaneously to facilitate quick problem identification and resolution.

联系客服,在线咨询