Polyv Help Center

Help Center

Quick Start

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

Prerequisites

Before installing and using the Polyv Workshop Java SDK, ensure that your backend environment meets the following requirements:

image-20200928151641632

image-20201023101627393

1. Add Maven Dependency

Add the following dependency to your 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-seminar-sdk</artifactId>
    <version>2.2.8</version>
</dependency> 

Note: To eliminate verbose Java code, the SDK uses the latest feature of JDK 1.8, Lombok. Please configure Lombok support in IntelliJ or Eclipse.

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

2. Initialize the System

Before executing test code, the backend must initialize the system configuration, including UserId, AppId, and AppSecret. If you do not have this information, refer to the Prerequisites section. The initialization example code is as follows (choose one):

   /**
     * 初始化配置,请配置自己的账号信息
     */
    public static void initPolyvSeminar(){
        String userId = "xxx";
        String appId = "xxx";
        String appSecret = "xxx";
        SeminarGlobalConfig.init(appId, userId, appSecret);
        log.debug("--初始化完成--");
    }
     /**
     * 初始化配置并初始化 HTTP CLIENT 连接池超时时间和最大连接数配置,请配置自己的账号信息
     */
    public static void initPolyvSeminar(){
        String userId = "xxx";
        String appId = "xxx";
        String appSecret = "xxx";        
        Integer timeOut = 20000;  //HTTP CLIENT 连接池超时时间
        Integer maxClientNum = 100;  //HTTP CLIENT 最大连接数      
        SeminarGlobalConfig.init(  appId,  userId,  appSecret,  timeOut ,  maxClientNum);
        log.debug("--初始化完成--");
    }

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

package net.polyv.live.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 appId = "xxx";
        String appSecret = "xxx";
        SeminarGlobalConfig.init(appId,userId,appSecret);
        log.debug("--初始化完成--");
    }
    
    
}

3. Execute Test Code

Test creating a workshop channel. The unit test code is as follows:

import org.junit.Assert;

import com.alibaba.fastjson.JSON;

import lombok.extern.slf4j.Slf4j;
import net.polyv.common.v1.exception.PloyvSdkException;
import net.polyv.seminar.v1.config.SeminarGlobalConfig;
import net.polyv.seminar.v1.entity.channel.SeminarCreateChannelV2Request;
import net.polyv.seminar.v1.entity.channel.SeminarCreateChannelV2Response;
import net.polyv.seminar.v1.service.channel.impl.SeminarChannelServiceImpl;

@Slf4j
public class SeminarChannelDemo {

  /**
   * 调用demo,必须处理PloyvSdkException。
   * <p>
   * 参数合法性校验:SDK采用自定义验证框架对输入参数进行校验,如有参数不合格,将抛出PloyvSdkException异常,exception的message
   * 包括具体校验不通过的字段信息,此异常是运行时异常,必须捕获处理相关业务逻辑;
   * <p>
   * 解析返回数据:解析返回数据,如SDK调用正常成功,将封装响应对象,正常返回,如服务器返回错误信息,SDK将将抛出PloyvSdkException异常,exception的message
   * 包括具体服务器执行错误信息,此异常是运行时异常,必须捕获处理相关业务逻辑;
   * @param args
   */
  public static void main(String[] args) {
        //全局初始化,此处应该全局执行一次
        String userId = "xxx";
        String appId = "xxx";
        String appSecret = "xxx";
        SeminarGlobalConfig.init(appId, userId, appSecret);
        log.debug("--初始化完成--");
        try {
          //封装API请求对象
          SeminarCreateChannelV2Request seminarCreateChannelV2Request = new SeminarCreateChannelV2Request();
          seminarCreateChannelV2Request.setName("测试研讨会创建") //设置频道主题信息
                  .setSeminarHostPassword("666888") //研讨会主持人密码
                  .setSeminarAttendeePassword("888888"); //研讨会参会人密码
          //调用SDK请求保利威服务器
          SeminarCreateChannelV2Response seminarCreateChannelV2Response =
                  new SeminarChannelServiceImpl().createChannelV2(
                          seminarCreateChannelV2Request);
          Assert.assertNotNull(seminarCreateChannelV2Response);
          //正常返回做B端正常的业务逻辑
          if (seminarCreateChannelV2Response != null) {
            //to do something ......
            log.debug("研讨会频道创建成功 {}", JSON.toJSONString(seminarCreateChannelV2Response));
            log.debug("入会地址:https://meet.polyv.net/?channelId={}, 主持人登录密码:{}, 参会人登录密码:{}",
                    seminarCreateChannelV2Response.getChannelId(),
                    seminarCreateChannelV2Request.getSeminarHostPassword(),
                    seminarCreateChannelV2Request.getSeminarAttendeePassword());
            log.debug("观众观看地址:https://live.polyv.cn/watch/{}", seminarCreateChannelV2Response.getChannelId());
          }
        } 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:

[main] DEBUG net.polyv.common.v1.base.HttpUtil - http 请求 url: https://api.polyv.net/live/v4/channel/create?requestId=2c272a5abc194d84bc0269bec4ea7395&appId=frlr1zazn3&sign=823E7D930DC34877F557076A892C1C64&timestamp=1644995639858 , 请求参数: {"appId":"frlr1zazn3","name":"测试研讨会创建","newScene":"seminar","requestId":"2c272a5abc194d84bc0269bec4ea7395","seminarAttendeePassword":"888888","seminarHostPassword":"666888","sign":"823E7D930DC34877F557076A892C1C64","timestamp":"1644995639858"}
[main] DEBUG net.polyv.common.v1.base.HttpUtil - http 请求结果: {"code":200,"status":"success","requestId":"bd4fbb48e79149e88f5225751a64ec7b.72.16449956414666319","data":{"channelId":2820970,"userId":"1b448be323","scene":null,"channelPasswd":null,"seminarHostPassword":"666888","seminarAttendeePassword":"888888"},"success":true}
[main] DEBUG cn.timelost.spring.SeminarChannelDemo - 研讨会频道创建成功 {"channelId":"2820970","seminarAttendeePassword":"888888","seminarHostPassword":"666888","userId":"1b448be323"}

You can also log in to the official website to verify whether the creation was successful:

image-2022-02-16_15-19-29.png

At this point, the backend has completed the installation and configuration of the Polyv Workshop Java SDK and can use the Workshop SDK for further development and testing. If you encounter any issues during the backend integration process, please use the Online Customer Service button in the lower right corner to contact after-sales technical support. Provide the runtime environment, operation steps, error feedback information, and contact details to facilitate quick problem identification and resolution.

联系客服,在线咨询