Commit de20a2d2 authored by clone's avatar clone

Merge branch 'test'

parents 23efa2e0 2b3bddbe
...@@ -11,22 +11,22 @@ namespace app\api_broker\controller; ...@@ -11,22 +11,22 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\untils\PlsDemo; use app\api_broker\untils\PlsDemo;
use app\api_broker\untils\RongDemo; use app\api_broker\untils\RongDemo;
use app\extra\RedisExt;
use app\model\AAgentsPhone; use app\model\AAgentsPhone;
use app\model\AliYunPhone; use app\model\AliYunPhone;
use app\model\BindingPhone; use app\model\BindingPhone;
use app\model\SecretReport; use think\Cache;
use think\Db;
use think\Log; use think\Log;
class CellPhone extends Basic class CellPhone extends Basic
{ {
protected $code = 200; protected $code = 200;
protected $data = []; protected $data = [];
protected $msg = ""; protected $msg = "";
/** /**
* 绑定手机号 * 绑定手机号
* 解绑之后有延迟(15s) * 解绑之后有延迟
* *
* @return \think\Response * @return \think\Response
* @throws \think\Exception * @throws \think\Exception
...@@ -34,13 +34,13 @@ class CellPhone extends Basic ...@@ -34,13 +34,13 @@ class CellPhone extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function bindAXB() public function bindAXB() {
{
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$params = $this->request->param();
if (empty($this->params['phone_a']) || empty($this->params['phone_b'])) { if (empty($params['phone_a']) || empty($params['phone_b'])) {
$this->code = 101; $this->code = 101;
$this->msg = 'phone_a or phone_b is null'; $this->msg = 'phone_a or phone_b is null';
return $this->response(101, '参数错误,请联系运营人员!'); return $this->response(101, '参数错误,请联系运营人员!');
} }
...@@ -48,97 +48,75 @@ class CellPhone extends Basic ...@@ -48,97 +48,75 @@ class CellPhone extends Basic
$phone_b = $this->params['phone_b'];//客户手机号 $phone_b = $this->params['phone_b'];//客户手机号
$record = true; //是否录音 $record = true; //是否录音
$redis = RedisExt::getRedis(); $setting = Cache::get('Setting'); //获取配置
$is_privacy = $redis->get('s_is_privacy');
//0不使用隐私号码 1阿里云 2容联云 //0不使用隐私号码 1阿里云 2容联云
if ($is_privacy == 0) { if ($setting['is_privacy'] != 0) {
$this->data = [ 'phone' => $phone_b ]; $aliYunPhone = new AliYunPhone();
$bind = new BindingPhone();
$m_report = new SecretReport(); $where['a.status'] = 1;
$report_data['phone_no'] = $phone_a; $where['a.phone_a'] = $phone_a;
$report_data['secret_no'] = $phone_b; $where['a.phone_b'] = $phone_b;
$report_data['peer_no'] = $phone_b; $where['a.type'] = $setting['is_privacy'];
$report_data['call_type'] = 1;
$report_data['record_down'] = 3;
$m_report->editData($report_data); //记录不使用隐号拨打记录
return $this->response($this->code, $this->msg, $this->data);
}
$bind = new BindingPhone();
$where['a.status'] = 1;
$where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b;
$where['a.type'] = $is_privacy;
$phone_x = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码
if (!empty($phone_x['phone_x'])) { $phone_x = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码
$this->data = [ 'phone' => $phone_x['phone_x'] ];
$this->msg = '已绑定,返回隐私号码。';
return $this->response($this->code, $this->msg, $this->data); //绑定过了,返回隐号
}
$day_num = $redis->get('s_day_num'); if ($phone_x != NULL) {
$release = 1; //是否释放 $this->data = ['phone' => $phone_x['phone_x']];
if (empty($day_num)) {
$time = _EXPIRATION;
} else {
if (empty($this->params['landlord'])) {
$time = date('Y-m-d H:i:s', strtotime("+{$day_num} day"));
} else { } else {
$day_num = $redis->get('s_landlord_phone_day'); $phone_x = $aliYunPhone->getAliYunPhone($phone_a, $phone_b, $setting['is_privacy']);
if ($day_num == 0) { //是否还有未绑定的中间号码
$time = date('Y-m-d H:i:s', time() + 5); if ($phone_x) {
$release = 0; if (empty($setting['day_num'])) {
} else { $time = _EXPIRATION;
$time = date('Y-m-d H:i:s', strtotime("+{$day_num} day")); } else {
} $setting['day_num'] += 1;
} $time = date('Y-m-d H:i:s',strtotime("+{$setting['day_num']} day"));
} }
if ($is_privacy == 1) {
/*阿里云*/
try {
$result = PlsDemo::bindAxb($phone_a, $phone_b, $time, $record);
} catch (\Exception $e) {
return $this->response(101, '参数异常,无法呼叫,请联系运营人员!');
}
if ($result->Code == 'OK') { if($setting['is_privacy'] == 1) {
//记录绑定 /*阿里云*/
$bind->recordBindPhone($result->SecretBindDTO->SecretNo, $phone_a, $phone_b, $record, $time, $result, '', $is_privacy, $release); $result = PlsDemo::bindAxb($phone_a, $phone_b, $time, $record, $phone_x['phone_x']);
if ($result->Message == 'OK') {
$aliYunPhone->editStatus($phone_x, $phone_a, $phone_b, $record, $time, $result,'',$setting['is_privacy']); //记录绑定
$this->msg = '绑定成功。';
$this->data = ['phone' => $phone_x['phone_x']];
} else {
$phone_x_array[] = $phone_x['phone_x'];
//尝试5次绑定
for ($i = 1; $i < 5; $i++) {
$phone_x = $aliYunPhone->getAliYunPhone($phone_a, $phone_b, $setting['is_privacy'], $phone_x_array);
$result = PlsDemo::bindAxb($phone_a, $phone_b, $time, $record, $phone_x); //再尝试一下
if ($result->Message == 'OK') {
$aliYunPhone->editStatus($phone_x, $phone_a, $phone_b, $record, $time, $result,'',$setting['is_privacy']); //记录绑定
$this->msg = '绑定成功。';
$this->data = ['phone' => $phone_x['phone_x']];
break;
} else {
$phone_x_array[] = $phone_x; //记录绑定冲突号码,重新分配
}
}
if ($result->Message != 'OK') {
$this->code = 101;
$this->msg = '拨号失败,10秒再试,再无法拨号请联系请联系运营人员!';
}
}
}else { }else {
/*容联云*/ /*容联云*/
$Rong = new RongDemo(); $Rong = new RongDemo();
$record2 = empty($this->params['record']) ? 'true' : 'false'; /* 是否录音(容联云规定string类型)*/ $record2 = empty($this->params['record']) ? 'true' : 'false'; /* 是否录音(容联云规定string类型)*/
$this->msg = '绑定成功。'; /*计算有效期*/
$this->data = [ 'phone' => $result->SecretBindDTO->SecretNo ]; if(empty($setting['day_num'])){
$yx_time=$setting['day_num']*60*60*24;
} elseif ($result->Code == 'isv.NO_AVAILABLE_NUMBER') { }else{
$this->code = 101; $yx_time=604800;
$this->msg = '号码使用完,请联系运营人员。'; }
$this->data = []; $result = $Rong->setNumber($phone_a, $phone_b, $phone_x['phone_x'], $phone_x['area'],$yx_time,$record2);
} else { /*绑定成功*/
$this->code = 101;
$this->msg = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!';
$this->data = [];
}
} else {
/*容联云*/
$Rong = new RongDemo();
$record2 = empty($this->params['record']) ? 'true' : 'false'; /* 是否录音(容联云规定string类型)*/
$aliYunPhone = new AliYunPhone();
$phone_x = $aliYunPhone->getAliYunPhone($phone_a, $phone_b, $is_privacy); //获取未绑定隐号
$result = $Rong->setNumber($phone_a, $phone_b, $phone_x['phone_x'], $phone_x['area'], $time, $record2);
/*绑定成功*/
if ($result['statusCode'] == '000000') { if ($result['statusCode'] == '000000') {
$bind->recordBindPhone($phone_x['phone_x'], $phone_a, $phone_b, $record, $time, 0, $result['data']['mappingId'], $is_privacy, $release); //记录绑定 $bind->recordBindPhone($phone_x['phone_x'], $phone_a, $phone_b, $record, $time, 0, $result['data']['mappingId'], $is_privacy, $release); //记录绑定
...@@ -171,7 +149,23 @@ class CellPhone extends Basic ...@@ -171,7 +149,23 @@ class CellPhone extends Basic
} }
} }
Log::write(json_encode($result), 'AliYunBindAxb'); //记录日志 Log::write(json_encode($result),'AliYunBindAxb'); //记录日志
} else {
$this->code = 102;
$this->msg = '号码使用完,请联系运营人员。';
}
}
} else {
$this->data = ['phone' => $phone_b];
Db::table('aliYun_secret_report')->insert([
'phone_no' => $phone_a,
'secret_no' => $phone_b,
'peer_no' => $phone_b,
'call_type' => 1,
'record_down' => 3,
]);
}
return $this->response($this->code, $this->msg, $this->data); return $this->response($this->code, $this->msg, $this->data);
} }
...@@ -180,17 +174,16 @@ class CellPhone extends Basic ...@@ -180,17 +174,16 @@ class CellPhone extends Basic
* *
* @return \think\Response * @return \think\Response
*/ */
public function updateBindAXB() public function updateBindAXB() {
{
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$params = $this->request->param(); $params = $this->request->param();
if ($params['phone_x'] && ($params['phone_a'] || $params['phone_b'])) { if ($params['phone_x'] && ($params['phone_a'] || $params['phone_b'])) {
$bind = new BindingPhone(); $bind = new BindingPhone();
if ($params['phone_a']) { if ($params['phone_a']) {
$subId = $bind->getSubsId($params['phone_x'], $params['phone_a'], '', 1); //跟换B号码 $subId = $bind->getSubsId($params['phone_x'], $params['phone_a'], '',1); //跟换B号码
} else { } else {
$subId = $bind->getSubsId($params['phone_x'], '', $params['phone_b'], 1); //更好A号码 $subId = $bind->getSubsId($params['phone_x'], '', $params['phone_b'],1); //更好A号码
} }
$resutl = PlsDemo::updateSubscription($params['type'], $subId, $this->params['phone_x'], $this->params['phone_a'], $this->params['phone_b'], $params['date']); $resutl = PlsDemo::updateSubscription($params['type'], $subId, $this->params['phone_x'], $this->params['phone_a'], $this->params['phone_b'], $params['date']);
...@@ -206,7 +199,7 @@ class CellPhone extends Basic ...@@ -206,7 +199,7 @@ class CellPhone extends Basic
$this->code = 101; $this->code = 101;
$this->msg = 'phone is null'; $this->msg = 'phone is null';
} }
return $this->response($this->code, $this->msg, $this->data); return $this->response($this->code, $this->msg,$this->data);
} }
/** /**
...@@ -215,63 +208,54 @@ class CellPhone extends Basic ...@@ -215,63 +208,54 @@ class CellPhone extends Basic
* @return \think\Response * @return \think\Response
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function agentsUnBind() public function agentsUnBind() {
{
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$phone_x = $this->params['phone_x']; $phone_x = $this->params['phone_x'];
$phone_a = $this->params['phone_a']; $phone_a = $this->params['phone_a'];
$phone_b = $this->params['phone_b']; $phone_b = $this->params['phone_b'];
if (empty($phone_x) || empty($phone_a) || empty($phone_b)) { if ($phone_x && $phone_a && $phone_b) {
$this->code = 101; $setting = Cache::get('Setting'); //获取配置
$this->msg = '解除关系参数错误,请联系运营人员!'; $phone = new BindingPhone();
return $this->response($this->code, $this->msg);
} if ($setting['is_privacy'] == 1) {
$phone = new BindingPhone(); /*阿里云*/
$subsId = $phone->getSubsId($phone_x,$phone_a,$phone_b,1,'subsId');
$redis = RedisExt::getRedis(); if ($subsId) {
$is_privacy = $redis->get('s_is_privacy'); $result = PlsDemo::unbindSubscription($subsId, $phone_x);/*解绑*/
$is_privacy = $is_privacy != '0' ? $is_privacy : 0; if ($result->Message == 'OK') {
$phone->unBind($phone_x, $phone_a, $phone_b);
if ($is_privacy == 1) { } else {
/*阿里云*/ $this->code = 101;
$subsId = $phone->getSubsId($phone_x, $phone_a, $phone_b, 1, 'subsId'); $this->msg = '解除绑定关系失败,请联系运营!';
if ($subsId) { }
$result = PlsDemo::unbindSubscription($subsId, $phone_x);/*解绑*/
if ($result->Message == 'OK') {
$phone->unBind($phone_x, $phone_a, $phone_b);
} else { } else {
$this->code = 101; $this->code = 200;
$this->msg = '解除绑定关系失败,请联系运营!'; $this->msg = '没有号码绑定关系,请忽略!。';
} }
} else { }else{
$this->code = 200; /*容联云*/
$this->msg = '没有号码绑定关系,请忽略!。'; $mappingId = $phone->getSubsId($phone_x,$phone_a,$phone_b,1,'mappingId');
} $Rong = new RongDemo();
} elseif ($is_privacy == 2) { if($mappingId) {
/*容联云*/ $result = $Rong->releaseNumber($mappingId);/*解绑*/
$mappingId = $phone->getSubsId($phone_x, $phone_a, $phone_b, 1, 'mappingId'); //var_dump($result);/*************测试****************/
$Rong = new RongDemo(); if ($result['statusCode'] == '000000') {
if ($mappingId) { $phone->unBind($phone_x, $phone_a, $phone_b);
}else{
$result = $Rong->releaseNumber($mappingId);/*解绑*/ $this->code = 101;
$this->msg = 'remove binding error';
if ($result['statusCode'] == '000000') { }
$phone->unBind($phone_x, $phone_a, $phone_b); }else{
} else {
$this->code = 101; $this->code = 101;
$this->msg = '解除绑定关系失败,请联系运营!'; $this->msg = 'dont\'t have about phone_x info';
} }
} else {
$this->code = 200;
$this->msg = '没有号码绑定关系,请忽略!。';
} }
} else { } else {
$this->code = 200; $this->code = 101;
$this->msg = '没有号码绑定关系,请忽略!。'; $this->msg = '解除关系参数错误,请联系运营人员!';
} }
$this->params['phone_x'];
return $this->response($this->code, $this->msg); return $this->response($this->code, $this->msg);
} }
...@@ -284,26 +268,24 @@ class CellPhone extends Basic ...@@ -284,26 +268,24 @@ class CellPhone extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function agentsPhone() public function agentsPhone() {
{
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
if (empty($this->params['agents_id'])) { if ($this->params['agents_id']) {
$this->msg = 'agents_id is null'; $agents_phone = new AAgentsPhone();
return $this->response(101, "agents_id is null"); if ($this->request->isGet()) {
} $where['agents_id'] = $this->params['agents_id'];
$where['status'] = 0;
$agents_phone = new AAgentsPhone(); $this->data = $agents_phone->getList(1,3,'id asc','id,phone',$where);
if ($this->request->isGet()) {
$where['agents_id'] = $this->params['agents_id'];
$where['status'] = 0;
$this->data = $agents_phone->getList(1, 3, 'id asc', 'id,phone', $where);
} else {
if ($this->params['type'] == 'delete') {
$this->data = $agents_phone->delPhone($this->params['agents_id'], $this->params['phone']);
} else { } else {
$this->data = $agents_phone->add($this->params['agents_id'], $this->params['phone']); if ($this->params['type'] == 'delete') {
$this->data = $agents_phone->delPhone($this->params['agents_id'],$this->params['phone']);
} else {
$this->data = $agents_phone->add($this->params['agents_id'],$this->params['phone']);
}
} }
} else {
$this->code = 101;
$this->msg = 'agents_id is null';
} }
return $this->response($this->code, $this->msg, $this->data); return $this->response($this->code, $this->msg, $this->data);
......
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