Commit ad95db3a authored by hujun's avatar hujun

阿里云回调下载录音

parent f70e64b3
......@@ -144,13 +144,39 @@ class AliYunSecretReport extends BaseModel
return $data;
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListAll($field, $where) {
return $this->field($field)
->where($where)
->select();
}
/**
* @param $data
* @throws \Exception
*/
public function insertDataAll($data) {
$this->allowField(true)->saveAll($data);
}
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getFindData($field, $where) {
return $this->field($field)
->where($where)
->find();
}
}
\ No newline at end of file
......@@ -612,6 +612,7 @@ Route::group('task', [
'rongRecordingInformUrl' => ['task/PrivacyNumber/rongRecordingInformUrl', ['method' => 'post | get']],//隐私号码回调[录音通知]
'rongStatusInformUrl' => ['task/PrivacyNumber/rongStatusInformUrl', ['method' => 'post | get']],//隐私号码回调[状态通知]
'defaultFollowUp' => ['task/PrivacyNumber/defaultFollowUp', ['method' => 'post | get']], //默认跟进
'callBackDownVoice' => ['task/PrivacyNumber/callBackDownVoice', ['method' => 'post | get']], //回调录音
'updateShopTask' => ['task/JobTask/updateShopTask', ['method' => 'post | get']], //默认跟进
......
......@@ -20,7 +20,6 @@ use app\model\BindingPhone;
use app\model\GLandlordPhone;
use app\model\TAgentTotalCallModel;
use app\model\Users;
use think\Db;
use think\Log;
use think\Request;
......@@ -42,48 +41,6 @@ class PrivacyNumber
$this->m_user = new Users();
}
/**
* 阿里大于隐私号码回调处理
*
* @return string
*/
public function addReport()
{
$post_data = Request::instance()->param();
$post_data[0]['report_id'] = $post_data[0]['id'];
unset($post_data[0]['id']); //阿里大于返回是的id改为report_id
if ($post_data[0]['phone_no']) {
$agents_id = Db::table('a_agents')->where("phone='{$post_data[0]['phone_no']}' AND password IS NOT NULL AND status=0")->value('id');
if (empty($agents_id)) {
$agents_id = Db::table('a_agents_phone')->where(['phone'=>$post_data[0]['phone_no'], 'status'=>0])->value('agents_id');
}
$post_data[0]['agents_id'] = $agents_id;
$post_data[0]['users_id'] = Db::table('u_users')->where('user_phone', $post_data[0]['peer_no'])->value('id');
}
$call_time = strtotime($post_data[0]['release_time']) - strtotime($post_data[0]['start_time']);
$post_data[0]['time'] = $call_time;
if ($call_time > 0) {
$end_date = date('Y-m-d H:i:s', time());
$start_date = date('Y-m-d H:i:s', strtotime("-1 day"));
$num = Db::table('aliyun_secret_report')->where('phone_no', $post_data[0]['phone_no'])
->where('peer_no', $post_data[0]['peer_no'])
->where('create_time', 'between', [ $start_date, $end_date ])
->count('id');
if (empty($num)) {
$m_service = new ClientService();
$m_service->saveCallNumByUserId($post_data[0]['users_id']);
}
}
$this->m_secret_report->allowField(true)->save($post_data[0]);
Log::write(json_encode($post_data[0]), 'AliYunSecretReport'); //记录日志
return json_encode([ 'code' => 0, 'msg' => '接收成功' ]);
}
/**
* 阿里大于隐私号码回调处理
*
......@@ -135,13 +92,6 @@ class PrivacyNumber
if ($call_time > 0) {
$key = 'call_back_'.$v['phone_no'].'_'.$v['peer_no'].'_'.date('Y-m-d');
$time = $this->redis->get($key);
// if (empty($time)) {
// $end_date = date('Y-m-d', time());
// $start_date = date('Y-m-d', strtotime("-1 day"));
// $num = $this->m_secret_report->getCallNumber($post_data[0]['phone_no'], $post_data[0]['peer_no'], $start_date, $end_date);
// } else {
// $num = 1;
// }
if (!empty($time)) {
$num = 1;
}
......@@ -168,10 +118,7 @@ class PrivacyNumber
/**
* 下载录音 高峰期 一般是早上9-11点 下午2-4点
*
* @throws \Aliyun\Core\Exception\ClientException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @return false|string|void
*/
public function queryRecordFile()
{
......@@ -190,8 +137,10 @@ class PrivacyNumber
$where['record_down'] = 1;
}
if (empty($param['date'])) {
$date = date('Y-m-d');
$is_today = date('Y-m-d', strtotime($param['date'])) == date('Y-m-d') ? 1:0;
if (empty($param['date']) && $is_today) {
$date = date('Y-m-d', time() - 5400); //录音生成时间15分钟左右
} else {
$date = date('Y-m-d', strtotime($param['date']));
}
......@@ -199,14 +148,27 @@ class PrivacyNumber
$fields = 'id,call_id,call_time,voice_file,type,record_down,mp3_url,create_time';
$where['time'] = [ '>', 0 ];
$where['type'] = [ '>', 0 ];
$down_data = $this->m_secret_report->secretReportAll($fields, $where, 2000);
$where['create_time'] = [ '>', $date ];
try {
$down_data = $this->m_secret_report->secretReportAll($fields, $where, 3000);
} catch (\Exception $e) {
Log::write($e->getMessage(), 'voice_down_select_error'); //记录日志
return ;
}
$is_down = '';
$is_down = '';
foreach ($down_data as $k => $v) {
$create_time = date('Y-m-d', strtotime($v['create_time']));
if ($v['type'] == 1) {
/*阿里云音频下载*/
$result_data = PlsDemo::queryRecordFileDownloadUrl($v['call_id'], $v['call_time']);
try {
/*阿里云音频下载*/
$result_data = PlsDemo::queryRecordFileDownloadUrl($v['call_id'], $v['call_time']);
} catch (\Exception $e) {
Log::write($e->getMessage(), 'voice_down_getVoiceUrl_error'); //记录日志
return ;
}
if (isset($result_data->Message) && $result_data->Message == 'OK') {
$down_url = isset($result_data->DownloadUrl) ? explode('?', $result_data->DownloadUrl) : $result_data->DownloadUrl;
......@@ -240,7 +202,7 @@ class PrivacyNumber
}
}
return;
return ;
}
/**
......@@ -641,4 +603,64 @@ class PrivacyNumber
echo '释放:'.$key.'组';
return ;
}
/**
* 阿里云回调下载录音
*/
public function callBackDownVoice() {
/**
* pool_key String 对应的号池Key
* subs_id Number 对应的三元组的绑定关系ID
* call_id String 对应的呼叫记录的call_id
* call_time Date 呼叫时间
*/
$post_data = Request::instance()->param();
$m_secret_report = new AliYunSecretReport();
$filed_string = 'id,voice_file';
if (isset($post_data[0]['call_id'])) {
$result = $post_data;
} else {
$result = [$post_data];
}
foreach ($result as $k => $v) {
if ((empty($v['call_id']) && empty($v['call_time'])) || !empty($secret_data['record_down'])){
continue;
}
$where['call_id'] = $v['call_id'];
$where['call_time'] = $v['call_time'];
try {
$secret_data = $m_secret_report->getFindData($filed_string, $where);
$result_data = PlsDemo::queryRecordFileDownloadUrl($v['call_id'], $v['call_time']);
} catch (\Exception $e) {
Log::write($e->getMessage(), 'voice_down_callBack_error'); //记录日志
return ;
}
if (isset($result_data->Message) && $result_data->Message == 'OK') {
$down_url = isset($result_data->DownloadUrl) ? explode('?', $result_data->DownloadUrl) : $result_data->DownloadUrl;
$file_name = basename($down_url[0]);
$is_down = down_file($result_data->DownloadUrl, PHONE_VOICE, $file_name, date('Y-m-d', strtotime($v['call_time'])));
if (file_exists($is_down)) {
$update_data[$k]['id'] = $secret_data['id'];
$update_data[$k]['record_down'] = 1;
$update_data[$k]['voice_file'] = date('Ymd') . '/' . basename($is_down);
}
}
}
if (isset($update_data)) {
try {
$m_secret_report->insertDataAll($update_data);
} catch (\Exception $e) {
Log::write($e->getMessage(), 'voice_down_callBack_save_error'); //记录日志
return ;
}
}
return ;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment