> For the complete documentation index, see [llms.txt](https://polyv.gitbook.io/document/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://polyv.gitbook.io/document/docs/live/api/web/watch-condition/set_watch_condition.md).

# 修改频道观看条件

### 接口描述

```
1、修改频道或通用设置的观看条件（旧版直播后台-通用设置-观看条件）
2、主要观看条件为关闭时，次要观看条件不能为打开，否则返回参数错误
3、主要观看条件和次要观看条件为相同时，不能够同时打开，否则返回参数错误
4、（channelId, timestamp, appId）参与sign签名，并和sign一起通过url传递，请求体参数不参与签名，通过post请求体传递【请设置请求头contentType:application/json】
5、接口支持https协议
```

### 接口URL

```
http://api.polyv.net/live/v3/channel/auth/update
```

[在线API调用](https://git.polyv.net/help-center/document-center/-/blob/master/req.html?api=http:/api.polyv.net/live/v3/channel/auth/update/README.md)

### 请求方式

```
POST
```

### 接口约束

1、接口同时支持HTTP 、HTTPS ，建议使用HTTPS 确保接口安全，接口调用有频率限制，[详细请查看](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/limit/README.md)

### 请求参数描述

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

### 请求体参数描述

| 参数名          | 必选   | 类型    | 说明                                                                                                                                                                     |
| ------------ | ---- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| authSettings | true | Array | 观看条件设置 【详见[authSettings字段说明](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/web/watch_condition/set_watch_condition.md?id=authSettings字段说明)】 |

#### authSettings字段说明

| 参数名                   | 必选    | 类型      | 说明                                                                                                                                                                                                                                                                                                                             |
| --------------------- | ----- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| rank                  | true  | Integer | 主要观看条件为1，次要观看条件为2                                                                                                                                                                                                                                                                                                              |
| enabled               | true  | String  | <p>是否开启条件观看<br>N：关闭<br>Y：开启</p>                                                                                                                                                                                                                                                                                                |
| authType              | false | String  | <p>pay：付费观看<br>code：验证码观看<br>phone：白名单观看 注：需确认对应rank的白名单是否存在，否则需要先调用<a href="https://git.polyv.net/help-center/document-center/-/blob/master/live/api/web/watch_condition/add_white_list/README.md">增加频道单个白名单</a>新增再设置观看条件<br>info：登记观看<br>custom：自定义授权观看<br>external：外部授权观看<br>direct：独立授权观看<br>public: 公开观看<br>wx:微信授权观看</p> |
| wxAuthExpireValue     | false | String  | authType为wx时，对应的微信授权值，支持以d和h为单位，例如3d表示3天，3h表示3小时                                                                                                                                                                                                                                                                               |
| payAuthTips           | false | String  | 当authType为pay时，设置参数，必填。欢迎语标题                                                                                                                                                                                                                                                                                                   |
| price                 | false | Float   | 当authType为pay时，设置参数，必填。价格，单位为元                                                                                                                                                                                                                                                                                                 |
| watchEndTime          | false | String  | 当authType为pay时，设置参数，非必填。付费有效截止日期，格式：yyyy-MM-dd HH:mm                                                                                                                                                                                                                                                                           |
| validTimePeriod       | false | Integer | 当authType为pay时，设置参数，非必填。付费有效时长，单位天。当watchEndTime和validTimePeriod都为空时，表示付费永久有效                                                                                                                                                                                                                                                  |
| authCode              | false | String  | 当authType为code时，设置参数，必填。验证码                                                                                                                                                                                                                                                                                                    |
| qcodeTips             | false | String  | 当authType为code时，设置参数，非必填。提示文案                                                                                                                                                                                                                                                                                                  |
| qcodeImg              | false | String  | 当authType为code时，设置参数，非必填。公众号二维码地址                                                                                                                                                                                                                                                                                              |
| authTips              | false | String  | 当authType为phone时，设置参数，非必填。提示文案                                                                                                                                                                                                                                                                                                 |
| infoFields            | false | Array   | 当authType为info时，设置参数，必填。登记观看信息，上限为5个【详见[infoFields字段说明](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/web/watch_condition/set_watch_condition.md?id=infoFields字段说明)】                                                                                                                                |
| infoAuthTips          | false | String  | 当authType为info时，设置参数，非必填。欢迎标题                                                                                                                                                                                                                                                                                                  |
| infoDesc              | false | String  | 当authType为info时，设置参数，非必填。提示信息                                                                                                                                                                                                                                                                                                  |
| infoEntryText         | false | String  | 当authType为info时，设置参数，非必填。入口文本                                                                                                                                                                                                                                                                                                  |
| externalKey           | false | String  | 当authType为external时，设置参数，必填。SecretKey                                                                                                                                                                                                                                                                                          |
| externalUri           | false | String  | 当authType为external时，设置参数，必填。自定义url                                                                                                                                                                                                                                                                                             |
| externalRedirectUri   | false | String  | 当authType为external时，设置参数，非必填。跳转地址                                                                                                                                                                                                                                                                                              |
| externalButtonEnabled | false | String  | 当authType为external时，设置参数，非必填.登录按钮。Y为开启，N为关闭。开启后用户访问链接时，引导页面将显示登录按钮                                                                                                                                                                                                                                                             |
| customKey             | false | String  | 当authType为custom时，设置参数，必填。SecretKey                                                                                                                                                                                                                                                                                            |
| customUri             | false | String  | 当authType为custom时，设置参数，必填。自定义url                                                                                                                                                                                                                                                                                               |
| directKey             | false | String  | 当authType为direct时，设置参数，必填。独立授权SecretKey                                                                                                                                                                                                                                                                                        |
| directKey             | false | String  | 当authType为direct时，设置参数，必填。独立授权SecretKey                                                                                                                                                                                                                                                                                        |
| privacyStatus         | false | String  | Y/N 隐私声明开关                                                                                                                                                                                                                                                                                                                     |
| privacyContent        | false | String  | 隐私内容，支持富文本                                                                                                                                                                                                                                                                                                                     |
| onceWhitelistEnabled  | false | String  | 白名单不允许重复使用，默认为N，Y:是、N:否                                                                                                                                                                                                                                                                                                        |

#### infoFields字段说明

| 参数名         | 必选    | 类型     | 说明                                                                                                   |
| ----------- | ----- | ------ | ---------------------------------------------------------------------------------------------------- |
| name        | false | String | 当authType为info时，设置参数，非必填。登记信息名，最多为20字符                                                               |
| type        | false | String | <p>当authType为info时，设置参数，必填。登记类型<br>name：姓名<br>text：文本<br>mobile：手机号码<br>number：数字<br>option：下拉选项</p> |
| options     | false | String | 当authType为info时，设置参数，非必填。下拉选项时，下拉的选项值，以英文逗号分割。选项个数上限为8个；选项内容最多为8字符                                   |
| placeholder | false | String | 当authType为info时，设置参数，非必填。文本框输入提示，最多为50字符                                                             |
| sms         | false | String | 当authType为info时，设置参数，非必填。短信验证开关，Y：开启，N：关闭                                                            |

### 示例

```requestUrl
http://api.polyv.net/live/v3/channel/auth/update?appId=frlr1zazn3&sign=E2B692768C6F467B1228B5876625B71E&channelId=2191532&timestamp=1621843761626
```

请求体参数

```json
{
	"authSettings": [{
		"rank": 1,
		"enabled": "Y",
		"authType": "pay",
		"payAuthTips": "给钱才能看",
		"price": "0.01",
		"watchEndTime": null,
		"validTimePeriod": null
	}, {
		"rank": 2,
		"enabled": "N"
	}]
}
```

### 响应参数描述

| 参数名     | 类型      | 说明                                                                                                                               |
| ------- | ------- | -------------------------------------------------------------------------------------------------------------------------------- |
| code    | Integer | 响应状态码，200为成功返回，非200为失败【详见[全局错误说明](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/errorInfo/README.md)】 |
| status  | String  | 响应状态文本信息                                                                                                                         |
| message | String  | 响应描述信息，当code为400或者500的时候，辅助描述错误原因                                                                                                |
| data    | String  | 成功时为true，错误时为空                                                                                                                   |

### Java请求示例

快速接入基础代码请下载相关依赖源码， [点击下载源代码](https://git.polyv.net/help-center/document-center/-/blob/master/third_res/util.zip) ,下载后加入到自己的源码工程中即可。测试用例中的**HttpUtil.java 和 LiveSignUtil.java** 都包含在下载文件中。

> 强烈建议您使用[直播Java SDK](https://git.polyv.net/help-center/document-center/-/blob/master/live/java/README.md)完成API的功能对接，直播Java SDK 对API调用逻辑、异常处理、数据签名、HTTP请求线程池进行了统一封装和优化。

```java
private static final Logger log = LoggerFactory.getLogger(WatchConditionTest.class);
/**
 * 修改频道观看条件
 * @throws IOException
 */
@Test
public void testSetWatchCondition() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId=super.appId;
    String appSecret=super.appSecret;
    String userId = super.userId;
    String timestamp=String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = "http://api.polyv.net/live/v3/channel/auth/update";
    String channelId = "2191532";
    String body = "{\"authSettings\":[{\"rank\":1,\"enabled\":\"N\"},{\"rank\":2,\"enabled\":\"N\"}]}";

    //http 调用逻辑
    Map<String,String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp",timestamp);

    requestMap.put("channelId",channelId);

    requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
    url = HttpUtil.appendUrl(url, requestMap);
    String response = HttpUtil.postJsonBody(url, body, null);
    log.info("测试修改频道观看条件接口返回值：{}",response);
    //do somethings

}
```

### 响应示例

系统全局错误说明详见[全局错误说明](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/errorInfo/README.md)

成功示例

```json
{
	"code": 200,
	"status": "success",
	"message": "",
	"data": true
}
```

异常示例

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