创建直播频道

点击这里查看旧版

接口URL

http://api.polyv.net/live/v2/channels/

接口说明

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

1、作用:创建直播频道
2、接口支持https协议

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp string 当前时间的毫秒级时间戳(13位)
sign string 签名,为32位大写的MD5值
userId string 直播账号ID
name string 频道名称
channelPasswd string 频道密码,长度不能超过16位
courseId string 课程号(参数已废弃,不推荐使用 )
autoPlay int 是否自动播放,0/1,默认1
playerColor string 播放器控制栏颜色,默认:#666666
scene string 直播场景:
alone 直播助手
ppt 云课堂
topclass 大班课
categoryId int 新建频道的所属分类,如果不提交,则为默认分类(分类ID可通过“获取直播分类”接口得到)
maxViewer int 频道的最大在线人数观看限制的人数
watchLayout string 三分屏频道的观看布局,不设置会使用账号的通用设置,取值:ppt 文档为主,video 视频为主
linkMicLimit int 连麦人数; -1:使用账号的连麦人数,范围>=-1,<=账号的连麦人数,最大16人
pureRtcEnabled string 是否为无延时直播,Y 表示开启,默认为N
receive string 是否为接收转播频道,Y 表示是,不填或者填其他值为发起转播频道(注:需要开启频道转播功能该参数才生效)
receiveChannelIds string 接收转播频道号,多个频道号用半角逗号,隔开,如果receive参数值为Y时,此参数无效(注:需要开启频道转播功能该参数才生效)
cnAndEnLiveEnabled string 中英文直播间标识,N不开启中英直播间(默认) 、Y开启中英直播间(scene需要为alone或topclass)
englishSettingEnabled string 英文直播间独立配置,N不开启、Y开启
channelEnglishName string 直播名称英文文案
publisherEnglishName string 主持人名称英文文案

响应成功JSON示例:

{
"code": 200,
"status": "success",
"message": "",
"data":{
"channelId": 100348,
 "userId": "e668hzrydq",
 "name": "myLive3",
 "description": "",
 "url": "rtmp://push2.videocc.net/recordf/",
 "stream": "e668hzrydq20151119102446328",
 "logoImage": "",
 "logoOpacity": 1,
 "logoPosition": "tr",
 "logoHref": "",
 "coverImage": "",
 "coverHref": "",
 "waitImage": "",
 "waitHref": "",
 "cutoffImage": "",
 "cutoffHref": "",
 "advertType": "NONE",
 "advertDuration": 0,
 "advertWidth": 0,
 "advertHeight": 0,
 "advertImage": "",
 "advertHref": "",
 "advertFlvVid": "",
 "advertFlvUrl": "",
 "playerColor": "#00ff0f",
 "autoPlay": true,
 "warmUpFlv": "",
 "passwdRestrict": false,
 "passwdEncrypted": "",
 "isOnlyAudio": "N",
 "isLowLatency": "N",
 "m3u8Url": "http://push2.videocc.net/record/e668hzrydq20151119102446328/playlist.m3u8",
 "m3u8Url1": "",
 "m3u8Url2": "",
 "m3u8Url3": "",
 "currentTimeMillis": 1447981498946,
 "linkMicLimit": 0
 }
}

响应失败JSON示例:

频道密码长度超过16或者含不可见或者非英文ASCII码

{
    "code":400,
    "status":"error",
    "message":"channel passwd illegal.",
    "data":""
}

签名错误

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

创建的频道数量超过限制

{
 "code":400,
 "status":"error",
 "message":"cannot create more than ${账号的频道号数量限制} channels.",
 "data":""
}

receiveChannelIds参数中输入的频道号已经存在关联

{
    "code": 400,
    "status": "error",
    "message": "transmit channel has already associated, channelIds: [xxx, xxx]",
    "data": null
}

receiveChannelIds大于50个或接收转播频道数超出限制,目前一个发起频道只能关联50个接收转播频道

{
    "code": 400,
    "status": "error",
    "message": "transmit channel number limit: 50",
    "data": null
}

两个频道的直播场景不一致,不能生成转播关系

{
    "code": 400,
    "status": "error",
    "message": "two channel live scene are not equals, channelId: xxx,xxx",
    "data": null
}

不是发起转播频道,不能关联接收转播频道

{
    "code": 400,
    "status": "error",
    "message": "not transmit main channel xxx",
    "data": null
}

字段说明

