保利威文档中心

帮助中心

批量创建频道

更新时间:2023-04-04 09:31:23

接口描述

1、批量创建直播频道
2、(timestamp, appId)参与sign签名,并和sign一起通过url传递,请求体参数不参与签名,通过post请求体传递【请设置请求头contentType:application/json】
3、接口支持https协议

接口URL

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

请求方式

POST

接口约束

1、接口同时支持HTTP 、HTTPS ,建议使用HTTPS 确保接口安全,接口调用有频率限制,详细请查看

请求参数描述

参数名 必选 类型 说明
appId true String 账号appId【详见获取密钥
timestamp true Long 当前13位毫秒级时间戳,3分钟内有效
sign true String 签名,为32位大写的MD5值,生成签名的appSecret密钥作为通信数据安全的关键信息,严禁保存在客户端直接使用,所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据【详见签名生成规则

请求体参数描述

参数名 必选 类型 说明
channels true Array 频道列表,每次最多创建100个频道【详见channel字段说明
channel参数描述
参数名 必选 类型 说明
name true String 频道名称
channelPasswd false String 频道密码
courseId false String 课程号
receive false String 是否为接收转播频道,不填或者填其他值为发起转播频道(注:需要开启频道转播功能该参数才生效)
Y:表示是
N:表示否
autoPlay false Integer 是否自动播放,默认1 (注意,如果该值为空,则该频道会使用全局的“功能开关设置”。 如果非空,则会使用频道的“功能开关设置”)
0:自动播放
1:手动播放
playerColor false String 播放器控制栏颜色,默认:#666666
scene false String 直播场景
alone:活动拍摄
ppt:三分屏
topclass:大班课
seminar:研讨会
categoryId false Integer 新建频道的所属分类,如果不提交,则为默认分类(分类ID可通过“查询直播分类”接口得到)
subAccount false String 子账号邮箱,填写时频道会创建在该子账号下(子账号不能被删除或者禁用),暂无法通过接口获取

示例

http://api.polyv.net/live/v3/channel/basic/batch-create?appId=frlr1zazn3&sign=1B76E8026C5F03B92E4725D6835DA57E&timestamp=1636707112481

请求体json参数:

{
    "channels": [
        {
            "name": "测试批量创建频道2(子账号)",
            "channelPasswd": "Hi826g",
            "subAccount": "test-dev@qq.com",
            "categoryId": 391352
        },
        {
            "name": "测试批量创建频道2(主账号)",
            "channelPasswd": "Hi826g",
            "autoPlay": 0,
            "playerColor": "#454545",
            "scene": "ppt",
            "categoryId": 391352
        }
    ]
}

响应参数描述

参数名 类型 说明
code Integer 响应状态码,200为成功返回,非200为失败【详见全局错误说明
status String 响应状态文本信息
message String 响应描述信息,当code为400或者500的时候,辅助描述错误原因
data Object 响应成功时返回批量频道信息【详见data字段说明
Data参数描述
参数名 类型 说明
channels Array 频道内容列表数组【详见channel字段说明
channel参数描述
参数名 类型 说明
channelId String 直播频道号
userId String POLYV用户ID,和保利威官网一致,获取路径:官网->登录->直播(开发设置)
name String 直播频道名称
publisher String 主持人
description String 直播频道描述
url String 直播推流地址
stream String 直播流名称
logoImage String 播放器logo
logoOpacity Float Logo不透明度
1:表示完全不透明
0:表示完全透明
logoPosition String logo位置
tr1:左上
tr:右上
b1:左下
br:右下
logoHref String Logo的跳转链接
coverImage String 播放前显示的封面图
coverHref String 封面图的跳转链接
waitImage String 等待推流时的显示图片
waitHref String 等待推流时显示图片的跳转链接
cutoffImage String 切断流时的显示图片
cutoffHref String 切断流时显示图片的跳转链接
advertType String 片头广告
NONE:无广告
IMAGE:图片
FLV:视频
advertDuration Integer 广告时长(秒)
advertWidth Integer 广告区域宽度(像素)
advertHeight Integer 广告区域高度(像素)
advertImage String 图片广告
advertHref String 广告的跳转链接
advertFlvVid String 视频广告ID
advertFlvUrl String 视频广告链接
playerColor String 播放器控制栏颜色,例如 #666666
autoPlay Boolean 是否自动播放
warmUpFlv String 暖场视频链接
passwdRestrict Boolean 观看密码限制,需要输入观看密码才能播放流
passwdEncrypted String 观看密码加密后的密文
isOnlyAudio String Y:音频模式
N:普通模式
isLowLatency String 低延迟
channelLogoImage String 频道图标
scene String 直播场景
alone:活动拍摄
ppt:三分屏
topclass:大班课
seminar:研讨会
channelViewerPasswd String 参与者密码
channelPasswd String 频道密码
linkMicLimit Integer 连麦人数,-1:使用账号连麦分数,0-16:代表连麦人数
streamType String 直播方式
pureRtcEnabled String 是否是纯rtc拉流
Y:是
N:否
type String 频道类型
发起转播:transmit
接收转播:receive
普通频道:normal
cnAndEnLiveEnabled String 中英文直播间开关
Y:开启
N:关闭
pushEnUrl String 英文推流地址
currentTimeMillis Long 当前时间戳(毫秒)

Java请求示例

快速接入基础代码请下载相关依赖源码点击下载源代码 ,下载后加入到自己的源码工程中即可。测试用例中的HttpUtil.java 和 LiveSignUtil.java 都包含在下载文件中。

