修改频道图标

接口URL

http://api.polyv.net/live/v2/channelSetting/{channelId}/setCoverImg

接口说明

1、作用:修改频道号图标
2、说明:上传的图片为不大于2MB的本地图片(格式只能为JPG、JPEG、PNG)。
3、接口URL中的{channelId}为 频道ID
4、接口支持https协议

支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
sign string 签名,32位大写MD5值
timestamp string 当前13位毫秒级时间戳,3分钟内有效
imgfile 本地上传图片 图片为大小为2MB的JPG、JPEG、PNG图片
startXs string 距离原点的水平距离(剪裁水平位置)
startYs string 距离原点的垂直距离(剪裁垂直位置)
Widths string 设置图片宽
Heights string 设置图片高

参数说明:Widths、Heights是特定矩形的宽度、高度,如果不填,默认为128。startXs和startYs是剪裁图片,截取矩形的X坐标和Y坐标。

​ ◆上述4个参数非必填,建议直接上传分辨率为128X128的图片。

响应成功JSON示例:

 {
    "code":200,
    "status":"success",
    "message":"",
    "data":"//livestatic.videocc.net/uploaded/images/2017/03/******.jpg"
}

响应异常JSON示例:

{
    code: 400,
    status: "error",
    message: "image format error",
    data: ""
}

字段说明

参数名 说明
status 响应状态
data 请求成功时,返回值是上传成功后的图片地址
code 异常错误代码
message 请求失败时的异常错误信息

php请求示例

<?php

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


//接口需要的参数(非sign)赋值
$appId = "XXXXXXXX";
$channelId = "127075";
$imgfile = 'C:\Users\polyv\Desktop\timg.jpg';

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

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

$data = array(
      'appId' => $appId,
      'timestamp' => $timestamp,
      'sign' => $sign,
      'imgfile' => new CURLFile(realpath($imgfile))
  );

$url = "http://api.polyv.net/live/v2/channelSetting/$channelId/setCoverImg";
$ch = curl_init() or die ( curl_error() );
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 360);
$reponse = curl_exec ( $ch );
curl_close ( $ch );
print_r($reponse); 

?>

java请求示例

public class SetCoverImg {

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

    public static void main(String[] args) {
        Integer channelId = 108888; // 频道号
        String appId = "XXXXXXXX"; // 应用Id
        String appSecret = "XXXXXXXX";  // 应用密匙
        Long timestamp = System.currentTimeMillis(); // 13位毫秒级时间戳

        // 构建签名
        String sign = DigestUtils.md5Hex(appSecret + "appId" + appId + "timestamp" + timestamp + appSecret).toUpperCase();

        String url = String.format("http://api.polyv.net/live/v2/channelSetting/%s/setCoverImg", channelId);

        Map<String, String> map = new HashMap<>();
        map.put("appId", appId);
        map.put("timestamp", String.valueOf(timestamp));
        map.put("sign", sign);

        // 图片的本地文件路径,推荐128X128
        File file = new File("C:\\Users\\lenovo\\Desktop\\demo.png");
        String responBody = sendHttpPost(url, map, file);
        System.out.println(responBody);
    }

    /**
     * 发送 post请求(带文件)
     * @param httpUrl 地址
     * @param maps 参数
     * @param file 上传文件
     */
    private static String sendHttpPost(String httpUrl, Map<String, String> maps, File file) {
        HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost
        MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create();
        for (String key : maps.keySet()) {
            meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN));
        }
        FileBody fileBody = new FileBody(file);
        meBuilder.addPart("imgfile", fileBody); // imgfile 图片对应参数名
        HttpEntity reqEntity = meBuilder.build();
        httpPost.setEntity(reqEntity);
        return sendHttpPost(httpPost);
    }

    /**
     * 发送Post请求
     */
    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) {
            e.printStackTrace();
        } finally {
            try {
                // 关闭连接,释放资源
                if (response != null) {
                    response.close();
                }
                if (null != httpPost) {
                    httpPost.releaseConnection();
                }
                if (httpClient != null) {
                    httpClient.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return responseContent;
    }
}

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

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

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