CDN加速

文档中心 直播分发 直播流在线人数查询API

直播流在线人数查询API

更新时间:2021-09-07 16:56:08

一.功能简介

  实时在线人数是指某时刻有多少用户观看某直播节目,该数据可以直观的反映直播节目的热度,网宿可以为直播客户提供相应的在线人数API 接口。(在线人数查询接口默认不支持hls协议的人数查询,如需此项功能,需另行开通)

二. 使用说明

  网宿提供相应的API 接口给客户。如下:
  https://open.chinanetcenter.com/QOSS/api/onlineViewers
  接口请求时可携带如下参数:

参数名称 类型 是否必填 说明
u string 域名(支持多个域名,以逗号分隔)
t int 时间,eg:20160527152300,不填时非实时为当前时间-5分钟,实时为当前时间-30秒
d string 域名类型,pull或push,不填时默认为pull
channel string 频道URL(仅支持单频道查询)
from int 开始时间,eg: 20160803103500,from和to都填或都不填,都填时channel参数必填,查询时间跨度最大为两个小时,如果超过两个小时,将查询开始时间两个小时内的数据,可查近1天内在线人数数据
to int 结束时间,eg: 20160803103900,from和to都填或都不填,都填时channel参数必填,查询时间跨度最大为两个小时,如果超过两个小时,将查询开始时间两个小时内的数据,可查近20天内在线人数数据
g int 查询间隔,可选值10、60;当g为10时,查询时间范围内每10秒的在线人数;当g为60时,查询时间范围内整分钟点对应的在线人数
realtime boolean 实时数据控制,默认为false,为true时,数据为实时,为false时,数据为非实时
unpack boolean 域名拆分控制,默认为false,为true时,拆分域名数据,为false时,合并域名数据

  请求示例 json:

  1) 请求实时数据:

#!/bin/bash

account='account'
apikey='passwd'

DATE=`date -R -u | awk '{print $1" "$2" "$3" "$4" "$5" GMT"}'`
PASSW=`echo -en "$DATE" | openssl dgst -sha1 -hmac $apikey -binary | openssl enc -base64`

curl -i --url "http://open.chinanetcenter.com/QOSS/api/onlineViewers?u=pull.test.com&d=pull&realtime=true&t=20180706080000" \
-X GET \
-u "$account:$PASSW" \
-H "Date: $DATE" \
-H 'Accept: application/json'

  2) 请求非实时数据:

#!/bin/bash

account='account'
apikey='passwd'

DATE=`date -R -u | awk '{print $1" "$2" "$3" "$4" "$5" GMT"}'`
PASSW=`echo -en "$DATE" | openssl dgst -sha1 -hmac $apikey -binary | openssl enc -base64`

curl -i --url "http://open.chinanetcenter.com/QOSS/api/onlineViewers?u=pull.test.comn&d=pull&realtime=false&t=20180706080000" \
-X GET \
-u "$account:$PASSW" \
-H "Date: $DATE" \
-H 'Accept: application/json'

  3) 请求指定时间范围数据:

#!/bin/bash

account='account'
apikey='passwd'

DATE=`date -R -u | awk '{print $1" "$2" "$3" "$4" "$5" GMT"}'`
PASSW=`echo -en "$DATE" | openssl dgst -sha1 -hmac $apikey -binary | openssl enc -base64`

curl -i --url "http://open.chinanetcenter.com/QOSS/api/onlineViewers?channel=pull.test.com/live/JTkrJw3E3&from=20180707000000&to=20180707003000" \
-X GET \
-u "$account:$PASSW" \
-H "Date: $DATE" \
-H 'Accept: application/json'

  4) 请求拆分域名数据:

#!/bin/bash

account='account'
apikey='passwd'

DATE=`date -R -u | awk '{print $1" "$2" "$3" "$4" "$5" GMT"}'`
PASSW=`echo -en "$DATE" | openssl dgst -sha1 -hmac $apikey -binary | openssl enc -base64`

curl -i --url "http://open.chinanetcenter.com/QOSS/api/onlineViewers?u=pull.test.com,pullbak.test.com&d=pull&unpack=true" \
-X GET \
-u "$account:$PASSW" \
-H "Date: $DATE" \
-H 'Accept: application/json'

  5) 请求合并域名数据:

#!/bin/bash

account='account'
apikey='passwd'

DATE=`date -R -u | awk '{print $1" "$2" "$3" "$4" "$5" GMT"}'`
PASSW=`echo -en "$DATE" | openssl dgst -sha1 -hmac $apikey -binary | openssl enc -base64`

curl -i --url "http://open.chinanetcenter.com/QOSS/api/onlineViewers?u=pull.test.com,pullbak.test.com&d=pull&unpack=false" \
-X GET \
-u "$account:$PASSW" \
-H "Date: $DATE" \
-H 'Accept: application/json'

  返回参数:

参数名称 类型 说明
prog string 流名, 显示 域名/发布点/流名
time string 时间,仅当查询时间范围,即channel,from和to参数不为空时才显示
value int 在线人数
retcode int 数据条数,仅当查询时间点,即from和to为空时才显示
rettime string 返回的数据的时间
count int 在线总人数,仅当查询时间点,即from和to为空时才显示

  1) 合并域名返回示例:

{
  "count": 8,
  "retcode": 4,
  "rettime": "2018-07-11 15:59:07",
  "dataValue": [
    {
      "prog": "pull.test.com/live/On5a5A8LPxxs",
      "value": 2
    },
    {
      "prog": "pull.test.com/live/DdmUf4JZtgKW",
      "value": 2
    },
    {
      "prog": "pullbak.test.com/live/X85npBIMZdCg",
      "value": 2
    },
    {
      "prog": "pullbak.test.com/live/wt6JPUn2ghkj",
      "value": 2
    }
  }
}

  2) 拆分域名返回示例:

{
    "count" : 320230,
    "retcode" : 1265,
    "rettime" : "2018-02-17 14:12:01",
    "域名A" : {
                "count" : 1568,
                "retcode" : 16,
                "dataValue" : [{"prog":"流名",  "value":154},...]
     },
    "域名B":{
                "count" : 3415,
                "retcode" : 25,
                "dataValue" : [{"prog":"流名",  "value":154},...]
     }

  3) 指定时间范围返回示例:

{
"rettime": "2018-07-11 15:55:01",
"dataValue": [
{
"prog": "pull.test.com/live/2aod8l4cLJGN",
"time": "20180711150000",
"value": 2
},
{
"prog": "pull.test.com/live/2aod8l4cLJGN",
"time": "20180711150100",
"value": 2
},
{
"prog": "pull.test.com/live/2aod8l4cLJGN",
"time": "20180711150200",
"value": 2
},
{
"prog": "pull.test.com/live/2aod8l4cLJGN",
"time": "20180711150300",
"value": 2
},
{
"prog": "pull.test.com/live/2aod8l4cLJGN",
"time": "20180711150400",
"value": 2
},
{
"prog": "pull.test.com/live/2aod8l4cLJGN",
"time": "20180711150500",
"value": 2
}
]
}

三. 应用场景

  所有直播业务,直播平台需要了解在线观看人数数据。

四.注意事项

  1) API 接口中两个参数之间用与号(&)隔开;
  2) 请不要在问号(?)后面带空格等不符合HTTP 协议的字符,如果在URL 或目录名中使用这些字符,请务必使用转义符(比如,空格的转义符为%20);
  3) 接口调用限制5分钟100次;