Commit 90996260 authored by hujun's avatar hujun

拨打电话service

parent ac468a92
......@@ -110,7 +110,7 @@ class CellPhone extends Basic
if ($result->Code == 'OK') {
//记录绑定
$bind->recordBindPhone($result->SecretBindDTO->SecretNo, $phone_a, $phone_b, $record, $time, $result, '', $is_privacy, $release);
$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 ];
......@@ -150,7 +150,7 @@ class CellPhone extends Basic
$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); //记录绑定
$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);
......
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/7/9
* Time: 16:28
*/
namespace app\api_broker\service;
use app\api_broker\untils\PlsDemo;
use app\api_broker\untils\RongDemo;
use app\extra\RedisExt;
use app\model\AliYunPhone;
use app\model\BindingPhone;
use app\model\SecretReport;
class CallPhoneService
{
private $phone_a = '';
private $phone_b = '';
private $expiry_date = '';
private $record = true;
private $release = 1;
private $subs_id = '';
private $request_id = '';
private $mapping_id = '';
private $is_privacy = 0; //0直接拨打号码1阿里云隐私号码2容联云隐私号码
/**
* 绑定AXB手机号
*
* @param $phone_a
* @param $phone_b
* @param bool $record
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function bindAXB($phone_a, $phone_b, $record = true)
{
$result['status'] = 'failed';
if (empty($phone_a) || empty($phone_b)) {
$result['msg'] = '参数错误,请联系运营人员!';
return $result;
}
if ((strlen($phone_a) != 11) || (strlen($phone_b) != 11)) {
$result['msg'] = '号码格式错误,请联系运营人员!';
return $result;
}
$call_phone = [];
$this->phone_a = $phone_a;//经纪人手机号
$this->phone_b = $phone_b;//客户手机号
$this->record = $record; //是否录音
$redis = RedisExt::getRedis();
$this->is_privacy = $redis->get('s_is_privacy');
//0不使用隐私号码 1阿里云 2容联云
if ($this->is_privacy == 0) {
$this->originalPhone();
$result['status'] = 'success';
$result['phone'] = $phone_b;
return $result;
}
$bind = new BindingPhone();
$where['a.status'] = 1;
$where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b;
$where['a.type'] = $this->is_privacy;
$phone_x = $bind->getPhoneX('b.phone_x', $where); //已经绑定的返回隐私号码
if (!empty($phone_x['phone_x'])) {
$result['status'] = 'success';
$result['data']['phone'] = $phone_x['phone_x'];
$result['msg'] = '已绑定,返回隐私号码。';
return $result; //绑定过了,返回隐号
}
$day_num = $redis->get('s_day_num');
$this->release = 1; //是否释放
if (empty($day_num)) {
$this->expiry_date = _EXPIRATION;
} else {
if (empty($this->params['landlord'])) {
$this->expiry_date = date('Y-m-d H:i:s', strtotime("+{$day_num} day"));
} else {
$day_num = $redis->get('s_landlord_phone_day');
if ($day_num == 0) {
$this->expiry_date = date('Y-m-d H:i:s', time() + 5);
$this->release = 0;
} else {
$this->expiry_date = date('Y-m-d H:i:s', strtotime("+{$day_num} day"));
}
}
}
if ($this->is_privacy == 1) {
/*阿里云*/
$call_phone = $this->aliYunBind();
if ($call_phone['status'] == 'success') {
$result['status'] = 'success';
$result['phone'] = $call_phone['phone'];
$result['msg'] = $call_phone['msg'];
} else {
$result['msg'] = $call_phone['msg'];
}
} elseif ($this->is_privacy == 2) {
$call_phone = $this->yunTongXun();
if ($call_phone['status'] == 'success') {
$result['status'] = 'success';
$result['phone'] = $call_phone['phone'];
$result['msg'] = $call_phone['msg'];
} else {
$result['msg'] = $call_phone['msg'];
}
}
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);
return $result;
}
/**
* @return mixed|\SimpleXMLElement
*/
public function aliYunBind()
{
$data['status'] = 'failed';
try {
$result = PlsDemo::bindAxb($this->phone_a, $this->phone_b, $this->expiry_date, $this->record);
if ($result->Code == 'OK') {
$data['status'] = 'success';
$data['msg'] = '绑定成功。';
$data['phone'] = $result->SecretBindDTO->SecretNo;
$this->subs_id = $result->SecretBindDTO->SubsId;
$this->request_id = $result->RequestId;
} elseif ($result->Code == 'isv.NO_AVAILABLE_NUMBER') {
$data['msg'] = '号码使用完,请联系运营人员。';
} else {
$data['msg'] = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!';
}
} catch (\Exception $e) {
$data['msg'] = '参数异常,无法呼叫,请联系运营人员!';
}
return $data;
}
/**
* 容联云
*
* @return mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function yunTongXun()
{
$yun_tong_xun = new RongDemo();
if ($this->record) {
$record = 'true';
} else {
$record = 'false';
}
$aliYunPhone = new AliYunPhone();
$phone_x = $aliYunPhone->getAliYunPhone($this->phone_a, $this->phone_b, $this->is_privacy); //获取未绑定隐号
$result = $yun_tong_xun->setNumber($this->phone_a, $this->phone_b, $phone_x['phone_x'], $phone_x['area'], $this->expiry_date, $record);
/*绑定成功*/
if ($result['statusCode'] == '000000') {
$data['status'] = 'success';
$data['msg'] = '绑定成功。';
$data['phone'] = $phone_x['phone_x'];
$this->mapping_id = $result['data']['mappingId'];
} else {
$phone_x_arr[] = $phone_x['phone_x']; //剔除绑定失败的中间号
//尝试5次再绑定
for ($i = 0; $i < 5; $i++) {
$phone_x = $aliYunPhone->getAliYunPhone($this->phone_a, $this->phone_b, $this->is_privacy, $phone_x_arr); //获取未绑定隐号
$result = $yun_tong_xun->setNumber($this->phone_a, $this->phone_b, $phone_x['phone_x'], $phone_x['area'], $this->expiry_date, $record);
if ($result['statusCode'] == '000000') {
$data['status'] = 'success';
$data['msg'] = '绑定成功。';
$data['phone'] = $phone_x['phone_x'];
$this->mapping_id = $result['data']['mappingId'];
break;
} else {
$phone_x_arr[] = $phone_x['phone_x']; //剔除绑定失败的中间号
}
}
//绑定失败返回错误信息
$data['status'] = 'failed';
$data['msg'] = '拨号失败,15秒再试,再无法拨号请联系请联系运营人员!';
}
return $data;
}
/**
* 直接拨打号码记录
*
* @return false|int
*/
private function originalPhone()
{
$m_report = new SecretReport();
$report_data['phone_no'] = $this->phone_a;
$report_data['secret_no'] = $this->phone_b;
$report_data['peer_no'] = $this->phone_b;
$report_data['call_type'] = 1;
$report_data['record_down'] = 3;
return $m_report->editData($report_data); //记录不使用隐号拨打记录
}
}
\ No newline at end of file
......@@ -150,16 +150,17 @@ class BindingPhone extends BaseModel
* @param $phone_b
* @param $record
* @param $time
* @param $result
* @param string $mappingId
* @param $subs_id
* @param $request_id
* @param string $mapping_id
* @param int $type
* @param int $status 绑定状态
* @param int $status
* @return int|string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function recordBindPhone($phone_x, $phone_a, $phone_b, $record, $time, $result, $mappingId = '', $type = 1, $status = 1)
public function recordBindPhone($phone_x, $phone_a, $phone_b, $record, $time, $subs_id, $request_id, $mapping_id = '', $type = 1, $status = 1)
{
$m_ali_phone = new AliYunPhone();
$phone_id = $m_ali_phone->field('id,bind_num')->where('phone_x', $phone_x)->find();
......@@ -168,9 +169,9 @@ class BindingPhone extends BaseModel
$insert_data['phone_a'] = $phone_a;
$insert_data['phone_b'] = $phone_b;
$insert_data['subsId'] = $result->SecretBindDTO->SubsId;
$insert_data['requestId'] = $result->RequestId;
$insert_data['mappingId'] = $mappingId;
$insert_data['subsId'] = $subs_id;
$insert_data['requestId'] = $request_id;
$insert_data['mappingId'] = $mapping_id;
$insert_data['record'] = $record;
$insert_data['aliYun_phone_id'] = $phone_id['id'];
$insert_data['expiry_date'] = $time;
......
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