# 语音呼叫API  - IVR语音通知接口

#### 接口说明

实行对某目标号码的呼叫发起，通话被接通后，自动播放语音内容，播放完之后会根据用户的按键或不按键，可将通话转入到分机组中，系统会根据分机状态，及后台配置的分机状态回调地址发送对应的回调数据。

#### 请求方式

POST，form-data格式

#### 请求参数

| 参数名 | 类型 | 是否必须 | 说明 |
| --- | --- | --- | --- |
| service | string | 是 | App.Sip\_Call.PlayVoice |
| token | string | 是 | 通过授权接口获取的token |
| destnumber | string | 是 | 目标号码 |
| voicetype | int | 是 | 播放的语音文件类型。1:离线语音文件、2:在线语音(url) |
| voicefile | string | 是 | 离线音频文件名或在线语音url地址 |
| chengshudu | string | 是 | 1 |
| userid | string | 是 | 用户转入坐席的按键和转入坐席的分机组名示例：”1@extGroup-1” |
| disnumber | string | 否 | 主叫号码，留空则随机取一个主叫号码 |
| customuuid | string | 否 | 客户自定义数据，在通话结束之后的回调数据中原样返回 |

#### 接口请求示例（PHP）

    <?php
        $apiUrl = 'http://127.0.0.1:8080';
        $postFields = [
            'service'   => 'App.Sip_Call.PlayVoice',
            'token'     => 'ABCDEFG',
            'voicetype'  => 2,
            'destnumber'  => '13333333333',
            'voicefile'  => 'wwww.baidu.com/test.mp3',
            'chengshudu'  => 1,
            'userid'  => '1@extGroup-1',
            'disnumber'  => '13333333333',
            'customuuid'  => '13333333333'
        ];
        $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": "播放命令发送成功",
            "reqtime": 1581307099,
            "rsptime": 1581307099
        },
        "msg": ""
    }
    

#### 分机状态回调数据示例

    {
        "buuid":"f4ffad68-4a0f-11ea-812d-fbc8753285b6",
        "callee":"85322888486",
        "caller":"20280003",
        "companycode":"2028",
        "direction":"callout",
        "disnumber":"2120280001",
        "extnumber":"20280003",
        "isbleg":"true",
        "method":"2",
        "starttime":"1581124302",
        "status":"ring",
        "uuid":"f4ee8e7a-4a0f-11ea-8126-fbc8753285b6",
        "ip":"149.129.249.47"
    }
    

#### 回调字段说明

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| buuid | string | B侧唯一id |
| callee | string | 被叫号码（用户号码） |
| caller | string | 呼叫号码（分机号） |
| companycode | string | 公司码 |
| direction | string | 呼叫方向 callin 呼入、callout 呼出 |
| disnumber | string | 显示号码 |
| extnumber | string | 分机号 |
| isbleg | string | 是否B侧 |
| method | string | 呼叫方式、1分机、2手动、3接口、4双呼、5预测 |
| starttime | string | 呼叫开始时间 |
| status | string | 分机状态 ring 响铃 answer 接听 hangup 挂断 |
| uuid | string | 通话唯一id |
| ip | string | ip |

#### 接口返回说明

该接口请求之后会向目标号码呼叫，目标号码接通之后会直接播放语音文件中的内容。呼叫结果会在通话结束之后，以回调方式通知到后台配置的通话详单回调地址。

#### 回调数据结构示例

    {
        "answertime":"2020-02-09 12:32:51",
        "hangupcause":10001,
        "duration":13,
        "id":220739,
        "extnumber":"",
        "uuid":"3418035c-4af5-11ea-afb2-fbc8753285b6",
        "downloadip":"149.129.249.47",
        "customuuid":"110001168",
        "chengshudu":"0",
        "callmethod":6,
        "recordfilename":"1111.mp3",
        "companycode":9017,
        "memberid":"0",
        "hangupdirection":10040,
        "billsec":10,
        "endtime":"2020-02-09 12:33:01",
        "starttime":"2020-02-09 12:32:38",
        "type":"callout",
        "disnumber":"2190170001",
        "crmid":"0",
        "userkey":"",
        "destnumber":"85781218893"
    }
    

#### 回调数据字段说明

| 字段 | 类型 | 说明 |
| --- | --- | --- |
| answertime | string | 接听时间 |
| hangupcause | string | 挂断原因 |
| duration | string | 等待接听时长 |
| id | string | 话单id |
| extnumber | string | 分机号 |
| uuid | string | 通话唯一id |
| downloadip | string | 下载ip |
| customuuid | string | 自定义参数 |
| chengshudu | string | 自定义参数 |
| callmethod | string | 呼叫方式 |
| recordfilename | string | 通话文件名 |
| companycode | string | 公司码 |
| memberid | string | 自定义参数 |
| hangupdirection | string | 挂断方向 |
| billsec | string | 通话时长 |
| endtime | string | 挂机时间 |
| starttime | string | 呼叫时间 |
| type | string | 呼叫方式 |
| disnumber | string | 主叫号码 |
| crmid | string | 坐席id |
| userkey | string | 用户按键 |
| destnumber | string | 目标号码 |