强烈建议您使用直播Java SDK完成API的功能对接,直播Java SDK 对API调用逻辑、异常处理、数据签名、HTTP请求线程池进行了统一封装和优化。

private static final Logger log = LoggerFactory.getLogger(ChannelOperateTest.class);
/**
 * 批量创建频道
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testBatchCreateChannels() 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/live/v3/channel/basic/batch-create";
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    url = HttpUtil.appendUrl(url, requestMap);
    
    String password = getRandomString(6);
    String json = "{\"channels\":[{\"name\":\"测试批量创建频道2(子账号)\",\"channelPasswd\":\"%s\"," +
    "\"subAccount\":\"test-dev@qq.com\",\"categoryId\":391352},{\"name\":\"测试批量创建频道2(主账号)\"," +
    "\"channelPasswd\":\"%s\",\"autoPlay\":0,\"playerColor\":\"#454545\",\"scene\":\"ppt\"," +
    "\"categoryId\":391352}]}";
    json = String.format(json, password, password);
    String response = HttpUtil.postJsonBody(url, json, null);
    log.info("测试批量创建频道,返回值:{}", response);
    //do somethings
    
}

响应示例

系统全局错误说明详见全局错误说明

成功示例

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "channels": [
            {
                "channelId": 2671471,
                "userId": "1b448be323",
                "name": "测试批量创建频道2(子账号)",
                "publisher": "主持人",
                "description": "",
                "url": "rtmp://push-d1.videocc.net/recordf/1b448be3231636707115007c115?auth_key=1636708917-0-0-355f0b98f5f93ddc588fcd7770fe07fa",
                "stream": "1b448be3231636707115007c115",
                "logoImage": "https://liveimages.videocc.net/uploaded/images/2021/04/fy3ce1e8uh.png",
                "logoOpacity": 0.37,
                "logoPosition": "tr",
                "logoHref": "",
                "coverImage": "",
                "coverHref": "",
                "waitImage": "",
                "waitHref": "",
                "cutoffImage": "",
                "cutoffHref": "",
                "advertType": "NONE",
                "advertDuration": 0,
                "advertWidth": 0,
                "advertHeight": 0,
                "advertImage": "",
                "advertHref": "",
                "advertFlvVid": "",
                "advertFlvUrl": "",
                "playerColor": "#666666",
                "autoPlay": false,
                "warmUpFlv": "",
                "passwdRestrict": false,
                "passwdEncrypted": "",
                "isOnlyAudio": "N",
                "isLowLatency": "N",
                "m3u8Url": "http://pull-d1.videocc.net/recordf/1b448be3231636707115007c115.m3u8?auth_key=1636707117-0-0-3dc1259df0643a2dc9c61c40b9d17c44",
                "m3u8Url1": "",
                "m3u8Url2": "",
                "m3u8Url3": "",
                "channelLogoImage": "https://liveimages.videocc.net/assets/wimages/pc_images/logo.png",
                "scene": "alone",
                "channelViewerPasswd": null,
                "channelPasswd": "Hi826g",
                "linkMicLimit": 16,
                "streamType": "client",
                "pureRtcEnabled": "N",
                "type": "normal",
                "cnAndEnLiveEnabled": "N",
                "pushEnUrl": null,
                "closeDanmu": "N",
                "currentTimeMillis": 1636707119516
            },
            {
                "channelId": 2671472,
                "userId": "1b448be323",
                "name": "测试批量创建频道2(主账号)",
                "publisher": "主持人",
                "description": "",
                "url": "rtmp://push-d1.videocc.net/recordf/1b448be32316367071173751967?auth_key=1636708919-0-0-2b2602020d19528b19d6374b12fe9263",
                "stream": "1b448be32316367071173751967",
                "logoImage": "https://liveimages.videocc.net/uploaded/images/2021/04/fy3ce1e8uh.png",
                "logoOpacity": 0.37,
                "logoPosition": "tr",
                "logoHref": "",
                "coverImage": "",
                "coverHref": "",
                "waitImage": "",
                "waitHref": "",
                "cutoffImage": "",
                "cutoffHref": "",
                "advertType": "NONE",
                "advertDuration": 0,
                "advertWidth": 0,
                "advertHeight": 0,
                "advertImage": "",
                "advertHref": "",
                "advertFlvVid": "",
                "advertFlvUrl": "",
                "playerColor": "#666666",
                "autoPlay": false,
                "warmUpFlv": "",
                "passwdRestrict": false,
                "passwdEncrypted": "",
                "isOnlyAudio": "N",
                "isLowLatency": "N",
                "m3u8Url": "http://pull-d1.videocc.net/recordf/1b448be32316367071173751967.m3u8?auth_key=1636707119-0-0-19617586a7f61654216cce2c4827cebc",
                "m3u8Url1": "",
                "m3u8Url2": "",
                "m3u8Url3": "",
                "channelLogoImage": "https://liveimages.videocc.net/assets/wimages/pc_images/logo.png",
                "scene": "ppt",
                "channelViewerPasswd": null,
                "channelPasswd": "Hi826g",
                "linkMicLimit": 16,
                "streamType": "client",
                "pureRtcEnabled": "N",
                "type": "normal",
                "cnAndEnLiveEnabled": "N",
                "pushEnUrl": null,
                "closeDanmu": "N",
                "currentTimeMillis": 1636707119516
            }
        ]
    }
}

异常示例

{
    "code": 400,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
联系客服,在线咨询