# 直播推流小程序开发

#### 小程序主要界面：

![login](https://6941759-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmV4PIbrO79lRJl9HCeLg%2Fuploads%2Fgit-blob-f7e8a233ffe29eae787ebc8b7b2bab362176435d%2F%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180330154514-168x300.png?alt=media) ![setting](https://6941759-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmV4PIbrO79lRJl9HCeLg%2Fuploads%2Fgit-blob-59b464bc1751d32c3247c2e8c34204f1c0ba51b5%2F%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180330154522-168x300.png?alt=media) ![push](https://6941759-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmV4PIbrO79lRJl9HCeLg%2Fuploads%2Fgit-blob-9a48cde6e8156e93d1dbff7971374be05c321426%2F%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180330154723-168x300.jpg?alt=media)

#### 开发前准备

1.小程序微信开发者后台设置-开发设置-服务器域名中配置 \[request合法域名] ![https](https://6941759-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmV4PIbrO79lRJl9HCeLg%2Fuploads%2Fgit-blob-1f8e803ec79376f4ecf3ea10101132b840eb7545%2F%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180330155224.png?alt=media) 2.小程序微信开发者后台设置-接口设置中打开实时播放音视频流、实时录制音视频流开关 ![switch](https://6941759-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FmV4PIbrO79lRJl9HCeLg%2Fuploads%2Fgit-blob-5102b51138feee56a628b159444a16e860611a8e%2F%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20180330155640.png?alt=media)

#### 接口说明

### 接口一：获取推流地址

#### 接口url

<https://live.polyv.net/api/v2/teacher\\_login.json>

#### 请求方式

POST

#### 请求参数

| 参数名       | 是否必选 | 类型     | 说明          |
| --------- | ---- | ------ | ----------- |
| passwd    | true | string | md5(频道密码)   |
| sign      | true | string | 签名          |
| timestamp | true | string | 当前13位毫秒级时间戳 |
| number    | true | string | 频道号         |
| account   | true | string | 频道号         |

#### 规则

1、passwd规则：md5(password) 示例： password(频道密码): 461666 passwd = md5(461666) = aeb0e56d32d841cbc52b0ed18721167e

2、sign规则：md5("live.polyv.net" + channelId + passwd + timestamp) 示例： channelId:153884 passwd: aeb0e56d32d841cbc52b0ed18721167e timestamp: 1516327146366 sign = md5(live.polyv.net153884aeb0e56d32d841cbc52b0ed18721167e1516327146366) sign = 32046e6a4bab8d95de9e5bc6fc4630e7

请求成功后需要用到的字段解释：

```json
{
	url: "rtmp://push2.videocc.net/recordfe/"  //推流域名
	stream："16ad889b3d20180118174258966" //流名
}
```

推流地址获取规则：url + stream； 示例：rtmp\://push2.videocc.net/recordfe/16ad889b3d20180118174258966

### 接口二：设置频道名称

#### 接口url

<https://api.live.polyv.net/v1/channels/{channelId}/update>

#### 请求方式

POST

#### 请求参数

| 参数名       | 是否必选 | 类型     | 说明          |
| --------- | ---- | ------ | ----------- |
| name      | true | string | 要修改的名字      |
| sign      | true | string | 签名          |
| ptime     | true | string | 当前13位毫秒级时间戳 |
| channelId | true | string | 频道号         |

#### 规则

大写的MD5值： "APPCHANNELSET" + "channelId=" + channelId + "name=" + name + "APPCHANNELSET"

示例：str = APPCHANNELSETchannelId=153884name=小程序推流测试testAPPCHANNELSET Md5(str) = 03395ed7f948a6f8cc63a5eeba21ccb7 注意：转成大写 sign = 03395ED7F948A6F8CC63A5EEBA21CCB7

返回结果

```json
{
	status: "success", 
	result: "update channel successfully"
}
```

### 接口三：获取聊天室观众人数

#### 接口url

<https://api.chat.polyv.net/front/listUsers>

#### 请求方式

GET

#### 请求参数

| 参数名    | 是否必选 | 类型     | 说明  |
| ------ | ---- | ------ | --- |
| roomId | true | string | 频道号 |

返回结果

```json
{
	count: 0,  //在线人数
	userlist: [] //在线用户列表
}
```

### [推流小程序sdk下载](https://git.polyv.net/help-center/document-center/-/blob/master/third_res/front/push.zip)
