diff --git a/app/Console/Commands/eslListen.php b/app/Console/Commands/eslListen.php index 4b8cb2b7..aa09e2f5 100644 --- a/app/Console/Commands/eslListen.php +++ b/app/Console/Commands/eslListen.php @@ -60,6 +60,7 @@ class eslListen extends Command } //====================== 接收事件参数验证 ==================== $eventarr = [ + 'CHANNEL_CALLSTATE', 'CHANNEL_ANSWER', 'RECORD_START', 'RECORD_STOP', @@ -95,11 +96,22 @@ class eslListen extends Command $info = $fs->serialize($received_parameters, "json"); $info = json_decode($info,true); $eventname = Arr::get($info,"Event-Name"); //事件名称 - $uuid = Arr::get($info,"Unique-ID"); //事件名称 - $CallerCallerIDNumber = Arr::get($info,"Caller-Caller-ID-Number"); //事件名称 - $CallerCalleeIDNumber = Arr::get($info,"Caller-Destination-Number"); //事件名称 + $uuid = Arr::get($info,"Unique-ID"); //UUID + $CallerCallerIDNumber = Arr::get($info,"Caller-Caller-ID-Number"); //主叫 + $CallerCalleeIDNumber = Arr::get($info,"Caller-Destination-Number"); //被叫 switch ($eventname){ + //呼叫状态 + case 'CHANNEL_CALLSTATE': + //是分机号才记录 + if (preg_match('/\d{4,5}/',$CallerCallerIDNumber)){ + $status = Arr::get($info,'Channel-Call-State'); + $uniqueid = Arr::get($info,'Caller-Unique-ID'); + Redis::set($CallerCallerIDNumber.'_state',$status); + Redis::setex($CallerCallerIDNumber.'_uuid',1200, $uniqueid); + } + break; + //通道应答 case 'CHANNEL_ANSWER': $otherUuid = Arr::get($info,"Other-Leg-Unique-ID"); $cdr_uuid = md5($uuid.Redis::incr('cdr_uuid_incr_key')); @@ -150,6 +162,7 @@ class eslListen extends Command unset($fullfile); } break; + //开始说话 case 'RECORD_START': $channel = Redis::get($uuid); if ($channel){ @@ -159,6 +172,7 @@ class eslListen extends Command Redis::set($uuid,json_encode($data)); } break; + //结束说话 case 'RECORD_STOP': if (Redis::get($this->asr_status_key)==1) { $channel = Redis::get($uuid); @@ -192,6 +206,7 @@ class eslListen extends Command unset($channel); } break; + //挂断 case 'CHANNEL_HANGUP_COMPLETE': $channel = Redis::get($uuid); if ($channel){ @@ -214,6 +229,7 @@ class eslListen extends Command $customer_caller = Arr::get($info,'variable_customer_caller',null); if (empty($otherType) || $otherType == 'originatee') { + Redis::del($CallerCallerIDNumber.'_uuid'); $data = [ 'table_name' => $this->cdr_table, 'leg_type' => 'A', diff --git a/app/Http/Controllers/Admin/SipController.php b/app/Http/Controllers/Admin/SipController.php index a2ce5995..91e1256b 100644 --- a/app/Http/Controllers/Admin/SipController.php +++ b/app/Http/Controllers/Admin/SipController.php @@ -31,7 +31,7 @@ class SipController extends Controller } $res = $query->orderByDesc('id')->paginate($request->get('limit', 30)); foreach ($res->items() as $d){ - $d->status = $d->getStatus($d->username); + //$d->status = $d->getStatus($d->username); } $data = [ 'code' => 0, diff --git a/app/Http/Controllers/ApiController.php b/app/Http/Controllers/ApiController.php index 80f39e8f..3099e8c2 100644 --- a/app/Http/Controllers/ApiController.php +++ b/app/Http/Controllers/ApiController.php @@ -73,10 +73,10 @@ class ApiController extends Controller } //检测10秒重复请求 - if(Redis::get('check_'.$data['exten'])!=null){ + if(Redis::get($data['exten'].'_check')!=null){ return Response::json(['code'=>1,'msg'=>'重复请求,请稍后再试']); }else{ - Redis::setex('check_'.$data['exten'],10,'exist'); + Redis::setex($data['exten'].'_check',10,'exist'); } //验证分机信息 @@ -167,7 +167,7 @@ class ApiController extends Controller $fs->bgapi($dialStr); $fs->disconnect(); //20分钟过期 - Redis::setex($data['exten'],1200, $aleg_uuid); + Redis::setex($data['exten'].'_uuid',1200, $aleg_uuid); return Response::json(['code'=>0,'msg'=>'呼叫成功','data'=>['uuid'=>$aleg_uuid,'time'=>date('Y-m-d H:i:s')]]); }catch (\Exception $exception){ Log::info("呼叫错误:".$exception->getMessage()); @@ -184,9 +184,9 @@ class ApiController extends Controller public function hangup(Request $request) { $exten = $request->get('exten'); - $uuid = !empty($exten) ? Redis::get($exten) : ''; - if(empty($uuid)){ - return Response::json(['code'=>0,'msg'=>'无通话']); + $uuid = Redis::get($exten.'_uuid'); + if($uuid == null){ + return Response::json(['code'=>0,'msg'=>'已挂断']); } $sip = Sip::where('username',$exten)->first(); if ($sip == null) { @@ -199,7 +199,7 @@ class ApiController extends Controller if ($fs->connect($service['host'],$service['port'],$service['password'])) { $fs->bgapi("uuid_kill",$uuid); $fs->disconnect(); - Redis::del($exten); + Redis::del($exten.'_uuid'); return Response::json(['code'=>0,'msg'=>'已挂断']); } diff --git a/app/Models/Sip.php b/app/Models/Sip.php index d4afb9a2..3aa0f0fe 100644 --- a/app/Models/Sip.php +++ b/app/Models/Sip.php @@ -3,7 +3,9 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Arr; use Illuminate\Support\Facades\Log; +use Illuminate\Support\Facades\Redis; class Sip extends Model { @@ -18,6 +20,18 @@ class Sip extends Model 'gateway_id', ]; + protected $appends = ['status','state']; + + public function getStateAttribute() + { + $state = Redis::get($this->username.'_state')??0; + return $this->attributes['state'] = Arr::get(config('freeswitch.channel_callstate'),$state,'-'); + } + + public function getStatusAttribute() + { + return $this->attributes['status'] = $this->getStatus($this->username); + } /** * 所属网关 diff --git a/config/freeswitch.php b/config/freeswitch.php index 457c06f8..5c805131 100644 --- a/config/freeswitch.php +++ b/config/freeswitch.php @@ -52,6 +52,14 @@ return [ 'random' => '随机振铃', ], + //呼叫状态 + 'channel_callstate' => [ + 'DOWN' => '空闲', + 'RINGING' => '响铃', + 'ACTIVE' => '通话中', + 'HANGUP' => '已挂断', + ], + //坐席状态status 'agent_status' => [ 'Logged Out' => '签出', diff --git a/resources/views/admin/sip/index.blade.php b/resources/views/admin/sip/index.blade.php index 779397fb..da2e486c 100644 --- a/resources/views/admin/sip/index.blade.php +++ b/resources/views/admin/sip/index.blade.php @@ -60,7 +60,8 @@ ,{field: 'effective_caller_id_number', title: '外显号码'} ,{field: 'outbound_caller_id_name', title: '出局名称'} ,{field: 'outbound_caller_id_number', title: '出局号码'} - ,{field: 'status', title: '状态'} + ,{field: 'status', title: '注册状态'} + ,{field: 'state', title: '呼叫状态'} ,{field: 'created_at', title: '添加时间'} ,{fixed: 'right', width: 220, align:'center', toolbar: '#options', title:'操作'} ]]