查询课件重制任务列表

接口URL

http://api.polyv.net/live/v3/channel/pptRecord/list

接口说明

1、接口用于查询课件重制任务列表
2、接口支持https

返回结果支持格式

JSON

请求方式

GET

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前时间戳
sign string 签名值
channelId int 频道号
sessionId string 场次id
status string 状态值。waiting-等待处理,process-处理中,success-重制成功,fail-重制失败,uploaded-上传点播成功,uploadFailed-上传点播失败
startTime string 直播开始时间开始区间,格式为yyyyMMddHHmmss
endTime string 直播开始时间结束区间,格式为yyyyMMddHHmmss
page int 分页页码
pageSize int 分页大小

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "pageNumber": 1,
        "totalPages": 8,
        "pageSize": 1,
        "contents": [
            {
                "channelId": 206204,
                "title": "test",
                "url": "http://playback.videocc.net/transform/a2c7d0ed37_0.mp4?auth_key=1577427993-0-0-d469619bbb434240c3e88aeadbbbcd2c",
                "sessionId": "fix2p01fiz",
                "startTime": "20191220000012",
                "status": "success",
                "remainDay": 178,
                "duration": 25
            }
        ]
    }
}

响应字段说明

参数名 说明
code 状态码,成功为200,签名失败为403,参数错误为400,服务端错误为500
status 成功为success,错误时为error
message 成功为"",错误时为错误描述信息
data 重制任务分页列表数据
pageNumber 当前页码
totalPages 总页数
pageSize 页面大小
contents 任务列表
channelId 频道号
title 对应回放的名称
url 重制mp4下载地址,有24小时的防盗链超时时间
sessionId 场次id
startTime 对应回放的直播开始时间,格式为yyyyMMddhhmmss
status 状态值。waiting-等待处理,process-处理中,success-重制成功,fail-重制失败,uploaded-上传点播成功,uploadFailed-上传点播失败
remainDay 重制剩余的过期时间,过期后将无法访问和下载
duration 重制的视频时长,单位秒

响应失败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": ""
}

php请求示例

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

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

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

$url = "http://api.polyv.net/live/v3/channel/pptRecord/list?".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;
?>

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

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

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

删除硬盘推流的视频

接口URL

http://api.polyv.net/live/v3/channel/stream/delete-disk-videos

接口说明

1、删除硬盘推流中的视频,不允许删除正在推流直播中的视频
2、接口支持https

请求方式

POST

请求参数

参数名 必选 类型 说明
vids string 要删除的硬盘推流视频id
channelId int 直播频道ID
appId string 从API设置中获取,在直播系统登记的appId
sign string 签名,为32位大写的MD5值
timestamp long 当前13位毫秒级时间戳,3分钟内有效

响应成功JSON示例:

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

响应异常JSON示例:

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

字段说明

参数名 说明
code 请求状态响应码
status 请求状态
message 错误信息
data

php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'streamType' => "client,
  'channelId' => 108888
);

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

$url = "http://api.polyv.net/live/v3/channel/stream/delete-disk-videos?".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;
?>

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

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

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

修改直播推流方式

接口URL

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

接口说明

1、修改频道的直播方式
2、接口支持https协议
3、直播过程中不允许修改直播方式

请求方式

POST

请求参数

参数名 必选 类型 说明
streamType string 直播方式:client 客户端推流,disk 硬盘推流,audio 音频直播
channelId int 直播频道ID
appId string 从API设置中获取,在直播系统登记的appId
sign string 签名,为32位大写的MD5值
timestamp long 当前13位毫秒级时间戳,3分钟内有效

响应成功JSON示例:

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

响应异常JSON示例:

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

字段说明

参数名 说明
code 请求状态响应码
status 请求状态
message 错误信息
data

php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'streamType' => "client,
  'channelId' => 108888
);

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

$url = "http://api.polyv.net/live/v3/channel/stream/update?".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;
?>

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

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

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

设置硬盘推流直播

接口URL

http://api.polyv.net/live/v3/channel/stream/add-disk-videos

接口说明

1、通过接口设置频道的硬盘推流,具体功能说明可参考:《直播方式》
2、调用接口后,如果当前频道未在直播中,会自动设置直播方式为“硬盘推流”
如果当前使用其他直播推流方式直播中,则需要在直播结束后,调用《修改直播推流方式》接口修改为硬盘推流,才会在所设置的开始时间进行直播
3、接口支持https协议

