# 创建频道接口

### 接口URL

```
https://api.polyv.net/live/v3/channel/create-cpic-channel
```

### 接口说明

```
1、接口用于创建频道
2、接口支持https
```

### 请求方式

```
POST
```

### 请求参数

| 参数名            | 必选 | 类型     | 说明                                                                                                                                                                                                        |
| -------------- | -- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| appId          | 是  | string | 从API设置中获取，在直播系统登记的appId                                                                                                                                                                                   |
| timestamp      | 是  | long   | 当前13位毫秒级时间戳，3分钟内有效                                                                                                                                                                                        |
| sign           | 是  | String | 签名，为32位大写的MD5值,`生成签名的appSecret密钥作为通信数据安全的关键信息，严禁保存在客户端直接使用，所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据`【详见[签名生成规则](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/buildSign/README.md)】 |
| name           | 是  | string | 频道名称，限制长度为60                                                                                                                                                                                              |
| scene          | 是  | string | 直播场景，三分屏：ppt，普通直播：alone                                                                                                                                                                                   |
| channelObject  | 是  | string | 频道属性，in 对内，out 对外                                                                                                                                                                                         |
| startTime      | 否  | long   | 直播开始时间,13位的时间戳                                                                                                                                                                                            |
| endTime        | 否  | long   | 直播结束时间,13位的时间戳                                                                                                                                                                                            |
| authSecretKey  | 否  | String | 用于请求用户信息的secretKey                                                                                                                                                                                        |
| airUrl         | 否  | String | 用于获取用户信息的自定义接口地址                                                                                                                                                                                          |
| airRedirectUrl | 否  | String | 观众直接访问Polyv观看页，会跳转到该地址                                                                                                                                                                                    |
| coverImage     | 否  | string | 频道的封面图片地址，如果需要上传图片可以先通过上传图片接口：[上传图片资源](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/web/setting/uploadimage/README.md) 得到图片地址用于设置频道的封面图片地址                                    |

### 响应成功JSON示例：

```json
// 创建成功
{
    "code":200,
    "status":"success",
    "message":"",
    "data":{
        "channelId":1830948,
        "passwd":"45a2d6",
        "teacherLoginUrl":"https://live.polyv.net/teacher.html",
        "teacherClientUrl":"https://live.polyv.net/start-client.html?channelId=1830948",
        "watchUrl":"https://live.polyv.cn/watch/1830948",
        "assistant":{
            "passwd":"90983",
            "loginUrl":"https://live.polyv.net/teacher.html",
            "account":"0011830948"
        },
        "guest":{
            "webStartUrl":"https://live.polyv.net/web-start/guest?channelId=0051830948",
            "passwd":"098653",
            "account":"0051830948"
        },
        "authSecretKey":"fp4mt33n3h"
    }
}
```

### 响应失败JSON示例：

```json
// 签名错误
{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
```

```json
// 未输入appId
{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}
```

```json
// appId不正确
{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}
```

```json
// 时间戳错误
{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}
```

```json
// 频道名称是必须
{
    "code": 400,
    "status": "error",
    "message": "channel name is required.",
    "data": ""
}
```

```json
// 频道名称过长
{
    "code": 400,
    "status": "error",
    "message": "channel name is over length.",
    "data": ""
}
```

```json
// channelObject非法
{
    "code": 400,
    "status": "error",
    "message": "channelobject not right.",
    "data": ""
}
```

```json
// 非法的直播场景值
{
    "code": 400,
    "status": "error",
    "message": "scene not right.",
    "data": ""
}
```

```json
// 超过了能创建的频道数的最大值
{
    "code": 400,
    "status": "error",
    "message": "cannot create more than xx channels.",
    "data": ""
}
```

### 字段说明

| 参数名                | 说明                                  |
| ------------------ | ----------------------------------- |
| code               | 响应代码，成功为200，失败为400，签名错误为403，异常错误500 |
| status             | 成功为success，失败为error                 |
| message            | 错误时为错误提示消息                          |
| data               | 响应数据                                |
| channelId          | 频道ID                                |
| passwd             | 频道密码                                |
| teacherLoginUrl    | 主讲登录地址                              |
| teacherClientUrl   | 主讲人客户端启动链接                          |
| watchUrl           | 观看链接                                |
| authSecretKey      | 请求用户信息接口的secretKey                  |
| assistant          | 助教相关信息                              |
| assistant.account  | 助教账号                                |
| assistant.passwd   | 助教密码                                |
| assistant.loginUrl | 助教登录地址                              |
| guest              | 嘉宾相关信息                              |
| guest.account      | 嘉宾账号                                |
| guest.passwd       | 嘉宾密码                                |
| guest.webStartUrl  | 嘉宾登录网页开播端地址                         |

### php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'name' =>  'channel name',
  'channelObjet' => 'in',
  'startTime' => 133333345553,
  'endTime' => 133333345553,
  'coverImage' => 133333345553,
  'scene' => 'alone'  
);

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

$url = "http://api.polyv.net/live/v3/channel/create-cpic-channel?".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;
?>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://polyv.gitbook.io/document/docs/unclassified/2020/9babca9762e5628b1e10d9deae430292.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
