# 获取一次性的观看页地址

### 接口URL

```javascript
https://api.polyv.net/live/v3/channel/watch/get-token-watch-url
```

### 接口说明

```javascript
1、获取一次性的观看页观看地址URL
2、接口支持https协议
```

### 请求方式

```javascript
GET POST
```

### 请求参数

| 参数名       | 必选 | 类型     | 说明                                                                                                                                                                                                        |
| --------- | -- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| appId     | 是  | string | 从API设置中获取，在直播系统登记的appId                                                                                                                                                                                   |
| channelId | 是  | int    | 频道ID                                                                                                                                                                                                      |
| sign      | 是  | String | 签名，为32位大写的MD5值,`生成签名的appSecret密钥作为通信数据安全的关键信息，严禁保存在客户端直接使用，所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据`【详见[签名生成规则](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/buildSign/README.md)】 |
| timestamp | 是  | long   | 当前13位毫秒级时间戳，3分钟内有效                                                                                                                                                                                        |

### 响应成功JSON示例：

```javascript
{
	"code": 200,
	"status": "success",
	"message": "",
	"data": "https://live1.polyv.cn/watch/450698?token=8b01210642bd4c0589cf6c2a09506399"
}
```

### 响应失败JSON示例：

未输入appId

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

appId不正确

```json
{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}
```

时间戳错误

```json
{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}
```

签名错误

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

### 字段说明

| 参数名     | 说明                                      |
| ------- | --------------------------------------- |
| code    | 请求状态响应码                                 |
| status  | 请求状态                                    |
| message | 错误信息                                    |
| data    | 一次性的观看地址url ,生成的url的有效期为一个小时，一旦使用过就失效了。 |

### php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'channelId' => $channelId
);

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

$url = "https://api.polyv.net/live/v3/channel/watch/get-token-watch-url?".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;
?>
```