请求方式

POST

请求参数

参数名 必选 类型 说明
vids string 要设置硬盘推流的点播视频ID
startTimes string 硬盘推流开始时间,13位毫秒级时间戳
appId string 从API设置中获取,在直播系统登记的appId
channelId int 频道ID
sign string 签名,为32位大写的MD5值
timestamp long 当前13位毫秒级时间戳,3分钟内有效

响应成功JSON示例:

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

响应异常JSON示例:

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

字段说明

参数名 说明
code 请求状态响应码
status 请求状态
message 错误信息
data

php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'vids' => "8205ac89d30adeb51a6f8bf1a1df6f63_8",
  'startTimes' => "1580646692367"
);

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

$url = "http://api.polyv.net/live/v3/channel/stream/add-disk-videos?".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;
?>

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

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

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

查询授权和连麦的token

接口URL

http://api.polyv.net/live/v3/channel/common/get-chat-token

接口说明

1、接口用于获取授权和连麦的token
2、接口支持https

返回结果支持格式

JSON

请求方式

GET POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前时间戳
sign string 签名值
channelId int 频道Id
userId String 观看者用户ID
role String 角色,值有:teacher admin guest assistant viewer等
origin String 观看来源

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
"mediaChannelKey": "e2355436235ba12d4c56493b575afed38f9f061d044f54d93c30f01463ffea852a7119c6195c6abf51b4682bc596bf5962eddc6cbf82784a1e5309ac52220ef7e66e4e7eb69a4e80081056972d5a9cb3bb723a0cb090702eef99369d479482b3bad99e5ec50eae5607b82c58da59aac3eada29fe6d753ef358d064ee308e406b3091f5256a77251001f99b6815651f18982da983b58c79d9caedd5ccec3f20ecd3dde7ba370f3c0ca0aa8c3ef088148523019f06e224d030b871da390c4a1a1c646e26684895d544dbba47751c535d07ea765fcf0cdfe8fe3de1538e4fe69eecadfd4a8b431aa4b00bc5dbccdb996ea3b7f962da2ecc21b6b14ba70c33601c53c3aa8d8e4857c111fa076e47e3a6eafc9601b87c079361f2d0f3cb4b31df2ff088ccb9428abe324ecb9e07e2fb8f48e40ab2ef3e119cfd93b15259bfa390938485a8fcd2e200dadeefe15a0516b7f61736cbe5bf48564d100e28ff64f979ebf42eadd3a0f3d58565d1ab619884d78c29",
"token": "71b961e6b2a68cde9559966b2f46d4e0"
}
}

响应字段说明

参数名 说明
code 状态码,成功为200,签名失败为403,参数错误为400,服务端错误为500
status 成功为success,错误时为error
message 成功为"",错误时为错误描述信息
data.token 链接接口需要的token值
data.mediaChannelKey 连麦需要的key

响应失败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": ""
}

php请求示例

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

$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'userId' => $userId,
  'role' => $role,
  'origin' => $origin,
  'channelId' =>  195770
);

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

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

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

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

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

查询频道广告列表

接口URL

http://api.polyv.net/live/v3/channel/advert/list

接口说明

1、提供查询频道轮播广告列表信息,频道广告为空时,获取全局广告
2、支持https

返回结果支持格式

JSON

请求方式

GET

请求参数

参数名 必选 类型 说明
appId string 账号应用下的appId
timestamp string 当前时间的秒级时间戳(13位)
sign string 签名,为32位大写的MD5值
channelId int 频道号

操作成功响应示例

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": [
        {
            "text": "",
            "img": "//liveimages.videocc.net/uploaded/images/2019/09/ffmgstpk58.png",
            "href": ""
        },
        {
            "text": "123445",
            "img": "",
            "href": ""
        }
    ]
}

操作失败响应示例

签名错误

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

缺少参数 channelId

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

响应字段说明

名称 类型 说明
code string 响应代码,成功为200,失败为400,签名错误为403,异常错误500
status string 成功为success,失败为error
message string 错误时为错误提示消息
data object[] 成功响应数据
text string 文本广告内容
img string 图片广告链接
href string 跳转链接

