/** * 双向回呼 * @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 添加成功处理逻辑 } }
/** * 取消回拨 * @param callSid 一个由32个字符组成的电话唯一标识符 * @param type 0: 任意时间都可以挂断电话;1 :被叫应答前可以挂断电话,其他时段返回错误代码;2: 主叫应答前可以挂断电话,其他时段返回错误代码;默认值为0。 */ function CallCancel($callSid, $type) { // 初始化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); // 调用取消回拨接口 $result = $rest->CallCancel($callSid, $type); 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 "CallCancel success!<br/>"; // 获取返回信息 echo "statusCode:" . $result->statusCode . "<br/>"; //TODO 添加成功处理逻辑 } }