创建直播频道

点击这里查看旧版

接口URL

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

接口说明

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

支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp string 当前时间的秒级时间戳(13位)
sign string 签名,为32位大写的MD5值
userId string 直播账号ID
name string 频道名称
channelPasswd string 频道密码
courseId string 课程号
autoPlay int 是否自动播放,0/1,默认1
playerColor string 播放器控制栏颜色,默认:#666666
scene string 直播场景:
alone 活动拍摄
ppt 三分屏
topclass 大班课

响应成功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
}
}

字段说明

参数名 类型 说明
status string 状态值
result object 响应的结果
channelId string 直播频道ID
userId string 直播用户ID
name string 直播频道名称
description string 直播频道描述
url string 直播推流地址
stream string 直播流名称
logoImage string 播放器logo
logoOpacity int 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 服务器返回的时间戳(毫秒)

php请求示例

<?php

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

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

$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.live.polyv.net/web/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...