Commit 74f9b2eb authored by hujun's avatar hujun

b端拨打号码调用

parent 309101d1
...@@ -9,14 +9,10 @@ ...@@ -9,14 +9,10 @@
namespace app\api_broker\controller; namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\service\CallPhoneService;
use app\api_broker\untils\PlsDemo; use app\api_broker\untils\PlsDemo;
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\BindingPhone; use app\model\BindingPhone;
use app\model\SecretReport;
use think\Log;
class CellPhone extends Basic class CellPhone extends Basic
{ {
...@@ -29,145 +25,22 @@ class CellPhone extends Basic ...@@ -29,145 +25,22 @@ class CellPhone extends Basic
* 解绑之后有延迟(15s) * 解绑之后有延迟(15s)
* *
* @return \think\Response * @return \think\Response
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function bindAXB() public function bindAXB()
{ {
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
if (empty($this->params['phone_a']) || empty($this->params['phone_b'])) { $call = new CallPhoneService();
$this->code = 101; $result = $call->bindAXB($this->params['phone_a'], $this->params['phone_b']);
$this->msg = 'phone_a or phone_b is null';
return $this->response(101, '参数错误,请联系运营人员!');
}
$phone_a = $this->params['phone_a'];//经纪人手机号
$phone_b = $this->params['phone_b'];//客户手机号
$record = true; //是否录音
$redis = RedisExt::getRedis();
$is_privacy = $redis->get('s_is_privacy');
//0不使用隐私号码 1阿里云 2容联云
if ($is_privacy == 0) {
$this->data = [ 'phone' => $phone_b ];
$m_report = new SecretReport();
$report_data['phone_no'] = $phone_a;
$report_data['secret_no'] = $phone_b;
$report_data['peer_no'] = $phone_b;
$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'])) {
$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 ($result['status'] == 'success') {
$release = 1; //是否释放 $this->msg = $result['msg'];
if (empty($day_num)) { $this->data['phone'] = $result['phone'];
$time = _EXPIRATION;
} else { } else {
if (empty($this->params['landlord'])) { $this->msg = $result['msg'];
$time = date('Y-m-d H:i:s', strtotime("+{$day_num} day")); $this->code = 101;
} else {
$day_num = $redis->get('s_landlord_phone_day');
if ($day_num == 0) {
$time = date('Y-m-d H:i:s', time() + 5);
$release = 0;
} else {
$time = date('Y-m-d H:i:s', strtotime("+{$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') {
//记录绑定
$bind->recordBindPhone($result->SecretBindDTO->SecretNo, $phone_a, $phone_b, $record, $time, $result->SecretBindDTO->SubsId, $result->RequestId, '', $is_privacy, $release);
$this->msg = '绑定成功。';
$this->data = [ 'phone' => $result->SecretBindDTO->SecretNo ];
} elseif ($result->Code == 'isv.NO_AVAILABLE_NUMBER') {
$this->code = 101;
$this->msg = '号码使用完,请联系运营人员。';
$this->data = [];
} 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') {
$bind->recordBindPhone($phone_x['phone_x'], $phone_a, $phone_b, $record, $time, 0, $result['data']['mappingId'], $is_privacy, $release); //记录绑定
$this->msg = '绑定成功';
$this->data = [ 'phone' => $phone_x['phone_x'] ];
} else {
$phone_x_arr[] = $phone_x['phone_x']; //剔除绑定失败的中间号
//尝试5次再绑定
for ($i = 0; $i < 5; $i++) {
$phone_x = $aliYunPhone->getAliYunPhone($phone_a, $phone_b, $is_privacy, $phone_x_arr); //获取未绑定隐号
$result = $Rong->setNumber($phone_a, $phone_b, $phone_x['phone_x'], $phone_x['area'], $time, $record2);
if ($result['statusCode'] == '000000') {
$bind->recordBindPhone($phone_x['phone_x'], $phone_a, $phone_b, $record, $time, '', '', $result['data']['mappingId'], $is_privacy, $release); //记录绑定
$this->msg = '绑定成功';
$this->data = [ 'phone' => $phone_x['phone_x'] ];
return $this->response($this->code, $this->msg, $this->data);
} else {
$phone_x_arr[] = $phone_x['phone_x']; //剔除绑定失败的中间号
}
}
//绑定失败返回错误信息
$this->code = 101;
$this->msg = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!';
}
} }
Log::write(json_encode($result), 'AliYunBindAxb'); //记录日志
return $this->response($this->code, $this->msg, $this->data); return $this->response($this->code, $this->msg, $this->data);
} }
...@@ -214,58 +87,16 @@ class CellPhone extends Basic ...@@ -214,58 +87,16 @@ class CellPhone extends Basic
public function agentsUnBind() public function agentsUnBind()
{ {
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$phone_x = $this->params['phone_x'];
$phone_a = $this->params['phone_a'];
$phone_b = $this->params['phone_b'];
if (empty($phone_x) || empty($phone_a) || empty($phone_b)) { $call = new CallPhoneService();
$this->code = 101; $result = $call->agentsUnBind($this->params['phone_a'], $this->params['phone_b']);
$this->msg = '解除关系参数错误,请联系运营人员!';
return $this->response($this->code, $this->msg);
}
$phone = new BindingPhone();
$redis = RedisExt::getRedis();
$is_privacy = $redis->get('s_is_privacy');
$is_privacy = $is_privacy != '0' ? $is_privacy : 0;
if ($is_privacy == 1) {
/*阿里云*/
$subsId = $phone->getSubsId($phone_x, $phone_a, $phone_b, 1, 'subsId');
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x);/*解绑*/
if ($result->Message == 'OK') {
$phone->unBind($phone_x, $phone_a, $phone_b);
} else {
$this->code = 101;
$this->msg = '解除绑定关系失败,请联系运营!';
}
} else {
$this->code = 200;
$this->msg = '没有号码绑定关系,请忽略!。';
}
} elseif ($is_privacy == 2) {
/*容联云*/
$mappingId = $phone->getSubsId($phone_x, $phone_a, $phone_b, 1, 'mappingId');
$Rong = new RongDemo();
if ($mappingId) {
$result = $Rong->releaseNumber($mappingId);/*解绑*/
if ($result['statusCode'] == '000000') {
$phone->unBind($phone_x, $phone_a, $phone_b);
} else {
$this->code = 101;
$this->msg = '解除绑定关系失败,请联系运营!';
}
} else {
$this->code = 200;
$this->msg = '没有号码绑定关系,请忽略!。';
}
if ($result['status'] == 'success') {
$this->msg = $result['msg'];
$this->data['phone'] = $result['phone'];
} else { } else {
$this->code = 200; $this->msg = $result['msg'];
$this->msg = '没有号码绑定关系,请忽略!。'; $this->code = 101;
} }
return $this->response($this->code, $this->msg); return $this->response($this->code, $this->msg);
......
...@@ -15,6 +15,7 @@ use app\extra\RedisExt; ...@@ -15,6 +15,7 @@ use app\extra\RedisExt;
use app\model\AliYunPhone; use app\model\AliYunPhone;
use app\model\BindingPhone; use app\model\BindingPhone;
use app\model\SecretReport; use app\model\SecretReport;
use think\Log;
class CallPhoneService class CallPhoneService
{ {
...@@ -31,6 +32,8 @@ class CallPhoneService ...@@ -31,6 +32,8 @@ class CallPhoneService
/** /**
* 绑定AXB手机号 * 绑定AXB手机号
* 绑定手机号
* 解绑之后有延迟(15s)
* *
* @param $phone_a * @param $phone_a
* @param $phone_b * @param $phone_b
...@@ -46,7 +49,7 @@ class CallPhoneService ...@@ -46,7 +49,7 @@ class CallPhoneService
} }
if ((strlen($phone_a) != 11) || (strlen($phone_b) != 11)) { if ((strlen($phone_a) != 11) || (strlen($phone_b) != 11)) {
$result['msg'] = '号码格式错误,请联系运营人员!'; $result['msg'] = '号码格式错误,请重新填写!';
return $result; return $result;
} }
...@@ -77,7 +80,7 @@ class CallPhoneService ...@@ -77,7 +80,7 @@ class CallPhoneService
if (!empty($phone_x['phone_x'])) { if (!empty($phone_x['phone_x'])) {
$result['status'] = 'success'; $result['status'] = 'success';
$result['data']['phone'] = $phone_x['phone_x']; $result['phone'] = $phone_x['phone_x'];
$result['msg'] = '已绑定,返回隐私号码。'; $result['msg'] = '已绑定,返回隐私号码。';
return $result; //绑定过了,返回隐号 return $result; //绑定过了,返回隐号
} }
...@@ -109,6 +112,8 @@ class CallPhoneService ...@@ -109,6 +112,8 @@ class CallPhoneService
$result['status'] = 'success'; $result['status'] = 'success';
$result['phone'] = $call_phone['phone']; $result['phone'] = $call_phone['phone'];
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
$type = 'AliYunBindAxb';
} else { } else {
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
} }
...@@ -119,6 +124,8 @@ class CallPhoneService ...@@ -119,6 +124,8 @@ class CallPhoneService
$result['status'] = 'success'; $result['status'] = 'success';
$result['phone'] = $call_phone['phone']; $result['phone'] = $call_phone['phone'];
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
$type = 'YunTongXunBindAxb';
} else { } else {
$result['msg'] = $call_phone['msg']; $result['msg'] = $call_phone['msg'];
} }
...@@ -127,6 +134,7 @@ class CallPhoneService ...@@ -127,6 +134,7 @@ class CallPhoneService
if ($result['status'] == 'success') if ($result['status'] == 'success')
$bind->recordBindPhone($call_phone['phone'], $phone_a, $phone_b, $record, $this->expiry_date, $this->subs_id, $this->request_id, $this->mapping_id, $this->is_privacy, $this->release); $bind->recordBindPhone($call_phone['phone'], $phone_a, $phone_b, $record, $this->expiry_date, $this->subs_id, $this->request_id, $this->mapping_id, $this->is_privacy, $this->release);
Log::write(json_encode($result), $type); //记录日志
} catch (\Exception $e) { } catch (\Exception $e) {
$data['status'] = 'failed'; $data['status'] = 'failed';
$data['msg'] = $e->getMessage(); $data['msg'] = $e->getMessage();
......
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