获取账号连麦分钟数使用量与剩余量

接口URL

http://api.polyv.net/live/v3/channel/statistics/mic/get-duration

接口说明

(接口调用有频率限制,详细请查看)

1、获取账号连麦使用情况
2、接口支持https

返回结果支持格式

JSON

请求方式

GET

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 当前13位毫秒级时间戳,3分钟内有效
sign string 签名,为32位大写的MD5值

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "available": -279,
        "history": 279
    }
}

响应失败JSON示例:

未输入appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId不正确

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

时间戳错误

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

签名错误

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

字段说明

参数名 类型 说明
code int 响应代码,成功为200,失败为400,签名错误为401,异常错误500
status string 成功为success,失败为error
message string 错误时为错误提示消息
data object 响应结果集
available int 可用连麦分钟数,单位分钟
history int 历史已使用连麦分钟数,单位分钟

Java请求示例

public static void main(String[] args) {
        String url = "http://api.polyv.net/live/v3/channel/statistics/mic/get-duration";
        // 用户对应的appId和加密串
        String appId = "xxxxxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxx";
        Map<String, String> params = new HashMap<>();
        PolyvTool.setLiveSign(params, appId, appSecret);
        // 调用Polyv的httpClient工具类发送请求
        String content = HttpClientUtil.getInstance()
                .sendHttpGet(url + "?" + PolyvTool.mapJoinNotEncode(params));
        System.out.println(content);
    }

签名规则(PolyvTool.java文件代码查看)

https://dev.polyv.net/2020/liveproduct/l-api/rule/live-api-java-detail/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

分页获取连麦情况使用详情

接口URL

http://api.polyv.net/live/v3/channel/statistics/mic/list

接口说明

(接口调用有频率限制,详细请查看)

1、分页获取连麦详情数据
2、支持账号、批量频道获取详情数据
3、接口支持https

返回结果支持格式

JSON

请求方式

GET

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 当前13位毫秒级时间戳,3分钟内有效
sign string 签名,为32位大写的MD5值
page int 当前页,默认1
size int 每页数据大小,默认10,最大值300
channelIds string 频道号,使用英文逗号分开,如:100000,100001
startDay string 开始时间,格式:yyyy-MM-dd
endDay string 结束时间,格式:yyyy-MM-dd

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "pageSize": 10,
        "pageNumber": 2,
        "totalItems": 11,
        "contents": [
            {
                "userId": "ee7fe7fbda",
                "channelId": 372228,
                "currentDay": "2019-10-25",
                "history": 3
            }
        ],
        "startRow": 11,
        "firstPage": false,
        "lastPage": true,
        "prePageNumber": 1,
        "limit": 1,
        "totalPages": 2,
        "endRow": 11,
        "nextPageNumber": 2,
        "offset": 10
    }
}

响应失败JSON示例:

未输入appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId不正确

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

时间戳错误

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

签名错误

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

时间格式错误

{
    "code": 400,
    "status": "error",
    "message": "param is not date normal format",
    "data": ""
}

分页参数错误

{
    "code": 400,
    "status": "error",
    "message": "param is not digit: page",
    "data": ""
}

字段说明

参数名 类型 说明
code int 响应代码,成功为200,失败为400,签名错误为401,异常错误500
status string 成功为success,失败为error
message string 错误时为错误提示消息
data object 响应结果集
pageNumber int 当前的页数
totalItems int 总的条数
contents array 查询的结果列表
userId string 用户userId
channelId int 频道号
currentDay string 当天
history int 使用连麦分钟数,单位:分钟
firstPage boolean 是否为第一页,值为:true/false
lastPage boolean 是否为最后一页,值为:true/false
nextPageNumber int 下一页编号
prePageNumber int 上一页编号
totalPages int 总页数
startRow int 当前页第一个数量的位置
endRow int 当前页最后一个数量的位置
limit int 每页数量大小

Java请求示例

public static void main(String[] args) {
        String url = "http://api.polyv.net/live/v3/channel/statistics/mic/list";
        // 用户对应的appId和加密串
        String appId = "fbixrsybs6";
        String appSecret = "019328f5e5f14f24a0e8d3403bac8f17";
        // 查询频道号
        String startDay = "2019-10-25";
        String endDay = "2020-11-25";
        String page = "1";
        String size = "10";
        String channelIds = "100000,100001";
        Map<String, String> params = new HashMap<>();
        params.put("channelIds", channelIds);
        params.put("size", size);
        params.put("page", page);
        params.put("endDay", endDay);
        params.put("startDay", startDay);
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        // 调用Polyv的httpClient工具类发送请求
        String content = HttpClientUtil.getInstance()
                .sendHttpGet(url + "?" + PolyvTool.mapJoinNotEncode(params));
        System.out.println(content);
    }

