# 通用API - 分机话务统计

#### 接口说明

按分机号汇总或按天统计指定时间范围内的呼叫量、接通率和通话时长

#### 请求参数

| 参数名      | 类型     | 是否必须 | 说明                         |
| :------- | :----- | :--- | :------------------------- |
| service  | string | 是    | App.Sip_Cdr.GetExtStats |
| token    | string | 是    | 通过授权接口获取的token             |
| starttime | string | 是    | 统计起始时间，格式：yyyy-mm-dd hh:mm:ss，时间范围最长31天            |
| endtime | string | 是    | 统计结束时间，格式：yyyy-mm-dd hh:mm:ss，时间范围最长31天           |
| extnumber | string | 否    | 分机号，多个分机号用英文逗号隔开；留空统计全部坐席            |
| granularity | string | 否    | 统计粒度：total时间范围汇总、day按天统计            |
| currentpage | int | 否   | 第几页            |
| itemsperpage | int | 否    | 分页数量            |

#### 接口请求示例（PHP）

```
<?php
    $apiUrl = 'http://127.0.0.1:8080';
    $postFields = [
        'service'   => 'App.Sip_Cdr.GetRecodeFile',
        'token'     => 'ABCDEFG',
        'starttime'  => 'yyyy-mm-dd hh:mm:ss',
        'endtime'  => 'yyyy-mm-dd hh:mm:ss',
        'extnumber'  => '121212',
        'granularity'  => 'day',
    ];
    $curl = curl_init();
    curl_setopt($curl, CURLOPT_URL, $apiUrl);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $postFields);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $response = curl_exec($curl);
    $curlError = curl_error($curl);
    curl_close($curl);
    var_dump($response);
?>

```

#### 返回数据结构示例

```
{
    "ret": 200,
    "data": {
        "status": 0,
        "desc": "success",
        "result": {
            "totalitems": 1,
            "currentpage": 1,
            "itemsperpage": 20,
            "stats": [
                {
                    "extnumber": "90020002",
                    "total_calls": 1,
                    "answered_calls": 0,
                    "unanswered_calls": 1,
                    "answer_rate": 0,
                    "total_talk_seconds": 0,
                    "avg_talk_seconds": 0,
                    "avg_wait_seconds": 18
                }
            ]
        },
        "reqtime": 1788932971,
        "rsptime": 1788932972
    },
    "msg": ""
}

```

#### 返回参数说明

| 参数名         | 类型     | 说明         |
| :---------- | :----- | :--------- |
| result      | objest | 返回的结果集     |