php请求示例

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

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

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

//接口请求url
$url = "https://api.polyv.net/live/v3/channel/advert/list?appId=".$appId."&sign=".$sign."&timestamp=".$timestamp."&channelId=".$channelId;
//输出接口请求结果
echo file_get_contents($url);

?>

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

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

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

修改频道的相关设置

接口URL

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

接口说明

1、接口用于修改频道的相关设置
2、接口支持https

返回结果支持格式

JSON

请求方式

POST

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
channelId int 频道号
timestamp long 13位当前时间戳
sign string 签名值
basicSetting json 基础设置
authSettings json 观看条件设置

注:这里的appId,timestamp,sign,channelId必须通过url传参,json数据通过请求体传参,如:
http://api.polyv.net/live/v3/channel/basic/update?appId={{appId}}&timestamp={{timestamp}}&channelId={{channelId}}&sign={{sign}}

请求体json示例

{
    "basicSetting": {
        "name": "测试", 
        "channelPasswd": "10086", 
        "publisher":"主持人名称",
        "startTime": 1557888134000,
        "pageView": 1000,
        "likes": 666,
        "coverImg": "http://my.polyv.net/v_22/assets/dist/images/navbar/logo.png",
        "splashImg": "http://my.polyv.net/v_22/assets/dist/images/navbar/logo.png",
        "splashEnabled": "Y",
        "desc": "这是直播介绍,可以是html代码"
        "consultingMenuEnabled": "N",
        "maxViewerRestrict": "Y",
        "maxViewer": 100,
        "categoryId": 0
    }, 
    "authSettings": [
        {
            "rank": 1, 
            "enabled": "Y", 
            "authType": "external", 
            "externalKey": "L0EjokKI4O", 
            "externalUri": "http://demo.polyv.net/chenwb/live-validate.php"
        }
    ]
}

basicSetting详细说明

参数名 必选 类型 说明
name string 频道名称
channelPasswd string 频道密码,长度不能超过16位
publisher string 主持人名称
startTime long 直播开始时间,13位时间戳,设置为0 表示关闭直播开始时间显示
pageView int 累积观看数
likes int 点赞数
coverImg string 封面图片地址
splashImg string 引导图地址
splashEnabled string(Y、N) 引导页开关
desc string 直播介绍
consultingMenuEnabled string(Y、N) 咨询提问开关
maxViewerRestrict string(Y、N) 是否限制最大观看人数
maxViewer int 最大在线人数
categoryId int 频道的所属分类(分类ID可通过“获取直播分类”接口得到)
linkMicLimit int 连麦人数,-1:使用账号的连麦人数,范围大于等于-1,小于等于账号的连麦人数,最大16人

authSettings详细说明

详细的数据参数,参考 更新观看条件 的请求参数部分

响应成功JSON示例:

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

响应失败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": ""
}

Json格式错误或字段类型不对

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

字段说明

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

php请求示例

<?php
//引用config.php
include '/srv/http/live/config.php';
$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp,
  'channelId' => $channelId
);

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

$json = '{"basicSetting":{"name":"测试","channelPasswd":"10086","maxViewer":20},"authSettings":[{"rank":1,"enabled":"Y","authType":"external","externalKey":"L0EjokKI4O","externalUri":"http://demo.polyv.net/chenwb/live-validate.php"}]}';

$params["sign"] = $sign;
$url="http://api.polyv.net/live/v3/channel/basic/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/basic/update";
        String appId = "appId";
        String key = "appSecret";
        String channelId="channelId";
        Map<String, String> map = new HashMap<>();
        String timestamp = Long.toString(System.currentTimeMillis());
        map.put("appId", appId);
        map.put("timestamp", timestamp);
        map.put("channelId", channelId);

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

        String body = "{\"basicSetting\":{\"name\":\"测试\",\"channelPasswd\":\"10086\",\"maxViewer\":20," +
                "\"startTime\":\"1\"},\"authSettings\":[{\"rank\":1,\"enabled\":\"Y\",\"authType\":\"external\"," +
                "\"externalKey\":\"L0EjokKI4O\",\"externalUri\":\"http://demo.polyv.net/chenwb/live-validate.php\"}]}";
        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

http://api.polyv.net/live/v3/channel/basic/get