签名规则(PolyvTool.java文件代码查看)

https://dev.polyv.net/2020/liveproduct/l-api/rule/live-api-java-detail/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

创建重制课件任务

接口URL

https://api.polyv.net/live/v3/channel/pptRecord/addRecordTask

接口说明

(接口调用有频率限制,详细请查看)

1、接口用于创建重制课件任务, 需等候任务队列执行完成,不是实时重制
2、接口支持https

返回结果支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前毫秒级时间戳
sign string 签名值
channelId int 频道号
videoId string 回放视频id

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": ""
}

响应字段说明

参数名 说明
code 状态码,成功为200,签名失败为403,参数错误为400,服务端错误为500
status 成功为success,错误时为error
message 成功为"",错误时为错误描述信息
data 响应数据

响应失败JSON示例:

参数错误

{
    "code": 400,
    "status": "error",
    "message": "param validate error",
    "data": ""
}

未输入appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId不正确

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

时间戳错误

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

签名错误

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

非法频道号

{
    "code": 403,
    "status": "error",
    "message": "illegal channel id: %s",
    "data": ""
}

回放视频不存在

{
    "code": 400,
    "status": "error",
    "message": "playback video not exist",
    "data": ""
}

不能重制的视频,例如不是三分屏

{
    "code": 400,
    "status": "error",
    "message": "invalid playback video",
    "data": ""
}

回放时长限制,例如视频时长大于6个小时

{
    "code": 400,
    "status": "error",
    "message": "playback duration limited",
    "data": ""
}

视频已经重制过

{
    "code": 400,
    "status": "error",
    "message": "this ppt record task already exist",
    "data": ""
}

java请求示例

public void testAddRecordTask() {
        String url = "https://api.polyv.net/live/v3/channel/pptRecord/addRecordTask";
        // appId和加密串
        String appId = "xxxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxxxx";
        String videoId = "abc";
        int channelId = 123;
        Map<String, String> params = new HashMap<>();
        params.put("videoId", videoId);
        params.put("channelId", String.valueOf(channelId));
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        String content = HttpClientUtil.getInstance()
                .sendHttpPost(url, params);
        System.out.println(content);
}

签名规则及工具文件代码

https://dev.polyv.net/2020/liveproduct/l-api/rule/live-api-java-detail/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

获取账号或频道转播列表信息

接口URL

https://api.polyv.net/live/v3/channel/transmit/get-associations

接口说明

(接口调用有频率限制,详细请查看)

1、接口用于获取账号或频道下的转播列表信息
2、接口支持https

返回结果支持格式

JSON

请求方式

GET

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前毫秒级时间戳
sign string 签名值
channelId int 频道号,如果不传,则查询appId对应的账号下所有转播频道关联关系

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": [
        {
            "channelId": 1853794,
            "receiveChannelId": 1853782
        },
        {
            "channelId": 1852725,
            "receiveChannelId": 1853044
        }
    ]
}

响应字段说明

参数名 说明
code 状态码,成功为200,签名失败为403,参数错误为400,服务端错误为500
status 成功为success,错误时为error
message 成功为"",错误时为错误描述信息
data 响应数据
data[0].channelId 发起转播频道号,如果一个接收转播频道没有关联主频道,则该值为null
data[0].receiveChannelId 接收转播频道号

响应失败JSON示例:

参数错误

{
    "code": 400,
    "status": "error",
    "message": "param validate error",
    "data": ""
}

未输入appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId不正确

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

时间戳错误

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

签名错误

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

非法频道号

{
    "code": 403,
    "status": "error",
    "message": "illegal channel id: %s",
    "data": ""
}

java请求示例

public void testGetAssociations() {
        String url = "https://api.polyv.net/live/v3/channel/transmit/get-associations";
        // appId和加密串
        String appId = "xxxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxx";
        // 如果不传频道号,则查询当前appId对应的账号下所有的转播频道关联关系
        int channelId = 123;
        Map<String, String> params = new HashMap<>();
        params.put("channelId", String.valueOf(channelId));
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        String content = HttpClientUtil.getInstance()
                .sendHttpGet(url + "?" +  PolyvTool.mapJoinNotEncode(params));
        System.out.println(content);
}

签名规则及工具文件代码

https://dev.polyv.net/2020/liveproduct/l-api/rule/live-api-java-detail/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

API使用需知

保利威API接口整个域名api.polyv.net都对单个ip在10s内不能超过1500次的限制。如超出限制请求频率的访问会被阻断5分钟。为此,需要广大API集成使用者,在API接口集成调用时,避免在限制条件内,频繁调用API接口,从而影响正常服务。
以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

批量创建子频道

接口URL

http://api.polyv.net/live/v3/channel/account/batch-create

接口说明

(接口调用有频率限制,详细请查看)

