设置观看条件

接口URL

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

接口说明

1、接口用于设置频道或全局的观看条件
2、主要观看条件为关闭时,次要观看条件不能为打开,否则返回参数错误
3、主要观看条件和次要观看条件为相同时,不能够同时打开,否则返回参数错误
4、接口支持https

支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前时间戳
sign string 签名值
channelId int 频道号,不传为全局设置
authSettings json 请求体中的json数据

注:这里的channelId,appId,timestamp,sign必须通过url传参,json数据通过请求体传参,如:

http://api.polyv.net/live/v3/channel/auth/update?channelId={{channelId}}&appId={{appId}}&timestamp={{timestamp}}&sign={{sign}}

authSettings详细说明

通用参数说明

参数名 必选 类型 说明
rank int 主要观看条件为1,次要观看条件为2
enabled string 是否开启,Y为开启,N为关闭
authType string 付费观看-pay,验证码观看-code,白名单观看-phone,登记观看-info,自定义授权观看-custom,外部授权-external

开启或关闭观看条件

{
    "authSettings": [{
        "rank": 1,
        "enabled": "N"
    },
    {
        "rank": 2,
        "enabled": "N"
    }]
}

付费观看

主要观看条件为付费观看,次要观看条件关闭,json数据格式如下:

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

参数说明

参数名 必选 类型 说明
payAuthTips string 欢迎语标题
price int 价格,单位为元
watchEndTime string 付费有效截止日期,格式为yyyy-MM-dd HH:mm
validTimePeriod int 付费有效时长,单位天

注:当watchEndTime和validTimePeriod都为空时,表示付费永久有效

验证码观看和白名单观看

主要观看条件为验证码观看,次要观看条件为白名单观看

设置观看条件为白名单观看时,必须已经存在白名单数据,否则设置失败。白名单可通过后台上传也可以通过上传白名单接口上传

{
    "authSettings": [{
        "rank": 1,
        "enabled": "Y",
        "authType": "code",
        "authCode": "polyv",
        "qcodeTips": "扫码关注XXX,获得观看码",
        "qcodeImg": "http://livestatic.polyv.net/xxxxx.png"
    },
    {
        "rank": 2,
        "enabled": "Y",
        "authType": "phone",
        "authTips": "会员通道"
    }
    ]
}

验证码观看参数说明

参数名 必选 类型 说明
authCode string 验证码
qcodeTips string 提示文案
qcodeImg string 公众号二维码地址

白名单观看参数说明

参数名 必选 类型 说明
authTips string 提示文案

登记观看

主要观看条件为登记观看

{
    "authSettings": [{
        "rank": 1,
        "enabled": "Y",
        "authType": "info",
        "infoFields": [
            {
                    "name": "姓名",
                    "type": "name",
                    "options": null,
                    "placeholder": null
                },
                {
                    "name": "从哪里来???",
                    "type": "text",
                    "options": null,
                    "placeholder": "请填写"
                },
                {
                    "name": "性别",
                    "type": "option",
                    "options": "男,女,你猜",
                    "placeholder": "请填写"
                },
                {   "name": "年龄",
                    "type": "number",
                    "options": null,
                    "placeholder": "请问你多大"
                },
                {
                    "name": "手机号",
                    "type": "mobile",
                    "options": null,
                    "placeholder": "留下你的号码"
                }
        ]
    }
    ]
}

登记观看参数说明

参数名 必选 类型 说明
infoFields json 登记观看信息,上线为5个
name string 登记信息名,最多为8字符
type string 登记类型,姓名-name,文本-text,手机号码-mobile,数字-number,下拉选项-option
options string 下拉选项时,下拉的选项值,以英文逗号分割。选项个数上限为8个;选项内容最多为8字符
placeholder string 文本框输入提示,最多为8字符

外部授权和自定义授权

主要观看条件为外部授权观看,次要条件为自定义授权观看

{
    "authSettings": [{
        "rank": 1,
        "enabled": "Y",
        "authType": "external",
        "externalKey": "zzxxccvvbb",
        "externalUri": "http://polyv.net",
        "externalRedirectUri": "http://12306.cn"
        },
    {
        "rank": 2,
        "enabled": "Y",
        "authType": "custom",
        "customKey": "aabbccddee",
        "customUri": "http://www.polyv.net"
    }
    ]
}

外部授权参数说明

参数名 必选 类型 说明
externalKey string SecretKey
externalUri string 自定义url
externalRedirectUri string 跳转地址

自定义授权json参数

参数名 必选 类型 说明
customKey string SecretKey
customUri string 自定义url

注:以上的json示例为同时设置两个观看条件,可以通过authSettings中只传递一个json对象来选择只控制主要观看条件或者次要观看条件。

响应成功JSON示例:

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

响应失败JSON示例:

参数错误

{
    "code": 400,
    "status": "error",
    "message": "param validate error",
    "data": 400
}

未输入appId

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