接口说明

1、接口用于查询频道基本信息
2、接口支持https

返回结果支持格式

JSON

请求方式

GET

请求参数

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

响应成功JSON示例:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "channelId": 108888,
        "name": "test111",
        "channelPasswd": "1234",
        "publisher": "主持人",
        "startTime": 0,
        "pageView": 111,
        "likes": 66,
        "coverImg": "//livestatic.videocc.net/uploaded/images/2019/05/fcowsdnzx8.png",
        "splashImg": "//livestatic.videocc.net/uploaded/images/2019/05/fcowsdrak0.png",
        "splashEnabled": "Y",
        "desc": "你好,这个是直播介绍11111",
        "consultingMenuEnabled": "N",
        "maxViewerRestrict": "N",
        "maxViewer": 123,
        "watchStatus": "playback",
        "watchStatusText": "回放中",
        "userCategory": {
            "categoryId": 155224,
            "categoryName": "新建分类测试",
            "userId": "edvf2fpec9",
            "rank": 3
        },
        "authSettings": [
            {
                "channelId": 108888,
                "rank": 1,
                "userId": "edvf2fpec9",
                "globalSettingEnabled": "N",
                "enabled": "Y",
                "authType": "code",
                "authTips": "欢迎观看本直播",
                "payAuthTips": "欢迎观看本次直播",
                "codeAuthTips": "欢迎观看本次直播",
                "infoAuthTips": "欢迎观看本次直播",
                "authCode": "1",
                "qcodeTips": "扫码关注XXX,获得观看码扫码关注XXX",
                "qcodeImg": "",
                "price": 999999.00,
                "watchEndTime": null,
                "validTimePeriod": null,
                "customKey": "c130221c6b",
                "customUri": null,
                "externalKey": "94c7e79aff",
                "externalUri": null,
                "externalRedirectUri": null,
                "directKey": null,
                "trialWatchEnabled": "Y",
                "trialWatchTime": 1,
                "trialWatchEndTime": null
            },
            {
                "channelId": 108888,
                "rank": 2,
                "userId": "edvf2fpec9",
                "globalSettingEnabled": "N",
                "enabled": "Y",
                "authType": "pay",
                "authTips": "欢迎观看本次直播",
                "payAuthTips": "欢迎观看本直播",
                "codeAuthTips": "验证码是1",
                "infoAuthTips": null,
                "authCode": "1",
                "qcodeTips": "",
                "qcodeImg": "",
                "price": 1.00,
                "watchEndTime": null,
                "validTimePeriod": null,
                "customKey": "17040194f4",
                "customUri": null,
                "externalKey": "693d8a540c",
                "externalUri": null,
                "externalRedirectUri": null,
                "directKey": null,
                "trialWatchEnabled": "N",
                "trialWatchTime": 1,
                "trialWatchEndTime": null
            }
        ]
    }
}

响应字段说明

参数名 类型 说明
code int 状态状态码,请求成功时为200
status string 状态值
message string 请求失败时返回的错误值
data ChannelDetailSettingModel 请求失败时为空,请求成功时为频道的详细设置信息

ChannelDetailSettingModel字段说明

参数名 类型 说明
channelId int 频道号
name string 频道名称
channelPasswd string 频道密码
publisher string 主持人名称
startTime long 直播开始时间,关闭时为0,开启时为13位毫秒级时间戳
pageView int 页面累计观看数
likes int 观看页点赞数
coverImg string 频道图标url
splashImg string 频道引导图url
splashEnabled string(取值为Y/N) 引导页开关
desc string 直播介绍
consultingMenuEnabled string(取值为Y/N) 咨询提问开关
maxViewerRestrict string(取值为Y/N) 限制最大在线观看人数开关
maxViewer int 最大在线观看人数
watchStatus string 频道的观看页状态,取值为: 频道状态,取值:live(直播中)、end(直播结束)、playback(回放中)、waiting(等待直播)
watchStatusDesc string 观看页状态描述,直播中,回放中,已结束,未开始
userCategory object 频道所属分类的信息
userCategory.categoryId int 分类ID
userCategory.categoryName string 分类名称
userCategory.rank int 分类的排序值
authSettings List 直播观看条件列表

关于ChannelAuthSetting 的参数说明请参考该接口的成功返回结果:查询直播频道观看条件

