# 按照日期区间或时间段查询分类的播放量、流量、播放时长统计信息

### 接口URL

```
https://api.polyv.net/v2/cata/{userid}/stats-info
```

### 接口说明

```
按照日期区间或时间段查询分类的播放量、流量、播放时长统计信息
```

### 支持格式

```
JSON
```

### 请求方式

```
GET
```

### 请求参数

| 参数名                | 必选    | 类型及范围  | 说明                                                                                                                                                      |
| ------------------ | ----- | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
| userid             | true  | string | 用户id，路径参数                                                                                                                                               |
| ptime              | true  | string | 当前13位毫秒级时间戳，3分钟内有效                                                                                                                                      |
| sign               | true  | string | 签名，40位大写的sha1值                                                                                                                                          |
| cataid             | true  | long   | 分类ID                                                                                                                                                    |
| dr                 | false | string | 时间段，具体值为以下几个：today（今天），yesterday（昨天），this\_week（本周），last\_week（上周），7days（最近7天），this\_month（本月），last\_month（上个月），this\_year（今年），last\_year（去年），默认值为7days |
| startDate          | false | string | 开始日期，格式为yyyy-MM-dd                                                                                                                                      |
| endDate            | false | string | 结束日期，格式为yyyy-MM-dd                                                                                                                                      |
| containSubCategory | false | string | 是否包含子分类的统计数据，取值Y表示包含子分类 ，N表示不包含                                                                                                                         |

### 返回结果

```json
{
  "code": 4,
  "status": "text",
  "message": "",
  "data": [
    {
      "current": "2018-08-01",
      "pcFlowSize": 10,
      "mobileFlowSize": 0,
      "mobilePlayDuration": 9,
      "pcPlayDuration": 2,
      "pcVideoView": 9,
      "mobileVideoView": 7
    },
    {
      "current": "2018-08-02",
      "pcFlowSize": 10,
      "mobileFlowSize": 1000,
      "mobilePlayDuration": 9,
      "pcPlayDuration": 20,
      "pcVideoView": 90,
      "mobileVideoView": 7
    }	
  ]
}
```

### 失败返回json(不带jsonp)

```json
{
  "code": 400,
  "status": "error",
  "message": "ptime is too old.",
  "data": ""
}
```

### 字段描述

| 字段名称               | 描述      |
| ------------------ | ------- |
| current            | 查询的日期   |
| pcFlowSize         | pc端流量   |
| mobileFlowSize     | 移动端流量   |
| mobilePlayDuration | 移动端播放时长 |
| pcPlayDuration     | pc端播放时长 |
| pcVideoView        | pc端播放量  |
| mobileVideoView    | 移动端播放量  |

### 响应说明

| 错误代码 | message                        | 说明                   |
| ---- | ------------------------------ | -------------------- |
| 400  | sign can not be empty.         | 加密串为空                |
| 402  | illegal cataid.                | 分类ID错误               |
| 400  | ptime is too old.              | 时间戳过期                |
| 400  | ptime is illegal.              | 时间戳参数格式不对或者超过当前时间3分钟 |
| 400  | Could not find user by userid. | userid不存在            |
| 400  | the sign is not right.         | 加密串不正确               |
| 402  | illegal query date.            | start日期大于end日期       |
| 500  | query failed.                  | 后台程序抛异常              |
| 200  | success                        | 提交成功                 |

**PHP请求示例**

```php
<?php
header("Content-type: text/html; charset=utf-8");
$userid="用户id";
$dr="this_year";
$cataid="1399488884";
$ptime=time()*1000;//13位
$secretkey="填写secretKey";
$str="cataid=".$cataid."&dr=".$dr."&ptime=".$ptime.$secretkey;

$hash=strtoupper(sha1($str));
$url="http://api.polyv.net/v2/cata/$userid/stats-info?ptime=$ptime&sign=$hash&dr=$dr&cataid=$cataid";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$output = curl_exec($ch);
curl_close($ch);
//打印获得的数据
print_r($output);
?>
```

### 签名规则：

将非空的请求参数按照参数名字典顺序排列，连接参数名与参数值,并在尾部加上secretkey，生成40位大写SHA1值，作为sign。 以下是示例过程：

**1、请求参数为**

```javascript
ptime = "1492591990000"
cataid = "1333444444"
format = "json"
```

**2、将请求参数按照参数名字典顺序排列**

```javascript
cataid = "1333444444"
format = "json"
ptime = "1492591990000"
```

**3、连接字符串** 连接参数名与参数值,并在尾部加上secretkey（secretkey的值为tIQp4ATe9Z），如下：

```javascript
cataid=1333444444&format=json&ptime=1492591990000be68715e9455f8d0971a_3tIQp4ATe9Z
```

**4、生成签名sign**

```javascript
50BF9B165630A8047EB1D17D95A469CC51FF754E
```
