124 lines
5.1 KiB
PHP
124 lines
5.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Created by Vim
|
|
* User: lcc
|
|
* Desc: 晓致拨号回调
|
|
* Date: 2021/4/14
|
|
* Time: 19:15
|
|
*/
|
|
class Xzcall extends HD_Controller
|
|
{
|
|
|
|
private $log_file;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->log_file = 'call_xz.log';
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
debug_log("start function:" . __FUNCTION__, $this->log_file);
|
|
$data = $this->input->post();
|
|
debug_log('data:' . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
if ($data && $data['seqId']) {
|
|
$row = $this->receiver_xz_model->get(array('call_id' => $data['seqId']));
|
|
if ($row) {
|
|
$jsondata = json_decode($row['json_data'], true);
|
|
$data['uname'] = $jsondata['uname'];
|
|
$data['brand_id'] = $jsondata['brand_id'];
|
|
$up_data['caller_state'] = $data['status'];
|
|
$up_data['status'] = 1;
|
|
$data['mid'] && $up_data['mid'] = $data['mid'];
|
|
$data['to'] && $up_data['called_num'] = $data['to'];
|
|
$data['from'] && $up_data['caller_num'] = $data['from'];
|
|
if ($data['callAnswer']) {
|
|
$up_data['duration'] = $data['callEnd'] - $data['callAnswer'];
|
|
$up_data['answer_time'] = $this->getMsecToMescdate($data['callAnswer']);
|
|
}
|
|
$data['callStart'] && $up_data['start_time'] = $this->getMsecToMescdate($data['callStart']);
|
|
$data['callEnd'] && $up_data['end_time'] = $this->getMsecToMescdate($data['callEnd']);
|
|
$up_data['json_data'] = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$this->receiver_xz_model->update($up_data, ['id' => $row['id']]);
|
|
if ($row['cf_id'] && $row['cf_platform'] == 'admin' && $row['cf_title'] == 'clues') { //后台线索池拨打电话回调
|
|
$admin_id = $row['cf_uid'];
|
|
$this->load->model('sys/sys_admin_model');
|
|
$admin = $this->sys_admin_model->get(array('id' => $admin_id));
|
|
$addData = array(
|
|
'clue_id' => $row['cf_id'],
|
|
'uid' => $admin_id,
|
|
'uname' => $admin['username'] ? $admin['username'] : '',
|
|
'type' => 2,//类型 0 普通 1短信 2电话
|
|
'log' => $row['id'],
|
|
'c_time' => time()
|
|
);
|
|
$this->mdOplogs->add($addData);
|
|
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
|
|
$xcall = new Xcall();
|
|
//解绑
|
|
$xcall->SWunbind($data['to'], $data['virtualMobile']);
|
|
}
|
|
} else {
|
|
debug_log("error: 未找到拨打记录", $this->log_file);
|
|
}
|
|
}
|
|
debug_log("end " . __FUNCTION__, $this->log_file);
|
|
echo '{"result":"0","error":""}';
|
|
}
|
|
|
|
//录音推送地址
|
|
public function video()
|
|
{
|
|
$data = $this->input->post();
|
|
debug_log("start function:" . __FUNCTION__, $this->log_file);
|
|
debug_log('data:' . json_encode($data, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
$row = $this->receiver_xz_model->get(array('mid' => $data['mid']));
|
|
if ($row) {
|
|
$jsondata = json_decode($row['json_data'], true);
|
|
if ($data['getFileUrl']) {
|
|
require_once COMMPATH . 'third_party/Xcall/Xcall.php';
|
|
$xcall = new Xcall();
|
|
$result = $xcall->getFile($data['getFileUrl'], $data['mid'], $data['tag']);
|
|
if ($result['code']) { //上传七牛
|
|
$this->load->library('qiniu');
|
|
$filename = $this->qiniu->getFileName($data['mid'], 'mp3', 'xz_video_');
|
|
$q_res = $this->qiniu->save($filename, $result['data']);
|
|
if (!$q_res) {
|
|
debug_log('error:文件上传七牛失败', $this->log_file);
|
|
} else {
|
|
$up_data['rec_url'] = $q_res['url'];
|
|
}
|
|
} else {
|
|
debug_log('error:' . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file);
|
|
}
|
|
}
|
|
$jsondata['file_info'] = $data;
|
|
$up_data['json_data'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE);
|
|
$this->receiver_xz_model->update($up_data, ['id' => $row['id']]);
|
|
}
|
|
debug_log("end " . __FUNCTION__, $this->log_file);
|
|
echo '{"result":"0","error":""}';
|
|
}
|
|
|
|
/**
|
|
* 毫秒转日期
|
|
*/
|
|
private function getMsecToMescdate($msectime)
|
|
{
|
|
$msectime = $msectime * 0.001;
|
|
if (strstr($msectime, '.')) {
|
|
sprintf("%01.3f", $msectime);
|
|
list($usec, $sec) = explode(".", $msectime);
|
|
$sec = str_pad($sec, 3, "0", STR_PAD_RIGHT);
|
|
} else {
|
|
$usec = $msectime;
|
|
$sec = "000";
|
|
}
|
|
$date = date("Y-m-d H:i:s.x", $usec);
|
|
return $mescdate = str_replace('x', $sec, $date);
|
|
}
|
|
}
|