Beispiel #1
0
/**
 * 双向回呼
 * @param from 主叫电话号码
 * @param to 被叫电话号码
 * @param customerSerNum 被叫侧显示的客服号码  
 * @param fromSerNum 主叫侧显示的号码
 * @param promptTone 自定义回拨提示音    
 */
function callBack($from, $to, $customerSerNum, $fromSerNum, $promptTone)
{
    // 初始化REST SDK
    global $appId, $subAccountSid, $subAccountToken, $voIPAccount, $voIPPassword, $serverIP, $serverPort, $softVersion;
    $rest = new REST($serverIP, $serverPort, $softVersion);
    $rest->setSubAccount($subAccountSid, $subAccountToken, $voIPAccount, $voIPPassword);
    $rest->setAppId($appId);
    // 调用回拨接口
    echo "Try to make a callback,called is {$to} <br/>";
    $result = $rest->callBack($from, $to, $customerSerNum, $fromSerNum, $promptTone);
    if ($result == NULL) {
        echo "result error!";
        break;
    }
    if ($result->statusCode != 0) {
        echo "error code :" . $result->statusCode . "<br>";
        echo "error msg :" . $result->statusMsg . "<br>";
        //TODO 添加错误处理逻辑
    } else {
        echo "callback success!<br>";
        // 获取返回信息
        $callback = $result->CallBack;
        echo "callSid:" . $callback->callSid . "<br/>";
        echo "dateCreated:" . $callback->dateCreated . "<br/>";
        //TODO 添加成功处理逻辑
    }
}