Commit 8439c732 authored by hujun's avatar hujun

解除绑定关系

parent 0c7fcc15
......@@ -4,10 +4,10 @@ error_reporting(E_ERROR | E_PARSE);
define('_MESSAGE_TYPE','SecretReport');
define('_QUEUE_NAME','Alicom-Queue-1186048444498461-SecretReport');
define('_EXPIRATION',date('Y-m-d H:i:s',time()+518400));//手机号码保留七天
define('_POOLKEY','FC100000022056027');
define('_TLSYPoolKey','FC100000022056027');
return [
'jwt_key' => 'tonglian+123',
// 应用模式状态
'app_status' => 'dev-config',
'_DefaultPoolKey' => 'FC100000022056027',
'tonglianshangyePoolKey' =>'FC100000027622039'
];
\ No newline at end of file
......@@ -11,8 +11,8 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\api_broker\untils\PlsDemo;
use app\model\AliyunPhone;
use think\Config;
use app\model\AliYunPhone;
use app\model\BindingPhone;
use think\Db;
class CellPhone extends Basic
......@@ -25,7 +25,9 @@ class CellPhone extends Basic
* 绑定手机号
*
* @return \think\Response
* @throws \Aliyun\Core\Exception\ClientException
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function bindAXB() {
$params = $this->request->param();
......@@ -35,22 +37,29 @@ class CellPhone extends Basic
$phone_b = $this->params['phone_b'];//客户手机号
$record = empty($this->params['record'])? false:true; //是否录音
$bind = new AliyunPhone();
$bind = new AliYunPhone();
$phone_x = $bind->getAliYunPhone($phone_b);
$result = PlsDemo::bindAxb($phone_a, $phone_b, $expiration, $record, Config::get('_DefaultPoolKey'), $phone_x);
if ($result->Message == 'OK') {
Db::table('aliyun_binding_phone')->save([
'phone_a' => $phone_a,
'phone_b' => $phone_b,
'SubsId' => $result->SecretBindDTO->SubsId,
'RequestId' => $result->RequestId,
'record' => $record
]);
$this->msg = 'Binding success';
//是否还有未绑定的中间号码
if ($phone_x) {
$result = PlsDemo::bindAxb($phone_a, $phone_b, $expiration, $record, $phone_x['phone_x']);
if ($result->Message == 'OK') {
$bind->where('phone_x',$phone_x['phone_x'])->setField('status',1);
Db::table('aliYun_binding_phone')->insert([
'phone_a' => $phone_a,
'phone_b' => $phone_b,
'subsId' => $result->SecretBindDTO->SubsId,
'requestId' => $result->RequestId,
'record' => $record,
'aliYun_phone_id' => $phone_x['id']
]);
$this->msg = 'Binding success.';
} else {
$this->code = 101;
$this->msg = 'Binding failure.';
}
} else {
$this->code = 101;
$this->msg = 'Binding failure';
$this->code = 102;
$this->msg = 'Number pool run out.';
}
} else {
$this->code = 101;
......@@ -67,8 +76,36 @@ class CellPhone extends Basic
return $this->response($this->code, $this->msg,$this->data);*/
}
/**
* 解除绑定关系
*
* @return \think\Response
* @throws \think\exception\DbException
*/
public function agentsUnBind() {
PlsDemo::unbindSubscription();
}
$phone_x = $this->params['phone_x'];
$phone_a = $this->params['phone_a'];
if ($phone_x) {
$phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,1);
if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x);
if ($result->Message == 'OK') {
$phone->UnBind($phone_x);
} else {
$this->code = 101;
$this->msg = 'remove binding error';
}
} else {
$this->code = 101;
$this->msg = 'dont\'t have about phone_x info';
}
} else {
$this->code = 101;
$this->msg = 'phone_x is null';
}
$this->params['phone_x'];
return $this->response($this->code, $this->msg);
}
}
\ No newline at end of file
......@@ -29,7 +29,7 @@ class PlsDemo
{
static $acsClient = null;
static $pool_key = _POOLKEY;
/**
* 取得AcsClient
*
......@@ -80,13 +80,13 @@ class PlsDemo
* @param string $phoneNoX 中间号码
* @return mixed|\SimpleXMLElement
*/
public static function bindAxb($phoneA, $phoneB, $time, $isRecordingEnabled=false, $poolKey='FC100000022056027', $phoneNoX = '17091955105') {
public static function bindAxb($phoneA, $phoneB, $time, $isRecordingEnabled=false, $phoneNoX = '17091955105') {
//组装请求对象-具体描述见控制台-文档部分内容
$request = new BindAxbRequest();
//必填:号池Key
$request->setPoolKey($poolKey);
$request->setPoolKey(self::$pool_key);
//必填:AXB关系中的A号码
$request->setPhoneNoA($phoneA);
......@@ -162,8 +162,9 @@ class PlsDemo
/**
* 解绑接口
*
* @return stdClass
* @throws ClientException
* @param $subsId
* @param $secretNo
* @return mixed|\SimpleXMLElement
*/
public static function unbindSubscription($subsId, $secretNo) {
......@@ -171,7 +172,7 @@ class PlsDemo
$request = new UnbindSubscriptionRequest();
//必填:号池Key
$request->setPoolKey("FC123456");
$request->setPoolKey(self::$pool_key);
//必填:对应的产品类型
$request->setProductType("AXB_170");
......
<?php
/**
* Created by PhpStorm.
* User: fuju
* User: hu jun
* Date: 2018/1/20
* Time: 17:52
*/
......@@ -10,8 +10,11 @@ namespace app\model;
use think\Db;
class AliyunPhone extends BaseModel
class AliYunPhone extends BaseModel
{
// 设置当前模型对应的完整数据表名称
protected $table = 'aliYun_phone';
/**
* 获取未绑定的手机号码
*
......@@ -22,19 +25,22 @@ class AliyunPhone extends BaseModel
* @throws \think\exception\DbException
*/
public function getAliYunPhone($phone = '') {
$where['status'] = 1;
$where['status'] = 0;
if ($phone) {
//查询之前一次绑定关系的号码
$phone_x = Db::table('aliyun_binding_phone')->field('phone_x')->alias('a')
->join('aliyun_phone b','a.aliyun_phone_id = b.id','left')
$phone_x = Db::table('aliYun_binding_phone')->field('phone_x')->alias('a')
->join('aliYun_phone b','a.aliYun_phone_id = b.id','left')
->where([
'phone_b' => $phone,
'a.status' => 1
])->value('phone_x');
$where['phone_x'] = $phone_x;
if ($phone_x) {
$where['phone_x'] = $phone_x;
}
}
$result = Db::table('aliyun_phone')->field('phone_x')->whereOr($where)->find();
$result = Db::table('aliYun_phone')->field('id,phone_x')->whereOr($where)->find();
return $result;
}
}
\ No newline at end of file
......@@ -12,4 +12,52 @@ class BindingPhone extends BaseModel
{
// 设置当前模型对应的完整数据表名称
protected $table = 'aliyun_binding_phone';
/**
* 通过阿里号码获取subsId
*
* @param $phone_x
* @param $phone_a
* @param int $status
* @return bool|mixed
*/
public function getSubsId($phone_x, $phone_a, $status = 0) {
if ($phone_x && $phone_a) {
$subsId = $this->alias('a')
->join('aliYun_phone b','a.aliYun_phone_id=b.id','left')
->where([
'a.status'=>$status,
'phone_x'=>$phone_x,
'phone_a'=>$phone_a
])->value('subsId');
} else {
$subsId = false;
}
return $subsId;
}
/**
* @param $phone_x
* @return bool|int
* @throws \think\exception\DbException
*/
public function UnBind($phone_x) {
if ($phone_x) {
$phone = new AliYunPhone();
$phone_data = $phone->get(['phone_x'=>$phone_x]);
if ($phone_data->id) {
$phone_data->status = 0;
$phone_data->save();
$result = $this->where([
'aliYun_phone_id'=>$phone_data->id,
'status' => 1
])->setField('status',0);
} else {
$result = false;
}
} else {
$result = false;
}
return $result;
}
}
\ No newline at end of file
......@@ -228,7 +228,8 @@ Route::group('broker', [
'add_phone_follow_up' => ['api_broker/broker/add_phone_follow_up',['method'=>'get|post']],//新增-客户电话跟进
'user_search' => ['api_broker/broker/user_search',['method'=>'get|post']],//客户搜索
'agentUserTb' => [ 'api_broker/Client/agentUserTb', [ 'method' => 'get' ] ],//客户列表
'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//客户列表
'bindAXB' => [ 'api_broker/CellPhone/bindAXB', [ 'method' => 'post' ] ],//隐私号码
'agentsUnBind' => [ 'api_broker/CellPhone/agentsUnBind', [ 'method' => 'post' ] ],//解除绑定关系
]);
......
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