1、批量创建子频道,子频道角色支持guest(嘉宾,只支持三分屏场景)、assistant(助教)
2、接口支持https

返回结果支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 当前13位毫秒级时间戳,3分钟内有效
sign string 签名,为32位大写的MD5值
channelId int 频道号

请求体参数

参数名 必选 类型 说明
role string 默认不传为助教,传Guest为嘉宾
nickname string 创建的助教或嘉宾昵称
passwd string 子频道密码
actor string 创建的助教或嘉宾头衔
avatar string 创建的助教或嘉宾头像

请求体信息示例

[
    {
        "role":"guest",
        "nickname": "嘉宾",
        "passwd": 123456
    },
    {
        "role":"assistant",
        "nickname": "助教",
        "passwd": 123456
    }
]

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": [
        {
            "account": "00111765203",
            "userId": "ee7fe7fbda",
            "channelId": 1765203,
            "passwd": "1",
            "nickname": "测试嘉1宾",
            "stream": "kcwz3qy4",
            "status": "Y",
            "createdTime": 1595398549000,
            "lastModified": 1595398549000,
            "channelSessionId": null,
            "sort": 11,
            "avatar": "//s1.videocc.net/default-img/avatar/guest.png",
            "actor": "嘉宾",
            "pageTurnEnabled": "N",
            "notifyEnabled": "N",
            "checkinEnabled": "Y",
            "voteEnabled": "N",
            "lotteryEnabled": "N",
            "role": "guest",
            "chatListEnabled": "Y",
            "chatAuditEnabled": "N",
            "monitorEnabled": "N",
            "roundTourEnabled": "N",
            "watchLockEnabled": "N",
            "loginUrl": "https://live.polyv.net/web-start/login?channelId=00111765203"
        }
    ]
}

响应失败JSON示例:

未输入appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId不正确

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

时间戳错误

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

签名错误

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

频道号格式错误

{
  "code": 400, 
  "status": "error", 
  "message": "param is not digit: dsadasd", 
  "data": ""
}

子频道角色错误

{
    "code": 400,
    "status": "error",
    "message": "invalid account role type",
    "data": ""
}

格式化json错误

{
    "code": 500,
    "status": "fail",
    "message": "undefined error",
    "data": null
}
{
    "code": 400,
    "status": "error",
    "message": "json format error",
    "data": ""
}

字段说明

参数名 类型 说明
code int 响应代码,成功为200,失败为400,签名错误为401,异常错误500
status string 成功为success,失败为error
message string 错误时为错误提示消息
account int 助教ID
userId string 用户ID
channelId int 频道ID
passwd string 助教密码
nickname string 助教名称
stream string 助教流名(单独使用无效)
status string 助教状态
createdTime long 创建助教时间
lastModified long 助教最后修改时间
sort int 频道中所有助教序号
avatar string 助教头像
pageTurnEnabled string 助教翻页权限(只能一个助教有)
notifyEnabled string 发布公告权限
checkinEnabled string 开启签到权限
voteEnabled string 发起投票
role string 子频道角色
loginUrl string 子账号(嘉宾)登陆地址

Java请求示例

public static void main(String[] args) {
        String url = "http://api.polyv.net/live/v3/channel/account/batch-create";
        // 用户对应的appId和加密串
        String appId = "xxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxxxxxxxxx";
        // 查询频道号
        String channelId = "1796673";
        Map<String, String> params = new HashMap<>();
        params.put("channelId", channelId);
        String reqBody = "[{\"role\":\"guest\",\"nickname\": \"测试嘉1宾\",\"passwd\": 1}]";
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        // 调用Polyv的httpClient工具类发送请求
        String content = HttpClientUtil.getInstance()
                .sendHttpPostJson(url + "?" + PolyvTool.mapJoinNotEncode(params), reqBody, null);
        System.out.println(content);
    }

签名规则(PolyvTool.java文件代码查看)

https://dev.polyv.net/2020/liveproduct/l-api/rule/live-api-java-detail/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

获取频道一定时间范围之内的历史最高并发人数

接口URL

旧接口,最小粒度支持天

https://api.polyv.net/live/v3/channel/statistics/get-max-history-concurrent

接口说明

(接口调用有频率限制,详细请查看)

1、获取频道一定时间范围之内的历史最高并发人数,粒度可以支持到分钟
2、接口支持https

返回结果支持格式

JSON

请求方式

GET

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 当前13位毫秒级时间戳,3分钟内有效
sign string 签名,为32位大写的MD5值
channelId int 频道号
startTime long 开始时间13位毫秒级时间戳
endTime long 结束时间13位毫秒级时间戳

响应成功JSON示例:

{
    "code": 200, 
    "status": "success", 
    "message": "", 
    "data": 0
}

