快速接入示例
示例代码接入前提条件
在对接保利威直播API功能前,确保B端已经具备如下环境:
安装Java环境。
示例代码支持JDK 1.8或更高版本。
1.报文协议
1.1 Protocol
HTTP 1.0/1.1
1.2 Header
Method: POST
Content-Type = application/json;charset=UTF-8
Accept = application/json;charset=UTF-8
Method: GET
Content-Type = application/json;charset=UTF-8
Accept = application/json;charset=UTF-8
2.添加Maven依赖
将如下依赖加入到项目的POM文件中:
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<httpclient.version>4.5.13</httpclient.version>
<slf4j.version>1.7.30</slf4j.version>
<lombok.version>1.18.16</lombok.version>
<fastjson.version>1.2.70</fastjson.version>
<junit.version>4.12</junit.version>
</properties>
<dependencies>
<!-- 基本工具 -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>${httpclient.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
3.系统基础代码
快速接入基础代码请下载相关依赖源码, 点击下载源代码 ,下载后加入到自己的源码工程中即可。测试用例中的HttpUtil.java 和 LiveSignUtil.java 都包含在下载文件中。
4.执行测试代码
测试依据频道分类ID修改直播频道分类名称,单元测试代码如下:
package net.polyv.live.account;
import net.polyv.LiveBaseTest;
import net.polyv.util.HttpUtil;
import net.polyv.util.LiveSignUtil;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.Map;
public class AccountTest extends LiveBaseTest {
private static final Logger log = LoggerFactory.getLogger(AccountTest.class);
/**
* 修改直播频道分类名称
* @throws IOException
*/
@Test
public void testUpdateCategoryName() throws IOException, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String appId=super.appId;
String appSecret=super.appSecret;
String userId = super.userId;
String timestamp=String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/small-class/xx/xx";
String categoryId = "345134";
String categoryName = "分类234";
//http 调用逻辑
Map<String,String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("timestamp",timestamp);
requestMap.put("categoryId",categoryId);
requestMap.put("categoryName",categoryName);
requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
String response = HttpUtil.postFormBody(url, requestMap);
log.info("测试修改直播频道分类名称,返回值:{}",response);
//do somethings
}
}
执行代码后,控制台应有如下关键输出,表示接入成功:
测试修改直播频道分类名称接口返回值:{"code":200,"status":"success","message":"","data":""}
Last updated
Was this helpful?