Commit 04b54d2a authored by zfc's avatar zfc Committed by zw

容联云回调

parent 13999beb
...@@ -10,7 +10,7 @@ namespace app\api_broker\controller; ...@@ -10,7 +10,7 @@ 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\model\AAgentsPhone; use app\model\AAgentsPhone;
use app\model\AliYunPhone; use app\model\AliYunPhone;
use app\model\BindingPhone; use app\model\BindingPhone;
...@@ -43,20 +43,21 @@ class CellPhone extends Basic ...@@ -43,20 +43,21 @@ class CellPhone extends Basic
$record = empty($this->params['record']) ? true : false; //是否录音 $record = empty($this->params['record']) ? true : false; //是否录音
$setting = Cache::get('Setting'); //获取配置 $setting = Cache::get('Setting'); //获取配置
//var_dump($setting);/*************测试****************/
$aliYunPhone = new AliYunPhone(); $aliYunPhone = new AliYunPhone();
$bind = new BindingPhone(); $bind = new BindingPhone();
$field = 'phone_x'; $field = 'phone_x';
$where['a.status'] = 1; $where['a.status'] = 1;
$where['a.phone_a'] = $phone_a; $where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b; $where['a.phone_b'] = $phone_b;
$where['a.type'] = $setting['is_privacy'];
if ($setting['is_privacy'] == 1) { if ($setting['is_privacy'] != 0) {
$phone_x = $bind->getPhoneX($field, $where); $phone_x = $bind->getPhoneX($field, $where);
if ($phone_x) { if ($phone_x) {
$this->data = ['phone' => $phone_x['phone_x']]; $this->data = ['phone' => $phone_x['phone_x']];
} else { } else {
$phone_x = $aliYunPhone->getAliYunPhone($phone_a, $phone_b); $phone_x = $aliYunPhone->getAliYunPhone($phone_a, $phone_b,$setting['is_privacy']);
//是否还有未绑定的中间号码 //是否还有未绑定的中间号码
if ($phone_x) { if ($phone_x) {
...@@ -67,15 +68,35 @@ class CellPhone extends Basic ...@@ -67,15 +68,35 @@ class CellPhone extends Basic
$time = date('Y-m-d H:i:s',strtotime("+{$setting['day_num']} day")); $time = date('Y-m-d H:i:s',strtotime("+{$setting['day_num']} day"));
// $time = date('Y-m-d H:i:s',time()+300); // $time = date('Y-m-d H:i:s',time()+300);
} }
$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); //记录绑定 if($setting['is_privacy']==2) {
$this->msg = 'Binding success.'; /*容联云*/
$this->data = ['phone' => $phone_x['phone_x']]; $Rong = new RongDemo();
} else { $record2 = empty($this->params['record']) ? 'true' : 'false'; /* 是否录音(容联云规定string类型)*/
$this->code = 101; // var_dump($phone_x);/*************测试****************/
$this->msg = '绑定失败,请重试!'; $result = $Rong->setNumber($phone_a, $phone_b, $phone_x['phone_x'], $phone_x['area'],$record2);
/*绑定成功*/
// var_dump($result);/*************测试****************/
if($result['statusCode']=='000000'){
$aliYunPhone->editStatus($phone_x, $phone_a, $phone_b, $record, $time, 0,$result['data']['mappingId'],$setting['is_privacy']); //记录绑定
$this->msg = 'Binding Rong success';
$this->data = ['phone' => $phone_x['phone_x']];
}
}else {
/*阿里云*/
$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 = 'Binding success.';
$this->data = ['phone' => $phone_x['phone_x']];
} else {
$this->code = 101;
$this->msg = '绑定失败,请重试!';
}
} }
Log::write(json_encode($result),'AliYunBindAxb'); //记录日志 Log::write(json_encode($result),'AliYunBindAxb'); //记录日志
} else { } else {
$this->code = 102; $this->code = 102;
...@@ -147,12 +168,15 @@ class CellPhone extends Basic ...@@ -147,12 +168,15 @@ class CellPhone extends Basic
if ($phone_x && $phone_a && $phone_b) { if ($phone_x && $phone_a && $phone_b) {
$setting = Cache::get('Setting'); //获取配置 $setting = Cache::get('Setting'); //获取配置
if ($setting['is_privacy'] == 1) { $phone = new BindingPhone();
$phone = new BindingPhone();
$subsId = $phone->getSubsId($phone_x,$phone_a,$phone_b,1);
if ($setting['is_privacy'] == 1) {
/*阿里云*/
$subsId = $phone->getSubsId($phone_x,$phone_a,$phone_b,1,'subsId');
if ($subsId) { if ($subsId) {
$result = PlsDemo::unbindSubscription($subsId, $phone_x); $result = PlsDemo::unbindSubscription($subsId, $phone_x);/*解绑*/
if ($result->Message == 'OK') { if ($result->Message == 'OK') {
$phone->UnBind($phone_x, $phone_a, $phone_b); $phone->UnBind($phone_x, $phone_a, $phone_b);
} else { } else {
...@@ -163,7 +187,28 @@ class CellPhone extends Basic ...@@ -163,7 +187,28 @@ class CellPhone extends Basic
$this->code = 101; $this->code = 101;
$this->msg = 'dont\'t have about phone_x info'; $this->msg = 'dont\'t have about phone_x info';
} }
}else{
/*容联云*/
$mappingId = $phone->getSubsId($phone_x,$phone_a,$phone_b,1,'mappingId');
$Rong = new RongDemo();
if($mappingId) {
$result = $Rong->releaseNumber($mappingId);/*解绑*/
//var_dump($result);/*************测试****************/
if ($result['statusCode'] == '000000') {
$phone->UnBind($phone_x, $phone_a, $phone_b);
}else{
$this->code = 101;
$this->msg = 'remove binding error';
}
}else{
$this->code = 101;
$this->msg = 'dont\'t have about phone_x info';
}
} }
} else { } else {
$this->code = 101; $this->code = 101;
$this->msg = 'phone_x or phone_a or phone_b is null'; $this->msg = 'phone_x or phone_a or phone_b is null';
......
...@@ -5,6 +5,7 @@ namespace app\api_broker\controller; ...@@ -5,6 +5,7 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\untils\RongDemo; use app\api_broker\untils\RongDemo;
use app\model\BindingPhone; use app\model\BindingPhone;
use app\model\AliYunPhone;
class RongPhone extends Basic class RongPhone extends Basic
{ {
...@@ -23,6 +24,7 @@ class RongPhone extends Basic ...@@ -23,6 +24,7 @@ class RongPhone extends Basic
$params = $this->request->param(); $params = $this->request->param();
$data=array(); $data=array();
$Rong = new RongDemo(); $Rong = new RongDemo();
$aliYunPhone = new AliYunPhone();
$code= $Rong->statusCode; $code= $Rong->statusCode;
$phone_a = $params['phone_a']; $phone_a = $params['phone_a'];
$phone_b = $params['phone_b']; $phone_b = $params['phone_b'];
...@@ -31,14 +33,14 @@ class RongPhone extends Basic ...@@ -31,14 +33,14 @@ class RongPhone extends Basic
$where['a.type'] = 2; $where['a.type'] = 2;
$where['a.phone_a'] = $phone_a; $where['a.phone_a'] = $phone_a;
$where['a.phone_b'] = $phone_b; $where['a.phone_b'] = $phone_b;
$phone_x['phone_x'] = $bind->getPhoneX('phone_x,area', $where); $phone_x['phone_x'] = $aliYunPhone->getAliYunPhone($phone_a,$phone_b,$type=2);
var_dump($phone_x); var_dump($phone_x);
exit; exit;
if(!$phone_x){ if(!$phone_x){
} }
$data['data'] = json_decode($Rong->setNumber($phone_a,$phone_b,$phone_x['phone_x'],$phone_x['area']),true); $data['data'] = $Rong->setNumber($phone_a,$phone_b,$phone_x['phone_x'],$phone_x['area']);
$data['msg']=$code[$data['data']['statusCode']]; $data['msg']=$code[$data['data']['statusCode']];
/*绑定成功*/ /*绑定成功*/
if($data['data']['statusCode']=='000000'){ if($data['data']['statusCode']=='000000'){
......
...@@ -128,9 +128,10 @@ class RongDemo ...@@ -128,9 +128,10 @@ class RongDemo
* @param $bNumber * @param $bNumber
* @param $xNumber * @param $xNumber
* @param $areaCode * @param $areaCode
* @param $record
* @return string * @return string
*/ */
public function setNumber($aNumber,$bNumber,$xNumber,$areaCode){ public function setNumber($aNumber,$bNumber,$xNumber,$areaCode,$record){
$data = $this->components; $data = $this->components;
$time = date('YmdHis',time()); $time = date('YmdHis',time());
$sign = $this->sigParameter($time); /*签名*/ $sign = $this->sigParameter($time); /*签名*/
...@@ -143,14 +144,16 @@ class RongDemo ...@@ -143,14 +144,16 @@ class RongDemo
'bNumber' => $bNumber, 'bNumber' => $bNumber,
'servingNumber' => $xNumber, 'servingNumber' => $xNumber,
'areaCode' => $areaCode, 'areaCode' => $areaCode,
'cdrNotifyUrl' =>CURRENT_URL."/task/rongBilledInformUrl", 'needRecord' =>$record,
'callStateNotifyUrl'=>CURRENT_URL."/task/rongRecordingInformUrl", 'cdrNotifyUrl' =>CURRENT_URL."task/rongBilledInformUrl",
'recordNotifyUrl'=>CURRENT_URL."/task/rongStatusInformUrl", 'callStateNotifyUrl'=>CURRENT_URL."task/rongStatusInformUrl",
'recordNotifyUrl'=>CURRENT_URL."task/rongRecordingInformUrl",
// 'cdrNotifyUrl' =>"http://pre.tonglianjituan.com/task/rongBilledInfromUrl", // 'cdrNotifyUrl' =>"http://pre.tonglianjituan.com/task/rongBilledInfromUrl",
// 'callStateNotifyUrl'=>"http://pre.tonglianjituan.com/task/rongRecordingInfromUrl", // 'callStateNotifyUrl'=>"http://pre.tonglianjituan.com/task/rongRecordingInfromUrl",
// 'recordNotifyUrl'=>"http://pre.tonglianjituan.com/task/rongStatusInfromUrl", // 'recordNotifyUrl'=>"http://pre.tonglianjituan.com/task/rongStatusInfromUrl",
]; ];
$result = $this->sendCurl($url,$post_data,$Authorization); var_dump($post_data);/*************测试****************/
$result = json_decode($this->sendCurl($url,$post_data,$Authorization),true);
return $result; return $result;
...@@ -172,7 +175,7 @@ class RongDemo ...@@ -172,7 +175,7 @@ class RongDemo
'appId' => $data['appId'], 'appId' => $data['appId'],
'mappingId'=>$mappingId 'mappingId'=>$mappingId
]; ];
$result = $this->sendCurl($url,$post_data,$Authorization); $result = json_decode($this->sendCurl($url,$post_data,$Authorization),true);
return $result; return $result;
......
...@@ -20,12 +20,13 @@ class AliYunPhone extends BaseModel ...@@ -20,12 +20,13 @@ class AliYunPhone extends BaseModel
* *
* @param $phone_a * @param $phone_a
* @param $phone_b * @param $phone_b
* @param $type
* @return array|false|\PDOStatement|string|\think\Model * @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getAliYunPhone($phone_a,$phone_b) { public function getAliYunPhone($phone_a,$phone_b,$type=1) {
/* //查找phone_x 与 phone_a绑定的号码 /* //查找phone_x 与 phone_a绑定的号码
$where_a['b.status'] = 1; $where_a['b.status'] = 1;
$where_a['phone_a'] = $phone_a; $where_a['phone_a'] = $phone_a;
...@@ -47,7 +48,7 @@ class AliYunPhone extends BaseModel ...@@ -47,7 +48,7 @@ class AliYunPhone extends BaseModel
$where_a['bind_num'] = ['<=',200]; $where_a['bind_num'] = ['<=',200];
$id_arr = $this->field('a.id,phone_x')->alias('a') $id_arr = $this->field('a.id,phone_x')->alias('a')
->join('aliYun_binding_phone b','a.id = b.aliYun_phone_id','left') ->join('aliYun_binding_phone b','a.id = b.aliYun_phone_id','left')
->where($where_a)->where('phone_a='.$phone_a.' or phone_b='.$phone_b)->select(); ->where($where_a)->where("(b.phone_a=$phone_a or b.phone_b=$phone_b) and a.type=$type ")->select();
foreach ($id_arr as $k=>$v) { foreach ($id_arr as $k=>$v) {
$id[$k] = $v['id'];//去除phone_a已经绑定的号码 $id[$k] = $v['id'];//去除phone_a已经绑定的号码
...@@ -55,12 +56,13 @@ class AliYunPhone extends BaseModel ...@@ -55,12 +56,13 @@ class AliYunPhone extends BaseModel
$id = empty($id) ? 0 : implode(',',$id); $id = empty($id) ? 0 : implode(',',$id);
$where_phone['status'] = 0; $where_phone['status'] = 0;
$where_phone['type'] = $type;
if (empty($id)) { if (empty($id)) {
$result = Db::table('aliYun_phone')->field('id,phone_x')->where($where_phone)->find(); $result = Db::table('aliYun_phone')->field('id,phone_x,area')->where($where_phone)->find();
} else { } else {
$where_phone['id'] = ['NOT IN',$id]; $where_phone['id'] = ['NOT IN',$id];
$result = Db::table('aliYun_phone')->field('id,phone_x')->where($where_phone)->find(); $result = Db::table('aliYun_phone')->field('id,phone_x,area')->where($where_phone)->find();
} }
return $result; return $result;
...@@ -119,20 +121,24 @@ class AliYunPhone extends BaseModel ...@@ -119,20 +121,24 @@ class AliYunPhone extends BaseModel
* @param $phone_a * @param $phone_a
* @param $phone_b * @param $phone_b
* @param $record * @param $record
* @param $mappingId
* @param $time * @param $time
* @param $type
* @param $result * @param $result
* @throws \think\Exception * @throws \think\Exception
*/ */
public function editStatus($phone_x, $phone_a, $phone_b,$record,$time,$result) { public function editStatus($phone_x, $phone_a, $phone_b,$record,$time,$result,$mappingId='',$type=1) {
$this->where('phone_x', $phone_x['phone_x'])->setInc('bind_num'); $this->where('phone_x', $phone_x['phone_x'])->setInc('bind_num');
Db::table('aliYun_binding_phone')->insert([ Db::table('aliYun_binding_phone')->insert([
'phone_a' => $phone_a, 'phone_a' => $phone_a,
'phone_b' => $phone_b, 'phone_b' => $phone_b,
'subsId' => $result->SecretBindDTO->SubsId, 'subsId' => $result->SecretBindDTO->SubsId,
'requestId' => $result->RequestId, 'requestId' => $result->RequestId,
'mappingId' => $mappingId,
'record' => $record, 'record' => $record,
'aliYun_phone_id' => $phone_x['id'], 'aliYun_phone_id' => $phone_x['id'],
'expiry_date' => $time, 'expiry_date' => $time,
'type' =>$type,
]); ]);
return ; return ;
} }
......
...@@ -19,10 +19,11 @@ class BindingPhone extends BaseModel ...@@ -19,10 +19,11 @@ class BindingPhone extends BaseModel
* @param $phone_x * @param $phone_x
* @param $phone_a * @param $phone_a
* @param $phone_b * @param $phone_b
* @param $phoneId
* @param int $status * @param int $status
* @return bool|mixed * @return bool|mixed
*/ */
public function getSubsId($phone_x, $phone_a, $phone_b = '', $status = 0) { public function getSubsId($phone_x, $phone_a, $phone_b = '', $status = 0,$phoneId='subsId') {
if ($phone_x && ($phone_a || $phone_b)) { if ($phone_x && ($phone_a || $phone_b)) {
$where['a.status'] = $status; $where['a.status'] = $status;
...@@ -35,7 +36,7 @@ class BindingPhone extends BaseModel ...@@ -35,7 +36,7 @@ class BindingPhone extends BaseModel
} }
$subsId = $this->alias('a') $subsId = $this->alias('a')
->join('aliYun_phone b','a.aliYun_phone_id=b.id','left') ->join('aliYun_phone b','a.aliYun_phone_id=b.id','left')
->where($where)->value('subsId'); ->where($where)->value($phoneId);
} else { } else {
$subsId = false; $subsId = false;
...@@ -93,7 +94,7 @@ class BindingPhone extends BaseModel ...@@ -93,7 +94,7 @@ class BindingPhone extends BaseModel
public function getPhoneX($field, $where) { public function getPhoneX($field, $where) {
return $this->alias('a') return $this->alias('a')
->field($field) ->field($field)
->join('aliYun_phone b','a.aliYun_phone_i=b.id','left') ->join('aliYun_phone b','a.aliYun_phone_id=b.id','left')
->where($where) ->where($where)
->find(); ->find();
} }
......
<?php
/**
* Created by PhpStorm.
* User: zfc
* Date: 2018/3/16
* Time: 14:55
*/
namespace app\model;
class RongBilledInform extends BaseModel
{
/**
* @param $where
* @param $v
* @return mixed
*/
public function getValue($where,$v)
{
$r = $this->where($where)->value($v);
return $r;
}
}
\ No newline at end of file
...@@ -11,6 +11,7 @@ namespace app\task\controller; ...@@ -11,6 +11,7 @@ namespace app\task\controller;
use app\api_broker\untils\PlsDemo; use app\api_broker\untils\PlsDemo;
use app\model\BindingPhone; use app\model\BindingPhone;
use app\model\SecretReport; use app\model\SecretReport;
use app\model\RongBilledInform;
use think\Db; use think\Db;
use think\Log; use think\Log;
use think\Request; use think\Request;
...@@ -115,25 +116,48 @@ class PrivacyNumber ...@@ -115,25 +116,48 @@ class PrivacyNumber
return ; return ;
} }
/*******************************↓↓↓↓↓↓容联云↓↓↓↓↓***********************************************/
//话单通知 /**话单通知
* @return string
*/
public function rongBilledInformUrl(){ public function rongBilledInformUrl(){
$params = Request::instance()->param(); $params = Request::instance()->param();
$str=date('Y-m-d h:i:s').' '.var_export($params,true); /*搜索A经纪人agent_id and B客户 user_id */
Log::write(json_encode($str),'rongBilledInformUrl'); //记录日志 $phone_a=$params['callerNum'];
if ($phone_a) {
$agents_id = Db::table('agents')->where("phone='{$phone_a}' AND password IS NOT NULL")->value('id');
if (empty($agents_id)) {
$agents_id = Db::table('a_agents_phone')->where('phone',$phone_a)->value('agents_id');
}
$params['agents_id'] = $agents_id;
$params['users_id'] = Db::table('u_users')->where('user_phone',$phone_a)->value('id');
}
$report = new RongBilledInform();
$report->allowField(true)->save($params);
$str=date('Y-m-d h:i:s').' 容联云话单'.var_export($params,true);
Log::write($str,'rongBilledInformUrl'); //记录日志
return json_encode(["statusCode"=>'000000','msg'=>'接收成功']);
} }
//录音通知 //录音通知
public function rongRecordingInformUrl(){ public function rongRecordingInformUrl(){
$params = Request::instance()->param(); $params = Request::instance()->param();
$str=date('Y-m-d h:i:s').' '.var_export($params,true); $report = new RongBilledInform();
Log::write(json_encode($str),'rongRecordingInformUrl'); //记录日志 $where['callId']=$params['callId'];
$update['mp3_url']=$params['recordUrl'];
$report->save($update,$where);
$str=date('Y-m-d h:i:s').' 容联云录音'.var_export($params,true);
Log::write($str,'rongRecordingInformUrl'); //记录日志
return json_encode(["statusCode"=>'000000','msg'=>'接收成功']);
} }
//状态通知 //状态通知
public function rongStatusInformUrl(){ public function rongStatusInformUrl(){
$params = Request::instance()->param(); $params = Request::instance()->param();
$str=date('Y-m-d h:i:s').' '.var_export($params,true); $str=date('Y-m-d h:i:s').' 容联云状态通知'.var_export($params,true);
Log::write(json_encode($str),'rongStatusInformUrl'); //记录日志 Log::write(json_encode($str),'rongStatusInformUrl'); //记录日志
} }
......
...@@ -10,12 +10,18 @@ ...@@ -10,12 +10,18 @@
</div> </div>
<div class="radio" style="display: inline-block"> <div class="radio" style="display: inline-block">
<label> <label>
<input type="radio" name="optionsRadios" id="optionsRadios2" value="1" [% if(it.is_privacy == 1) { %] checked [% } %]>开启 <input type="radio" name="optionsRadios" id="optionsRadios2" value="1" [% if(it.is_privacy == 1) { %] checked [% } %]>阿里云
</label>
</div>
<div class="radio" style="display: inline-block">
<label>
<input type="radio" name="optionsRadios" id="optionsRadios3" value="2" [% if(it.is_privacy == 2) { %] checked [% } %]>容联云
</label> </label>
</div> </div>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label" style="text-align: right">隐号绑定有效期(天数):</label> <label class="col-sm-3 control-label" style="text-align: right">隐号绑定有效期(天数):</label>
<div class="col-sm-9"> <div class="col-sm-9">
......
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