响应失败JSON示例:

未输入appId

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

appId不正确

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

时间戳错误

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

签名错误

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

频道号格式错误

{
  "code": 400, 
  "status": "error", 
  "message": "param is not digit: dsadasd", 
  "data": ""
}

日期范围错误

{
  "code": 400, 
  "status": "error", 
  "message": "date range error", 
  "data": ""
}

字段说明

参数名 说明
code 响应代码,成功为200,失败为400,签名错误为401,异常错误500
status 成功为success,失败为error
message 错误时为错误提示消息
data 日期区间内最大的历史并发人数

Java请求示例

private static void testBasic() {
        String url = "https://api.polyv.net/live/v3/channel/statistics/get-max-history-concurrent";
        // 用户对应的appId和加密串
        String appId = "xxxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        // 查询频道号
        String channelId = "415174";

        Map<String, String> params = new HashMap<>();
        params.put("channelId", channelId);
        params.put("startTime", String.valueOf(System.currentTimeMillis()));
        params.put("endTime", String.valueOf(System.currentTimeMillis()));
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        // 调用Polyv的httpClient工具类发送请求
        String content = HttpClientUtil.getInstance()
                .sendHttpGet(url + "?" + PolyvTool.mapJoinNotEncode(params));
        System.out.println(content);
    }

签名规则(PolyvTool.java文件代码查看)

https://dev.polyv.net/2020/liveproduct/l-api/rule/live-api-java-detail/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

JAVA调用直播接口详述

一、userId、appId、appSecret值的获取

developer
在直播管理后台,点击开发设置,在显示的页面中获取userId、appId、appSecret值。

二、sign生成规则

将请求所需所有参数按照参数名字典顺序排列,连接参数名与参数值,并在首尾加上appSecret,然后计算MD5,将MD5结果转为16进制、大写字母,作为sign。

三、Java 接口调用示例

1、接口请求示例

private static void testBasic() {
        String url = "http://api.polyv.net/live/v3/channel/basic/get";
        // 用户对应的appId和加密串
        String appId = "xxxxxxx";
        String appSecret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
        // 查询频道号
        String channelId = "415174";

        Map<String, String> params = new HashMap<>();
        params.put("channelId", channelId);
        // 调用Polyv的工具类方法设置sign
        PolyvTool.setLiveSign(params, appId, appSecret);
        // 调用Polyv的httpClient工具类发送请求
        String content = HttpClientUtil.getInstance()
                .sendHttpGet(url + "?" + PolyvTool.mapJoinNotEncode(params));
        System.out.println(content);
    }

2、生成sign结果示例

// 请求参数(这里为频道号)
channelId = "415174";
// appId和appSecret
appId = "egyszbtsd58";
appSecret = "6ef8d34c08f44e91a18e28d42ff0da7e";
// 时间戳
timeStamp = "1594369061376";
// 拼接后字符串
6ef8d34c08f44e91a18e28d42ff0da7eappIdegyszbtsd58channelId415174timestamp15943690613766ef8d34c08f44e91a18e28d42ff0da7e
// 加密串
7DEDD50579ECB5E5062954DBA10ADCA1

四、Java sign签名生成工具类

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * polyv工具类
 */
public class PolyvTool {

    /**
     * 获取加密串
     */
    public static void setLiveSign(Map<String, String> params, String appId, String key) {
        params.put("sign", getSign(params, appId, key));
    }

    /**
     * 获取加密串
     */
    public static String getSign(Map<String, String> params, String appId, String key) {
        params.put("appId", appId);
        params.put("timestamp", String.valueOf(System.currentTimeMillis()));
        // 处理参数,计算MD5哈希值
        String concatStr = concatParams(params);
        String plain = key + concatStr + key;
        System.out.println("request signStr=" + plain);
        String encrypted = md5Hex(plain);
        // 32位大写MD5值
        return encrypted.toUpperCase();
    }

    /**
     * 把数组所有元素排序,并按照“参数参数值”的模式成字符串,用于计算MD5哈希值
     * @param params 需要排序并参与字符拼接的参数组
     * @return 拼接后字符串
     */
    public static String concatParams(Map<String, String> params) {
        List<String> keys = new ArrayList<>(params.keySet());
        Collections.sort(keys);

        StringBuilder sb = new StringBuilder();
        for (String key : keys) {
            String value = params.get(key);
            if (isBlank(value)) {
                continue;
            }
            sb.append(key).append(value);
        }
        return sb.toString();
    }