响应失败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": ""
}

php请求示例

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

$channelId="183950";

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

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

$url = "http://api.polyv.net/live/v3/channel/basic/get?appId=".$appId."&channelId=".$channelId."&timestamp=".$timestamp."&sign=".$sign;

echo file_get_contents($url);

?>

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

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

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

创建并初始化频道

接口URL

http://api.polyv.net/live/v3/channel/basic/create

接口说明

1、接口用于创建频道并进行相关设置
2、接口支持https

返回结果支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp long 13位当前时间戳
sign string 签名值
basicSetting json 基础设置
authSettings json 观看条件设置

注:这里的appId,timestamp,sign必须通过url传参,json数据通过请求体传参,如:
http://api.polyv.net/live/v3/channel/basic/create?appId={{appId}}&timestamp={{timestamp}}&sign={{sign}}

请求体json示例

{
    "basicSetting": {
        "name": "测试", 
        "channelPasswd": "10086", 
        "maxViewer": 20, 
        "startTime": 1557888134000
    }, 
    "authSettings": [
        {
            "rank": 1, 
            "enabled": "Y", 
            "authType": "external", 
            "externalKey": "L0EjokKI4O", 
            "externalUri": "http://demo.polyv.net/chenwb/live-validate.php"
        }
    ]
}

basicSetting详细说明

参数名 必选 类型 说明
name string 频道名称
channelPasswd string 频道密码,长度不能超过16位
autoPlay int 是否自动播放,0/1,默认1
playerColor string 播放器控制栏颜色,默认:#666666
scene string 直播场景:
alone 活动拍摄
ppt 三分屏
topclass 大班课
categoryId int 新建频道的所属分类,如果不提交,则为默认分类(分类ID可通过“获取直播分类”接口得到)
maxViewer int 最大同时在线人数
startTime long 直播开始时间,13位时间戳
desc string 直播介绍的内容
publisher string 主持人
linkMicLimit int 连麦人数,-1:使用账号的连麦人数,范围大于等于-1,小于等于账号的连麦人数,最大16人

authSettings详细说明

详细的数据参数,参考 更新观看条件 的请求参数部分

响应成功JSON示例:

{
    "code": 200, 
    "status": "success", 
    "message": "", 
    "data": {
        "channelId": 323158, 
        "userId": "b0f7041324", 
        "name": "测试", 
        "publisher": null, 
        "description": "", 
        "url": "rtmp://push-c1.videocc.net/recordf/b0f704132420190515115309303", 
        "stream": "b0f704132420190515115309303", 
        "logoImage": "", 
        "logoOpacity": 1, 
        "logoPosition": "tr", 
        "logoHref": "", 
        "coverImage": "", 
        "coverHref": "", 
        "waitImage": "", 
        "waitHref": "", 
        "cutoffImage": "", 
        "cutoffHref": "", 
        "advertType": "NONE", 
        "advertDuration": 0, 
        "advertWidth": 0, 
        "advertHeight": 0, 
        "advertImage": "", 
        "advertHref": "", 
        "advertFlvVid": "", 
        "advertFlvUrl": "", 
        "playerColor": "#FFFFFF", 
        "autoPlay": false, 
        "warmUpFlv": "", 
        "passwdRestrict": false, 
        "passwdEncrypted": "", 
        "isOnlyAudio": "N", 
        "isLowLatency": "N", 
        "m3u8Url": "http://pull-c1.videocc.net/recordf/b0f704132420190515115309303.m3u8?auth_key=1557892389-0-0-d1cab3b24dc910dc22e3ab60915f682b", 
        "m3u8Url1": "", 
        "m3u8Url2": "", 
        "m3u8Url3": "", 
        "channelLogoImage": null, 
        "scene": "topclass", 
        "currentTimeMillis": 1557892389591
    }
}

响应字段说明