appId不正确

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

时间戳错误

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

签名错误

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

字段说明

参数名 说明
code 状态码,成功为200,签名失败为403,参数错误为400,服务端错误为500
status 成功为success,错误时为error
message 成功为"",错误时为错误描述信息
data 成功时为true,错误时为""

php请求示例

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

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

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

$json = '{
    "authSettings": [{
        "rank": 1,
        "enabled": "N"
    },
    {
        "rank": 2,
        "enabled": "N"
    }]
}';

$params["sign"] = $sign;
$url="http://api.polyv.net/live/v3/channel/auth/update?".http_build_query($params);

function post($url, $post_data = '', $timeout = 5){
   $ch = curl_init();
   curl_setopt ($ch, CURLOPT_URL, $url);
   curl_setopt ($ch, CURLOPT_POST, 1);
   if($post_data != ''){
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   }

   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
   curl_setopt($ch, CURLOPT_HEADER, false);
   curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($post_data)));
   $file_contents = curl_exec($ch);
   curl_close($ch);
   return $file_contents;
}

echo post($url,$json);
?>

Java请求示例

import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpEntity;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import com.live.util.EncryptionUtils;

public class Demo {

    private static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000)
            .setConnectionRequestTimeout(15000).build();

    public static void main(String[] args) {

        String url = "http://api.polyv.net/live/v3/channel/auth/update";
        String channelId = "频道号";
        String appId = "appId";
        String key = "secretKey";
        Map<String, String> map = new HashMap<>();
        String timestamp = Long.toString(System.currentTimeMillis());
        map.put("appId", appId);
        map.put("timestamp", "1533893354000");
        map.put("channelId", channelId);

        String sign = getSign(map, key);
        map.put("sign", sign);

        String body = "{\"authSettings\":[{\"rank\":1,\"enabled\":\"N\"},{\"rank\":2,\"enabled\":\"N\"}]}";
        String content = sendHttpPost(url, map, body);
        System.out.println(content);

    }

    /**
     * 发送 post请求
     * @param httpUrl 地址
     * @param maps 参数
     */
    public static String sendHttpPost(String httpUrl, Map<String, String> maps, String body) {
        StringBuilder url = new StringBuilder();
        url.append(httpUrl).append("?");
        for (Map.Entry<String, String> map : maps.entrySet()) {
            url.append(map.getKey()).append("=").append(map.getValue()).append("&");
        }
        String urlStr = url.toString().substring(0, url.length() - 1);

        System.out.println(urlStr);
        // 创建httpPost
        HttpPost httpPost = new HttpPost(urlStr);
        try {
            StringEntity entity = new StringEntity(body, Charset.forName("UTF-8"));
            httpPost.setEntity(entity);
        } catch (Exception e) {
            // ...
        }
        return sendHttpPost(httpPost);
    }

    /**
     * 发送Post请求
     * @param httpPost
     * @return
     */
    private static String sendHttpPost(HttpPost httpPost) {
        CloseableHttpClient httpClient = null;
        CloseableHttpResponse response = null;
        HttpEntity entity;
        String responseContent = null;
        try {
            // 创建默认的httpClient实例.
            httpClient = HttpClients.createDefault();
            httpPost.setConfig(requestConfig);
            // 执行请求
            response = httpClient.execute(httpPost);
            entity = response.getEntity();
            responseContent = EntityUtils.toString(entity, "UTF-8");
        } catch (Exception e) {
            // ...
        } finally {
            try {
                // 关闭连接,释放资源
                if (response != null) {
                    response.close();
                }
                if (null != httpPost) {
                    httpPost.releaseConnection();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                // ...
            }
        }
        return responseContent;
    }

    /**
     * 根据map里的参数构建加密串
     * @param map
     * @param secretKey
     * @return
     */
    protected static String getSign(Map<String, String> map, String secretKey) {
        Map<String, String> params = paraFilter(map);
        // 处理参数,计算MD5哈希值
        String concatedStr = concatParams(params);
        String plain = secretKey + concatedStr + secretKey;
        String encrypted = EncryptionUtils.md5Hex(plain);

        // 32位大写MD5值
        return encrypted.toUpperCase();
    }

    /**
     * 对params根据key来排序并且以key1=value1&key2=value2的形式拼接起来
     * @param params
     * @return
     */
    private static String concatParams(Map<String, String> params) {
        List<String> keys = new ArrayList<>(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();
    }

    /**
     * 除去数组中的空值和签名参数
     * @param sArray 签名参数组
     * @return 去掉空值与签名参数后的新签名参数组
     */
    private static Map<String, String> paraFilter(Map<String, String> sArray) {

        Map<String, String> result = new HashMap<>();

        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;
    }

}

签名规则(config.php文件代码查看)

http://dev.polyv.net/2018/liveproduct/l-api/rule/sign/

以上内容是否对您有帮助?根本没有帮助文档较差文档一般文档不错文档很好
Loading...