    /**
     * 对字符串做MD5加密,返回加密后的字符串。
     * @param text 待加密的字符串。
     * @return 加密后的字符串。
     */
    public static String md5Hex(String text) {
        try {
            MessageDigest messageDigest = MessageDigest.getInstance("MD5");
            byte[] inputByteArray = text.getBytes();
            messageDigest.update(inputByteArray);
            byte[] resultByteArray = messageDigest.digest();
            return byteArrayToHex(resultByteArray).toLowerCase();
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }

    /**
     * 将字节数组换成成16进制的字符串
     * @param byteArray 字节
     * @return 字符串
     */
    public static String byteArrayToHex(byte[] byteArray) {
        // 初始化一个字符数组用来存放每个16进制字符
        char[] hexDigits = {'0','1','2','3','4','5','6','7','8','9', 'A','B','C','D','E','F' };
        // new一个字符数组,这个就是用来组成结果字符串的(一个byte是八位二进制,也就是2位十六进制字符(2的8次方等于16的2次方))
        char[] resultCharArray =new char[byteArray.length * 2];
        // 遍历字节数组,通过位运算(位运算效率高),转换成字符放到字符数组中去
        int index = 0;
        for (byte b : byteArray) {
            resultCharArray[index++] = hexDigits[b>>> 4 & 0xf];
            resultCharArray[index++] = hexDigits[b& 0xf];
        }
        // 字符数组组合成字符串返回
        return new String(resultCharArray);
    }


    /**
     * url 参数串连但是不进行参数Encode
     * @param map map
     * @return string
     */
    public static String mapJoinNotEncode(Map<String, String> map) {
        StringBuilder stringBuilder = new StringBuilder();
        int i = 0;
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (isBlank(value)) {
                continue;
            }
            if (0 != i) {
                stringBuilder.append("&");
            }
            stringBuilder.append(key).append("=").append(map.get(key));
            i++;
        }
        return stringBuilder.toString();
    }

    /**
     * url 参数串连
     * @param map map
     * @param keyLower keyLower
     * @param valueUrlEncode valueUrlEncode
     * @return string
     */
    public static String mapJoin(Map<String, String> map, boolean keyLower, boolean valueUrlEncode) {
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (isBlank(value)){
                continue;
            }

            try {
                String temp = (key.endsWith("_") && key.length() > 1) ? key.substring(0, key.length() - 1) : key;
                stringBuilder.append(keyLower ? temp.toLowerCase() : temp)
                        .append("=")
                        .append(valueUrlEncode ? URLEncoder.encode(value, "utf-8").replace("+", "%20") : value)
                        .append("&");
            } catch (UnsupportedEncodingException e) {
                System.out.println(e.getMessage());
            }
        }
        if (stringBuilder.length() > 0) {
            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        }
        return stringBuilder.toString();
    }

    /**
     * 判断字符是否为空
     * @param cs 字符
     * @return true/false
     */
    public static boolean isBlank(CharSequence cs) {
        int strLen;
        if (cs != null && (strLen = cs.length()) != 0) {
            for(int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }

            return true;
        } else {
            return true;
        }
    }
}

五、Java http请求调用工具类

注:该工具类仅为示例(非必须),客户可以按照自己的方式进行接口请求,如需在生产环境使用该工具类,客户需按需进行httpClient的一些配置优化

1、使用该工具类需要引入apache的工具包,下面提供该工具包的maven引用方式

<dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>4.5</version>
</dependency>
<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpmime</artifactId>
  <version>4.5</version>
</dependency>

2、http请求工具类代码

import java.io.File;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.net.ssl.SSLContext;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.HttpClientUtils;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.util.EntityUtils;

/**
 * httpclient的操作实现类
 */
public class HttpClientUtil {

    private static final String QUESTION_MARK = "?";
    private static final String DEFAULT_ENCODING = "UTF-8";
    private static final String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
    public static final String APPLICATION_FORM_URLENCODED_VALUE = "application/x-www-form-urlencoded";

    private final RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(10000).setConnectTimeout(10000)
            .setConnectionRequestTimeout(10000).build();

    private static HttpClientUtil instance = null;

    private HttpClient ignoreSslClient;

    private HttpClient client;

    private HttpClientUtil() {
        this.ignoreSslClient = createHttpsClient(true);
        this.client = createHttpsClient(false);
    }

    public static HttpClientUtil getInstance() {
        if (instance == null) {
            instance = new HttpClientUtil();
        }
        return instance;
    }