参数名 类型 说明
status string 状态值
result object 响应的结果
channelId string 直播频道ID
userId string 直播用户ID
name string 直播频道名称
description string 直播频道描述
url string 直播推流地址
stream string 直播流名称
logoImage string 播放器logo
logoOpacity float Logo不透明度,1表示完全不透明
logoPosition string Logo位置
logoHref string Logo的跳转链接
coverImage string 播放前显示的封面图
coverHref string 封面图的跳转链接
waitImage string 等待推流时的显示图片
waitHref string 等待推流时显示图片的跳转链接
cutoffImage string 切断流时的显示图片
cutoffHref string 切断流时显示图片的跳转链接
advertType string 广告类型
advertDuration string 广告时长
advertWidth string 广告区域宽度
advertHeight string 广告区域高度
advertImage string 图片广告
advertHref string 广告的跳转链接
advertFlvVid string 视频广告ID
advertFlvUrl string 视频广告链接
playerColor string 播放器控制栏颜色
autoPlay boolean 自动播放
warmUpFlv string 一开始的暖场视频
passwdRestrict boolean 观看密码限制,需要输入观看密码才能播放流
passwdEncrypted string 观看密码加密后的密文
isOnlyAudio string 仅推音频流
isLowLatency string 低延迟
m3u8Url string 直播拉流(播放)m3u8地址
m3u8Url1 string 直播拉流(播放)m3u8地址1
m3u8Url2 string 直播拉流(播放)m3u8地址2
m3u8Url3 string 直播拉流(播放)m3u8地址3
currentTimeMillis timestamp 服务器返回的时间戳(毫秒)

响应失败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": ""
}

Json格式错误或字段类型不对

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

字段说明

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

php请求示例

<?php
//引用config.php
include '/srv/http/live/config.php';
$params = array(
  'appId' => $appId,
  'timestamp' => $timestamp
);

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

$json = '{"basicSetting":{"name":"测试","channelPasswd":"10086","maxViewer":20},"authSettings":[{"rank":1,"enabled":"Y","authType":"external","externalKey":"L0EjokKI4O","externalUri":"http://demo.polyv.net/chenwb/live-validate.php"}]}';

$params["sign"] = $sign;
$url="http://api.polyv.net/live/v3/channel/basic/create?".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/basic/create";
        String appId = "appId";
        String key = "appSecret";
        Map<String, String> map = new HashMap<>();
        String timestamp = Long.toString(System.currentTimeMillis());
        map.put("appId", appId);
        map.put("timestamp", timestamp);

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

        String body = "{\"basicSetting\":{\"name\":\"测试\",\"channelPasswd\":\"10086\",\"maxViewer\":20," +
                "\"startTime\":\"1\"},\"authSettings\":[{\"rank\":1,\"enabled\":\"Y\",\"authType\":\"external\"," +
                "\"externalKey\":\"L0EjokKI4O\",\"externalUri\":\"http://demo.polyv.net/chenwb/live-validate.php\"}]}";
        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

http://api.polyv.net/live/v3/channel/basic/batch-delete

接口说明

1、作用:批量删除直播频道
2、接口支持https协议

返回结果支持格式

JSON

请求方式

POST

请求数限制

TRUE

请求参数

参数名 必选 类型 说明
appId string 从API设置中获取,在直播系统登记的appId
timestamp string 当前时间的秒级时间戳(13位)
sign string 签名,为32位大写的MD5值
channelIds json 频道ID列表,每次最多删除100个频道, 必须放在请求体中

请求体示例

{
    "channelIds": [123001, 123002, 123003]
}

操作成功响应示例

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

操作失败响应示例

留意,如果响应失败,则表示全部频道都失败,不会有部份成功、部份失败的结果

签名错误

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

请求体json格式错误

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

channelIds 列表中的频道ID数超过上限(100个)

{
    "code": 400,
    "status": "error"
    "message": "channel batch count over limit",
    "data": ""
}

channelIds 列表中有错误的频道ID(会输出第一个错误的频道ID)

{
    "code": 400,
    "status": "error"
    "message": "channel not found: 123456",
    "data": ""
}

响应字段说明

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

php请求示例

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

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

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

$json = '{
    "channelIds": [123001, 123002, 123003]
}';

$params["sign"] = $sign;
$url="http://api.polyv.net/live/v3/channel/basic/batch-delete?".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请求示例

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/basic/batch-delete";
        String appId = "appId";
        String key = "secretKey";
        Map<String, String> map = new HashMap<>();
        map.put("appId", appId);
        map.put("timestamp", String.valueOf(System.currentTimeMillis()));

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

        String body = "{\"channelIds\":[123001, 123002, 123003]}";
        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...