参数名 类型 说明
status string 状态值
result object 响应的结果
channelId string 直播频道ID
userId string 直播用户ID
name string 直播频道名称
description string 直播频道描述
url string 直播推流地址
stream string 直播流名称
logoImage string 播放器logo
logoOpacity float Logo不透明度,1表示完全不透明
logoPosition string Logo位置
logoHref string Logo的跳转链接
coverImage string 播放前显示的封面图
coverHref string 封面图的跳转链接
waitImage string 等待推流时的显示图片
waitHref string 等待推流时显示图片的跳转链接
cutoffImage string 切断流时的显示图片
cutoffHref string 切断流时显示图片的跳转链接
advertType string 广告类型
advertDuration string 广告时长
advertWidth string 广告区域宽度
advertHeight string 广告区域高度
advertImage string 图片广告
advertHref string 广告的跳转链接
advertFlvVid string 视频广告ID
advertFlvUrl string 视频广告链接
playerColor string 播放器控制栏颜色
autoPlay boolean 自动播放
warmUpFlv string 一开始的暖场视频
passwdRestrict boolean 观看密码限制,需要输入观看密码才能播放流
passwdEncrypted string 观看密码加密后的密文
isOnlyAudio string 仅推音频流
isLowLatency string 低延迟
m3u8Url string 直播拉流(播放)m3u8地址
m3u8Url1 string 直播拉流(播放)m3u8地址1
m3u8Url2 string 直播拉流(播放)m3u8地址2
m3u8Url3 string 直播拉流(播放)m3u8地址3
currentTimeMillis timestamp 服务器返回的时间戳(毫秒)
linkMicLimit int 连麦人数
cnAndEnLiveEnabled string 中英文直播间标识,N不开启中英直播间 、Y开启中英直播间

php请求示例

<?php

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

//接口需要的参数(非sign)赋值
$userId = "XXXXXXXX";
$autoPlay = 1;
$name = "内部测试";
$playerColor = "#00ffff";
$channelPasswd = "123456";
$courseId = "123456";
$scene = "alone";

$params = array(
    'appId'=>$appId,
    'autoPlay'=>$autoPlay,
    'name'=>$name,
    'courseId'=>$courseId,
    'playerColor'=>$playerColor,
    'userId'=>$userId,
    'channelPasswd'=>$channelPasswd,
    'scene'=>$scene,
    'timestamp'=>$timestamp
  );

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


$data = array(
'appId' => $appId,
'autoPlay'=>$autoPlay,
'name'=>$name,
'courseId'=>$courseId,
'playerColor'=>$playerColor,
'timestamp'=>$timestamp,
'userId'=>$userId,
'channelPasswd'=>$channelPasswd,
'scene'=>$scene,
'sign'=>$sign
);

$url = "http://api.polyv.net/live/v2/channels";
$ch = curl_init() or die ( curl_error() );
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 360);
$response = curl_exec ( $ch );
curl_close ( $ch );

echo $response;

?>

java请求示例

public class createChanelTest {
    private RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000)
            .setConnectionRequestTimeout(15000).build();
    /**
     * http://live.polyv.net/secure/user/detail.htm
     * http://live.polyv.net/secure/user/app.htm
     */
    private static final String APP_USER_ID = "xxx";
    private static final String APP_ID = "xxx";
    private static final String APP_SECRET = "xxx";
    private static final String CREATE_CHANNEL_URL = "http://api.polyv.net/live/v2/channels/";

    public static void main(String[] args) {
        createChanelTest demo = new createChanelTest();
        demo.createChannelDemo();
    }

    private void createChannelDemo() {
        Map<String, String> params = new HashMap<>();
        params.put("appId", APP_ID);
        params.put("channelPasswd", "12345");
        params.put("name", "创建直播频道测试");
        params.put("scene", "ppt");
        params.put("timestamp", System.currentTimeMillis()+"");
        params.put("userId", APP_USER_ID);
        String sign = this.generateSign(params, APP_SECRET);
        params.put("sign", sign);

        String result = sendHttpPost(CREATE_CHANNEL_URL, params);
        System.out.println("create channel result=" + result);
    }

    public String sendHttpPost(String httpUrl, Map<String, String> maps) {
        HttpPost httpPost = new HttpPost(httpUrl);
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        for (String key : maps.keySet()) {
            nameValuePairs.add(new BasicNameValuePair(key, maps.get(key)));
        }
        try {
            httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return sendHttpPost(httpPost);
    }

    private String sendHttpPost(HttpPost httpPost) {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        HttpEntity entity = null;
        String responseContent = null;
        try {
            httpClient = HttpClients.createDefault();
            httpPost.setConfig(requestConfig);
            response = httpClient.execute(httpPost);
            entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, "UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (response != null) {
                    response.close();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseContent;
    }

    protected String generateSign(Map<String, String> parray, String secretKey) {
        Map<String, String> params = this.paraFilter(parray);
        String concatedStr = this.concatParams(params);
        String plain = secretKey + concatedStr + secretKey;
        String encrypted = MD5Utils.getMD5String(plain);
        String upperCase = encrypted.toUpperCase();
        return upperCase;
    }

    private Map<String, String> paraFilter(Map<String, String> sArray) {
        Map<String, String> result = new HashMap<String, String>();
        if (sArray == null || sArray.size() <= 0) {
            return result;
        }
        for (String key : sArray.keySet()) {
            String value = sArray.get(key);
            if (value == null || value.equals("") || key.equalsIgnoreCase("sign")
                    || key.equalsIgnoreCase("sign_type")) {
                continue;
            }
            result.put(key, value);
        }
        return result;
    }

    private String concatParams(Map<String, String> params) {
        List<String> keys = new ArrayList<String>(params.keySet());
        Collections.sort(keys);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < keys.size(); i++) {
            String key = keys.get(i);
            String value = params.get(key);
            sb.append(key).append(value);
        }
        return sb.toString();
    }
}

java可运行项目下载

点击这里

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

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

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