290 lines
12 KiB
PHP
290 lines
12 KiB
PHP
<?php
|
|
require_once COMMPATH . 'third_party/Ycall/Ycall.php';
|
|
|
|
class Yxcall extends HD_Controller
|
|
{
|
|
private $log_file;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->log_file = 'call.log';
|
|
$this->load->model('receiver/receiver_yx_model');
|
|
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
|
$this->load->library('receiver/customers_entity');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
debug_log("start", $this->log_file);
|
|
$str = file_get_contents('php://input');
|
|
debug_log('string:' . $str, $this->log_file);
|
|
$data = json_decode($str, true);
|
|
if ($data && $data['customerData']) {
|
|
$row = $this->receiver_yx_model->get(array('call_id' => $data['customerData']));
|
|
if ($row) {
|
|
$jsondata = json_decode($row['json_data'], true);
|
|
$data['uname'] = $jsondata['uname'];
|
|
$up_data['caller_state'] = $data['callerState'];
|
|
$up_data['status'] = 1;
|
|
$data['displayNumber'] && $up_data['mid'] = $data['displayNumber'];
|
|
$data['calleeNumber'] && $up_data['called_num'] = $data['calleeNumber'];
|
|
$data['callerNumber'] && $up_data['caller_num'] = $data['callerNumber'];
|
|
if ($data['calleeDuration'] > 0) {
|
|
$up_data['duration'] = $data['calleeDuration'];
|
|
$up_data['answer_time'] = $data['callerAnsweredTime'];
|
|
}
|
|
$data['startCallTime'] && $up_data['start_time'] = $data['startCallTime'];
|
|
$data['recUrl'] && $up_data['rec_url'] = $data['recUrl'];
|
|
$data['endTime'] && $up_data['end_time'] = $data['endTime'];
|
|
$up_data['json_data'] = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
$this->receiver_yx_model->update($up_data, ['id' => $row['id']]);
|
|
if ($row['cf_id'] && $row['cf_platform'] == 'admin') { //后台
|
|
$admin_id = $row['cf_uid'];
|
|
$this->load->model('sys/sys_admin_model');
|
|
$admin = $this->sys_admin_model->get(array('id' => $admin_id));
|
|
$addData = array(
|
|
'uid' => $admin_id,
|
|
'uname' => $admin['username'] ? $admin['username'] : '',
|
|
'type' => 2,//类型 0 普通 1短信 2电话
|
|
'log' => $row['id'],
|
|
'c_time' => time()
|
|
);
|
|
if ($row['cf_title'] == 'clues') {//线索拨打电话回调
|
|
$this->load->model('receiver/receiver_clue_oplogs_model', 'mdOplogs');
|
|
$addData['clue_id'] = $row['cf_id'];
|
|
} else if ($row['cf_title'] == 'customer') {//客户拨打电话回调
|
|
$this->load->model('receiver/receiver_customer_oplogs_model', 'mdOplogs');
|
|
$addData['customer_id'] = $row['cf_id'];
|
|
} else if ($row['cf_title'] == 'owners') {//车主拨打电话回调
|
|
$this->load->model('receiver/receiver_owners_oplogs_model', 'mdOplogs');
|
|
$addData['own_id'] = $row['cf_id'];
|
|
}
|
|
$this->mdOplogs->add($addData);
|
|
$xcall = new Xcall($this->admin_config);
|
|
//解绑
|
|
$xcall->SWunbind($data['to'], $data['virtualMobile']);
|
|
} elseif ($row['cf_id'] && $row['cf_platform'] == 'api') { //理车宝
|
|
$ycall = new Ycall();
|
|
//解绑
|
|
$result = $ycall->AXBUnbind($data['displayNumber'], $data['calleeNumber'], $data['callerNumber']);
|
|
//删除redis
|
|
$cache_key = "XZ_LICHEB_MOBILEA_{$data['calleeNumber']}_MOBILEB_{$data['callerNumber']}_{$row['cf_uid']}";
|
|
$redis = &load_cache('redis');
|
|
$redis->delete($cache_key);
|
|
$cust = $this->customers_model->get(['id' => $row['cf_id']]);
|
|
$visit = $row['cf_title'] == 'customer' ? 1 : 0;
|
|
$this->customers_entity->add_log_visit($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2, $visit);
|
|
}
|
|
} else {
|
|
debug_log("error: 未找到拨打记录", $this->log_file);
|
|
}
|
|
}
|
|
debug_log("end", $this->log_file);
|
|
die(json_encode(array('resultCode' => 200)));
|
|
}
|
|
|
|
//未绑定关系用户打入指定手机号
|
|
public function axb()
|
|
{
|
|
$this->config->load('ycall', TRUE);
|
|
$mobile_list = $this->config->item('mobile_list', 'ycall');
|
|
/**设置为平台分配的account*/
|
|
$account = "985437";
|
|
/**设置为平台分配的token*/
|
|
$token = "5c5ee9cfcb2948a1aadefc445cf96b13";
|
|
require_once(COMMPATH . "/third_party/Ycall/sdk/PrivacyUnbindBoody.php");
|
|
require_once(COMMPATH . "/third_party/Ycall/sdk/PrivacyAxbBindBody.php");
|
|
require_once(COMMPATH . "/third_party/Ycall/sdk/PrivacyAxTransferBody.php");
|
|
require_once(COMMPATH . "/third_party/Ycall/sdk/WinnerVoiceSender.php");
|
|
foreach ($mobile_list as $key => $value) {
|
|
$axTransferBody = new PrivacyAxTransferBody();
|
|
$axTransferBody->transferMiddleNumber = $value;
|
|
$axTransferBody->transferToNumberA = '19959277910';
|
|
$axTransferBody->callRec = 1;
|
|
$axTransferBody->callbackUrl = "https://api.haodian.cn/plan/yxcall";
|
|
$sender = new WinnerVoiceSender($account, $token, true);
|
|
$result = $sender->sendRequest('/voice/1.0.0/axbTransfer', json_encode($axTransferBody));
|
|
var_dump($result);
|
|
}
|
|
}
|
|
|
|
//后台接单宝添加日志
|
|
private function jdb_add_log($admin_id, $rc_id, $log_id, $duration)
|
|
{
|
|
$this->load->model('app/jdb/receiver_oplogs_model');
|
|
$this->load->model('app/jdb/receiver_customers_model');
|
|
$this->load->model('sys/sys_admin_model');
|
|
$admin = $this->sys_admin_model->get(array('id' => $admin_id));
|
|
$data = array(
|
|
'rc_id' => $rc_id,
|
|
'admin_id' => $admin_id,
|
|
'admin_name' => $admin['username'],
|
|
'type' => 4,
|
|
'log' => $log_id,
|
|
'c_time' => time()
|
|
);
|
|
$res = $this->receiver_oplogs_model->add($data);//增加操作记录
|
|
if ($res) {
|
|
$updateData = array('last_admin_id' => $admin_id, 'last_op_time' => date('Y-m-d H:i:s'));
|
|
$duration && $updateData['call_records = call_records+1'] = null;
|
|
$this->receiver_customers_model->update($updateData, array('id' => $rc_id));
|
|
}
|
|
}
|
|
|
|
//下载链接到七牛云
|
|
public function down_video()
|
|
{
|
|
$redis = &load_cache('redis');
|
|
$key = "RECEIVER_LAST_ID";
|
|
$last_id = $redis->get($key);
|
|
$where = array(
|
|
"rec_url <> ''" => null,
|
|
'c_time<' => time() - 50 * 60
|
|
);
|
|
if ($last_id) {
|
|
$where['id>'] = $last_id;
|
|
} else {
|
|
$where["rec_url like '%winnerlook-voice.oss-cn-hangzhou.aliyuncs.com%'"] = null;
|
|
}
|
|
$count = $this->receiver_yx_model->count($where);
|
|
$failed_num = $success_num = $do_num = 0;
|
|
if ($count) {
|
|
$rows = $this->receiver_yx_model->select($where, 'id asc', 1, 20, 'id,rec_url');
|
|
foreach ($rows as $key => $val) {
|
|
$file = $this->upload($val['rec_url']);
|
|
if ($file) {
|
|
$this->receiver_yx_model->update(array('rec_url' => $file), array('id' => $val['id']));
|
|
$success_num++;
|
|
} else {
|
|
$failed_num++;
|
|
}
|
|
$do_num++;
|
|
$last_id = $val['id'];
|
|
}
|
|
$redis->save($key, $last_id);
|
|
}
|
|
echo "do_num:{$do_num},success_num:{$success_num},failed_num:{$failed_num}";
|
|
}
|
|
|
|
private function upload($url, $i = '')
|
|
{
|
|
$this->load->helper('image');
|
|
$arr = explode('?', $url);
|
|
$this->load->library('qiniu');
|
|
$filename = $this->qiniu->getFileName($arr[0] . $i);
|
|
$filename = 'yx/' . $filename;
|
|
$info = $this->qiniu->getInfo($filename);
|
|
if ($info) {
|
|
return $filename;
|
|
} else {
|
|
$file = $this->qiniu->fetch($url, $filename);
|
|
return $file ? $file['file'] : '';
|
|
}
|
|
}
|
|
|
|
//检测录音文件为空的数据
|
|
public function check_wav()
|
|
{
|
|
$this->load->model('app/jdb/receiver_yx_model');
|
|
$cache = $this->input->get('cache');
|
|
$size = $this->input->get('size');
|
|
!$size && $size = 20;
|
|
$where = array(
|
|
"duration>" => 0,
|
|
);
|
|
$redis = &load_cache('redis');
|
|
$save_key = "RECEIVER_CHECK_WAV_LAST_ID";
|
|
if (!$cache) {
|
|
$last_id = $redis->get($save_key);
|
|
$last_id && $where['id>'] = $last_id;
|
|
}
|
|
$total = $this->receiver_yx_model->count($where);
|
|
if ($total) {
|
|
$rows = $this->receiver_yx_model->select($where, 'id asc', 1, $size, 'id,call_id,rec_url');
|
|
$this->load->library('qiniu');
|
|
foreach ($rows as $key => $val) {
|
|
$filename = $val['rec_url'];
|
|
$info = $this->qiniu->getInfo($filename);
|
|
if (!$info['fsize']) {
|
|
debug_log(json_encode($val, JSON_UNESCAPED_UNICODE), 'jdb_call_null_rec_url.log');
|
|
}
|
|
$last_id = $val['id'];
|
|
}
|
|
$res = $redis->save($save_key, $last_id);
|
|
}
|
|
$left = $total > count($rows) ? $total - count($rows) : 0;
|
|
echo 'total:' . $total . ',left:' . $left;
|
|
}
|
|
|
|
//重新下载空录音文件
|
|
public function check_wav_update()
|
|
{
|
|
$this->load->model('app/jdb/receiver_yx_model');
|
|
$id = $this->input->get('id');
|
|
$cache = $this->input->get('cache');
|
|
$size = $this->input->get('size');
|
|
!$size && $size = 20;
|
|
$where = array(
|
|
"duration>" => 0,
|
|
);
|
|
$id && $where['id'] = $id;
|
|
$redis = &load_cache('redis');
|
|
$save_key = "RECEIVER_UPDATE_WAV_LAST_ID";
|
|
if (!$cache) {
|
|
$last_id = $redis->get($save_key);
|
|
$last_id && $where['id>'] = $last_id;
|
|
}
|
|
$total = $this->receiver_yx_model->count($where);
|
|
if ($total) {
|
|
$rows = $this->receiver_yx_model->select($where, 'id asc', 1, $size, 'id,call_id,rec_url,json_data');
|
|
$this->load->library('qiniu');
|
|
foreach ($rows as $key => $val) {
|
|
$filename = $val['rec_url'];
|
|
if (strpos($filename, 'hdi/yx') !== false) {
|
|
echo $val['id'];
|
|
$info = $this->qiniu->getInfo($filename);
|
|
if (!$info['fsize']) {
|
|
$res = $this->qiniu->rm($filename);
|
|
$res = $this->qiniu->rm(str_replace('hdi/', '', $filename));
|
|
$json_data = json_decode($val['json_data'], true);
|
|
$file = $this->upload($json_data['recUrl'], 1);
|
|
if ($file) {
|
|
$this->receiver_yx_model->update(array('rec_url' => $file), array('id' => $val['id']));
|
|
$val['result'] = $file;
|
|
debug_log(json_encode($val, JSON_UNESCAPED_UNICODE), 'jdb_call_update_rec_url.log');
|
|
}
|
|
}
|
|
if (!$id) {
|
|
$last_id = $val['id'];
|
|
}
|
|
}
|
|
}
|
|
$res = $redis->save($save_key, $last_id);
|
|
}
|
|
$left = $total > count($rows) ? $total - count($rows) : 0;
|
|
echo 'total:' . $total . ',left:' . $left;
|
|
}
|
|
|
|
//更新空录音通话记录
|
|
public function up_empty()
|
|
{
|
|
$this->load->model('app/jdb/receiver_yx_model');
|
|
$id = $this->input->get('id');
|
|
$callid = $this->input->get('callid');
|
|
$filename = $this->input->get('filename');
|
|
$where = array(
|
|
'id' => $id,
|
|
'call_id' => $callid
|
|
);
|
|
$row = $this->receiver_yx_model->get($where);
|
|
$filename = base64_decode($filename);
|
|
if ($row && $filename) {
|
|
$res = $this->receiver_yx_model->update(array('rec_url' => $filename), array('id' => $row['id']));
|
|
die(json_encode(array('code' => $res)));
|
|
} else {
|
|
die(json_encode(array('code' => 0)));
|
|
}
|
|
}
|
|
}
|