    private HttpClient getHttpClient(boolean ignoreSsl) {
        return ignoreSsl ? ignoreSslClient : client;
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @return 请求结果
     */
    public String sendHttpPost(String httpUrl) {
        HttpPost httpPost = new HttpPost(httpUrl);
        return sendHttpPost(httpPost);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param params 参数(格式:json格式的内容)
     * @param headers 请求头
     * @return 请求结果
     */
    public String sendHttpPostJson(String httpUrl, String params, Map<String, String> headers) {
        return sendHttpPostJson(httpUrl, params, headers, false);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param params 参数(格式:json格式的内容)
     * @param headers 请求头
     * @param ignoreSsl 是否跳过证书校验,true为跳过 false为不跳过
     * @return 请求结果
     */
    public String sendHttpPostJson(String httpUrl, String params, Map<String, String> headers, boolean ignoreSsl) {
        // 创建httpPost
        HttpPost httpPost = new HttpPost(httpUrl);
        try {
            // 设置参数
            StringEntity stringEntity = new StringEntity(params, DEFAULT_ENCODING);
            stringEntity.setContentType(APPLICATION_JSON_UTF8_VALUE);
            httpPost.setEntity(stringEntity);
            if (null != headers && headers.size() > 0) {
                for (String name : headers.keySet()) {
                    httpPost.addHeader(name, headers.get(name));
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return sendHttpRequest(httpPost, ignoreSsl);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param maps 参数
     * @param body 请求体
     * @return 请求结果
     */
    public String sendHttpPost(String httpUrl, Map<String, String> maps, String body) {
        String paramStr = PolyvTool.mapJoinNotEncode(maps);
        if (null != paramStr) {
            paramStr = QUESTION_MARK + paramStr;
        }
        String urlStr = httpUrl + paramStr;
        HttpPost httpPost = new HttpPost(urlStr);
        try {
            StringEntity entity = new StringEntity(body, DEFAULT_ENCODING);
            entity.setContentType(APPLICATION_JSON_UTF8_VALUE);
            httpPost.setEntity(entity);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return sendHttpRequest(httpPost, true);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param params 参数(格式:key1=value1&key2=value2)
     * @return 请求结果
     */
    public String sendHttpPost(String httpUrl, String params) {
        return sendHttpPostWithHeader(httpUrl, params, null);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param headers 头
     * @param params 参数(格式:key1=value1&key2=value2)
     * @return 请求结果
     */
    public String sendHttpPostWithHeader(String httpUrl, String params, Header[] headers) {
        HttpPost httpPost = new HttpPost(httpUrl);
        try {
            if (null != headers) {
                httpPost.setHeaders(headers);
            }
            // 设置参数
            StringEntity stringEntity = new StringEntity(params, DEFAULT_ENCODING);
            stringEntity.setContentType(APPLICATION_FORM_URLENCODED_VALUE);
            httpPost.setEntity(stringEntity);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return sendHttpPost(httpPost);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param maps 参数
     * @return 请求结果
     */
    public String sendHttpPost(String httpUrl, Map<String, String> maps) {
        return sendHttpPostWithHeader(httpUrl, maps, null);
    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param maps 参数
     * @return 请求结果
     */
    public String sendHttpPostWithHeader(String httpUrl, Map<String, String> maps, Header[] headers) {
        HttpPost httpPost = new HttpPost(httpUrl);
        if (null != headers) {
            httpPost.setHeaders(headers);
        }
        // 创建参数队列
        List<NameValuePair> nameValuePairs = new ArrayList<>();
        for (String key : maps.keySet()) {
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));
        }
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, DEFAULT_ENCODING));
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return sendHttpPost(httpPost);
    }

    /**
     * 发送 get请求
     * @param httpUrl 地址
     * @param headers 请求头
     * @return 请求结果
     */
    public String sendHttpGet(String httpUrl, Map<String, String> headers) {
        // 创建httpGet
        HttpGet httpGet = new HttpGet(httpUrl);
        try {
            if (null != headers && headers.size() > 0) {
                for (String name : headers.keySet()) {
                    httpGet.addHeader(name, headers.get(name));
                }
            }
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return sendHttpGet(httpGet);
    }

    /**
     * 发送 post请求(带文件)
     * @param httpUrl 地址
     * @param maps 参数
     * @param fileLists 附件
     * @return 请求结果
     */
    public String sendHttpPost(String httpUrl, Map<String, String> maps, List<File> files, String fileParamName) {
        HttpPost httpPost = new HttpPost(httpUrl);
        MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create();
        // 设置此参数后可以保证服务器拿到的文件名不会出现乱码
        meBuilder.setMode(HttpMultipartMode.RFC6532);
        for (String key : maps.keySet()) {
            meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN));
        }
        for (File file : files) {
            FileBody fileBody = new FileBody(file);
            fileParamName = (null == fileParamName) ? "files" : fileParamName;
            meBuilder.addPart(fileParamName, fileBody);
        }
        HttpEntity reqEntity = meBuilder.build();
        httpPost.setEntity(reqEntity);
        return sendHttpPost(httpPost);
    }

    /**
     * 发送 post请求(带文件)
     * @param httpUrl 地址
     * @param maps 参数
     * @param file 上传文件
     * @param fileParamName 上传文件参数名
     */
    private static String sendHttpPost(String httpUrl, Map<String, String> maps, File file, String fileParamName) {
        fileParamName = (null == fileParamName) ? "file" : fileParamName;
        return sendHttpPost(httpUrl, maps, file, fileParamName);
    }

    /**
     * 发送Post请求
     * @param httpPost post请求
     * @return 请求结果
     */
    private String sendHttpPost(HttpPost httpPost) {
        return sendHttpRequest(httpPost);
    }

    /**
     * 发送 get请求
     * @param httpUrl 请求的路径
     * @return 成功时为响应内容,失败时为 null
     */
    public String sendHttpGet(String httpUrl) {
        // 创建get请求
        HttpGet httpGet = new HttpGet(httpUrl);
        return sendHttpGet(httpGet);
    }

    /**
     * 发送DELETE请求
     * @param httpUrl 请求的路径
     * @return 成功时为响应内容,失败时为 null
     */
    public String sendHttpDelete(String httpUrl) {
        HttpDelete httpDelete = new HttpDelete(httpUrl);
        return sendHttpRequest(httpDelete);
    }

    /**
     * 发送 get请求Https
     * @param httpUrl 请求的路径
     * @param ignoreSSLCerts 是否忽略证书校验
     */
    public String sendHttpsGet(String httpUrl, boolean ignoreSslCerts) {
        HttpGet httpGet = new HttpGet(httpUrl);
        return sendHttpsGet(httpGet, ignoreSslCerts);
    }

    /**
     * 发送Get请求
     * @param httpGet 请求
     * @return 成功时为响应内容,失败时为 null
     */
    private String sendHttpGet(HttpGet httpGet) {
        return sendHttpRequest(httpGet);
    }

    /**
     * 发送Get请求
     * @param requestBase 请求
     * @return 成功时为响应内容,失败时为 null
     */
    private String sendHttpRequest(HttpRequestBase requestBase) {
        return sendHttpRequest(requestBase, false);
    }

    /**
     * 发送请求
     * @param requestBase 请求
     * @param ignoreSslCerts 忽略证书和域名校验
     * @return 成功时为响应内容,失败时为 null
     */
    private String sendHttpRequest(HttpRequestBase requestBase, boolean ignoreSslCerts) {
        HttpResponse response = null;
        HttpEntity entity;
        try {
            // 创建默认的httpClient实例.
            requestBase.setConfig(requestConfig);
            // 执行请求
            response = getHttpClient(ignoreSslCerts).execute(requestBase);
            entity = response.getEntity();
            return EntityUtils.toString(entity, DEFAULT_ENCODING);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        return null;
    }

    /**
     * 发送Get请求Https
     * ignoreSSLCerts参数为true可以忽略证书和域名的校验,可以避免 {@link sun.security.validator.ValidatorException}
     * @param httpGet 使用https发送get请求
     * @param ignoreSSLCerts 忽略证书和域名校验
     * @return 返回内容
     */
    private String sendHttpsGet(HttpGet httpGet, boolean ignoreSslCerts) {
        HttpResponse response = null;
        String responseContent = null;
        try {
            httpGet.setConfig(requestConfig);
            // 执行请求
            response = getHttpClient(ignoreSslCerts).execute(httpGet);
            HttpEntity entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, DEFAULT_ENCODING);
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
            HttpClientUtils.closeQuietly(response);
        }
        return responseContent;
    }

    /**
     * 初始化https请求Client
     * @param ignoreSSLCerts 忽略证书
     */
    private CloseableHttpClient createHttpsClient(boolean ignoreSslCerts) {
        CloseableHttpClient httpClient;
        if (ignoreSslCerts) {
            SSLContext ctx = null;
            try {
                // 忽略客户端证书校验
                ctx = new SSLContextBuilder().loadTrustMaterial(null, (chain, authType) -> true).build();
            } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
                System.out.println("create ssl context error");
            }

            // 忽略证书和hostName校验
            httpClient = HttpClients.custom()
                    .setSSLHostnameVerifier((host, session) -> true)
                    .setSSLSocketFactory(new SSLConnectionSocketFactory(ctx)).build();
        } else {
            httpClient = HttpClients.createDefault();
        }
        return httpClient;
    }


以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

查询频道回调设置接口

接口URL

https://api.polyv.net/live/v3/channel/callback/get-setting

接口说明

(接口调用有频率限制,详细请查看)

1、接口用于查询频道回调设置接口
3、接口支持https

请求方式

GET

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 当前13位当前时间戳,3分钟有效
sign string 签名值,32位大写MD5值
channelId int 频道ID

响应成功JSON示例:

// 查询成功
{
  "code": 200,
  "status": "success",
  "message": "",
  "data": {
    "recordCallbackUrl": "url",
    "playbackCallbackUrl": "url",
    "streamCallbackUrl": "url",
    "liveScanCallbackUrl": "url",
    "recordCallbackVideoType": "url",
    "playbackCacheCallbackUrl": "url",
    "pptRecordCallbackUrl": "url",
    "globalSettingEnabled": "N"
  }
}

字段说明

字段 说明
recordCallbackUrl 录制生成回调URL
playbackCallbackUrl 录制视频转存成功回调URL
streamCallbackUrl 流状态回调URL
liveScanCallbackUrl 直播内容审核回调URL
recordCallbackVideoType 录制回调的视频类型,多个视频类型用,分隔
playbackCacheCallbackUrl 回放缓存生成成功的回调URL
pptRecordCallbackUrl 课件重制成功回调URL
globalSettingEnabled 是否应用全局设置开关,Y走用户回调设置,N走频道设置

响应失败JSON示例:

// 签名错误
{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
// 未输入appId
{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}
// appId不正确
{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}
// 时间戳错误
{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}
// 频道非法
{
    "code": 400,
    "status": "error",
    "message": "illegal channel id: xxx",
    "data": ""
}

字段说明

参数名 说明
code 响应代码,成功为200,失败为400,签名错误为403,异常错误500
status 成功为success,失败为error
message 错误时为错误提示消息
data 成功修改信息

php请求示例

<?php
//引用config.php
include 'config.php';

$params = array(
  'appId' => "填写获取到的appId",
  'timestamp' => "填写13位时间戳",
  'channelId' => "填写频道号"
);

//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
$params["sign"] = $sign;

$url="https://api.polyv.net/live/v3/channel/callback/get-setting";

function post($url, $post_data = '', $timeout = 5){
   $ch = curl_init();
   curl_setopt ($ch, CURLOPT_URL, $url);
   curl_setopt ($ch, CURLOPT_POST, 1);
   if($post_data != ''){
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   }

   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
   curl_setopt($ch, CURLOPT_HEADER, false);
   $file_contents = curl_exec($ch);
   curl_close($ch);
   return $file_contents;
}

echo post($url, $params);
?>

签名规则(config.php文件代码查看)

http://dev.polyv.net/2018/liveproduct/l-api/rule/sign/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...

设置频道回调设置

接口URL

https://api.polyv.net/live/v3/channel/callback/update-setting

接口说明

(接口调用有频率限制,详细请查看)

1、接口用于修改频道回调设置接口
2、接口支持https
3、如频道需要跟随用户设置,可以调用设置频道默认项开关接口

请求方式

POST

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 当前13位毫秒级时间戳,3分钟内有效
sign string 签名,32位大写MD5值
channelId int 频道ID
recordCallbackVideoType string 录制回调文件类型,可选值m3u8或mp4或m3u8,mp4
recordCallbackUrl string 录制回调http(s)地址,需要url编码,如果要清空设置传入空串
playbackCallbackUrl string 转存成功回调http(s)地址,需要url编码,如果要清空设置传入空串
streamCallbackUrl string 流状态回调http(s)地址,需要url编码,如果要清空设置传入空串
pptRecordCallbackUrl string 课件重制成功回调http(s)地址,需要url编码,如果要清空设置传入空串
liveScanCallbackUrl string 直播内容鉴别回调http(s)地址,需要url编码,如果要清空设置传入空串
playbackCacheCallbackUrl string 回放缓存回调http(s)地址,需要url编码,如果要清空设置传入空串

响应成功JSON示例:

// 修改成功
{
    "code": 200,
    "status": "success",
    "message": "",
    "data": null
}

响应失败JSON示例:

// 签名错误
{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
// 未输入appId
{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}
// appId不正确
{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}
// 时间戳错误
{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}
// 频道非法
{
    "code": 400,
    "status": "error",
    "message": "illegal channel id: xxx",
    "data": ""
}
// url非法
{
    "code": 400,
    "status": "error",
    "message": "url invalid:tttt",
    "data": ""
}
// recordCallbackVideoType非法
{
    "code": 400,
    "status": "error",
    "message": "invalid record callback type",
    "data": ""
}

字段说明

参数名 说明
code 响应代码,成功为200,失败为400,签名错误为403,异常错误500
status 成功为success,失败为error
message 错误时为错误提示消息
data 响应数据,这里暂无,为null

php请求示例

<?php
//引用config.php
include 'config.php';

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'channelId' =>  195770,
  'recordCallbackVideoType' => 'm3u8,mp4',
  'recordCallbackUrl' => ''
);

//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
$params['sign'] = $sign;

$url = "http://api.polyv.net/live/v3/channel/playback/set-setting?".http_build_query($params);

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
$res = curl_exec($curl);
curl_close($curl);

echo $res;
?>

签名规则(config.php文件代码查看)

http://dev.polyv.net/2018/liveproduct/l-api/rule/sign/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...