修改菜单排序

接口URL

http://api.polyv.net/live/v3/channel/menu/update-rank

接口说明

1、作用:修改直播频道的菜单的顺序
2、接口支持https协议

支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp string 当前时间的秒级时间戳(13位)
sign string 签名,为32位大写的MD5值
channelId int 频道号
menuIds string 频道菜单ID列表,必须是完整的列表(不能多也不能少),表示按该顺序排列菜单

操作成功响应示例

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

操作失败响应示例

签名错误

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

缺少参数 menuIds

{
    "code": 400,
    "status": "error"
    "message": "param should not be empty: menuIds",
    "data": ""
}

菜单ID列表错误(缺少菜单ID,或者有多余的、错误的菜单ID)

{
    "code": 400,
    "status": "error"
    "message": "illegal menu id: menuIds",
    "data": ""
}

响应字段说明

名称 类型 说明
code string 响应代码,成功为200,失败为400,签名错误为401,异常错误500
status string 成功为success,失败为error
message string 错误时为错误提示消息

php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'channelId' => '123456',
  'menuIds' => '123,456'
);

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

$params["sign"] = $sign;
$url="http://api.polyv.net/live/v3/channel/menu/update-rank?".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);
?>

java请求示例

package com.live;

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/menu/update-rank";
        String appId = "appId";
        String key = "secretKey";
        Map<String, String> map = new HashMap<>();
        map.put("appId", appId);
        map.put("timestamp", String.valueOf(System.currentTimeMillis()));
        map.put("channelId", "123456");
        map.put("menuIds", "123,456");

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

        String body = "";
        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...

删除指定菜单

接口URL

https://api.polyv.net/live/v3/channel/menu/delete

接口说明

1、接口用于删除指定的频道菜单,支持批量
2、接口支持https

支持格式

JSON

请求方式

GET

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前时间戳
sign string 签名值
menuIds string 菜单id,指定多个以英文逗号,分隔

响应成功JSON示例:

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

响应失败JSON示例:

未输入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": ""
}

menuId分割后为空

{
  "code": 400, 
  "status": "error", 
  "message": "param length is incorrect: menuIds", 
  "data": ""
}

菜单不存在

{
  "code": 400, 
  "status": "error", 
  "message": "illegal menu id: test", 
  "data": ""
}

菜单类型不能删除

{
  "code": 400, 
  "status": "error", 
  "message": "can't delete special menu type", 
  "data": ""
}

字段说明

参数名 说明
code 响应代码,成功为200,失败为400,签名错误为401,异常错误500
status 成功为success,失败为error
message 错误时为错误提示消息
data 成功响应时为本次成功删除的个数

php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'menuIds' => "9991391d9d,ea4375fcfb"
);

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

$url = "http://api.polyv.net/live/v3/channel/menu/delete?".http_build_query($params);

$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 500);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_URL, $url);
$res = curl_exec($curl);
curl_close($curl);

echo $res;
?>

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

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

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