本文介绍互动PaaS服务端SDK的集成方法。

SDK获取

目前测试阶段,通过压缩包形式提供SDK,后续通过Maven地址引入SDK。

模块初始化

  1. 增加依赖。
    在服务端应用的pom.xml文件中添加如下依赖:
    <dependency>
      <groupId>com.aliyun</groupId>
      <artifactId>live_interaction20201214</artifactId>
      <version>2.1.0</version>
    </dependency>
  2. 服务初始化
    // 配置实例初始化
    Config authConfig = new Config();
    
    // 阿里云账号信息,需要修改为自己的账号
    authConfig.accessKeyId = "LTAI***gJDwUJ";
    authConfig.accessKeySecret = "6D5ZkE7k**O778";
    
    // 后端服务域名
    authConfig.endpoint = "live-interaction.aliyuncs.com";
  3. 创建房间
    public class TestCreateRoom {
    
          public static void main(String[] args) throws Throwable{
            // 1. 创建Config实例并初始化
            Config authConfig = new Config();
            authConfig.accessKeyId = "LTA***wUJ";
            authConfig.accessKeySecret = "6D5***778";
            authConfig.endpoint = "live-interaction.aliyuncs.com";
    
              // 2. 构造请求
              Client authClient = new Client(authConfig);
            CreateRoomRequest.CreateRoomRequestRequest requestRequest = new CreateRoomRequest.CreateRoomRequestRequest();
            requestRequest.setDomain("此处填写AppId");
            requestRequest.setOwnerId("test_ownerId");
            requestRequest.setTitle("test_title");
            requestRequest.setOwnerNick("test_owner_nick");
              CreateRoomRequest request = new CreateRoomRequest();
            request.setRequest(requestRequest);
    
              // 3. 执行操作
            CreateRoomResponse response = authClient.createRoom(request);
            CreateRoomResponseBody body = response.getBody();
            System.out.println(body.getSuccess());
            System.out.println(body.getResult().getRoomId());
        }
    }
  4. 销毁房间
    public class TestDestroyRoom {
    
        public static void main(String[] args) throws Throwable{
            // 1. 创建Config实例并初始化
            Config authConfig = new Config();
            authConfig.accessKeyId = "LTA***wUJ";
            authConfig.accessKeySecret = "6D5***778";
            authConfig.endpoint = "live-interaction.aliyuncs.com";
    
            // 2. 构造请求
            Client authClient = new Client(authConfig);
            DestroyRoomRequest.DestroyRoomRequestRequest requestRequest = new DestroyRoomRequest.DestroyRoomRequestRequest();
            requestRequest.setDomain("此处填写AppId");
            requestRequest.setRoomId("test_roomId");
            requestRequest.setOpenId("test_openId");
            DestroyRoomRequest request = new DestroyRoomRequest();
            request.setRequest(requestRequest);
    
            // 3. 执行操作
            DestroyRoomResponse response = authClient.destroyRoom(request);
            DestroyRoomResponseBody body = response.getBody();
            System.out.println(body.getSuccess());
            System.out.println(body.getResult());
        }
    }