diff --git a/admin/config/xcall.php b/admin/config/xcall.php index d61fa5fc..436d08b3 100644 --- a/admin/config/xcall.php +++ b/admin/config/xcall.php @@ -7,6 +7,10 @@ * Time: 10:32 */ +$config['app_id'] = 1206; +$config['app_key'] = 'WX6HDVZX3AYSZDR1739332ZM'; + $config['mobile_list'] = array( - '18916735350','18916689195', + '13391247942','13391407003','13391416119','13391416302', + '13391416570', ); diff --git a/admin/controllers/Common.php b/admin/controllers/Common.php index 7102fbfa..ef01653d 100644 --- a/admin/controllers/Common.php +++ b/admin/controllers/Common.php @@ -1145,7 +1145,13 @@ class Common extends CI_Controller $this->load->helper('order'); $seq_id = create_order_no(); require_once COMMPATH . 'third_party/Xcall/Xcall.php'; - $xcall = new Xcall(); + + $this->config->load('xcall'); + $init_config = [ + 'app_id' => $this->config->item('app_id'), + 'app_key' => $this->config->item('app_key'), + ]; + $xcall = new Xcall($init_config); $result = $xcall->SWbind($mobile, $seq_id, $middleNumber); if ($result['t_code'] == '-26') {//已经绑定解绑 $s_res = $xcall->Searchbind($middleNumber); diff --git a/api/config/xcall.php b/api/config/xcall.php index e8beb018..9089fb51 100644 --- a/api/config/xcall.php +++ b/api/config/xcall.php @@ -7,6 +7,15 @@ * Time: 11:32 */ +$config['app_id'] = 1216; +$config['app_key'] = 'V44SK7UJMUN1SH9FETN8QRT2'; + $config['mobile_list'] = array( - '18916751561','18916739316' + '15317082243','15317096491','15317099349','15317100493', + '15317101451','15317101741','15317103479','15317106421', + '15317106841','15317107415','15317108649','15317110549', + '15317110641','15317110742','15317111407','15317113469', + '15317115406','15317302492','15317304631','15317313410', + '18016257495','18017240317','18017414423','18017420332', + '18017439042', ); diff --git a/api/controllers/plan/Xzcall.php b/api/controllers/plan/Xzcall.php index e141e3b4..63525446 100644 --- a/api/controllers/plan/Xzcall.php +++ b/api/controllers/plan/Xzcall.php @@ -7,10 +7,15 @@ * Date: 2021/4/14 * Time: 19:15 */ +require_once COMMPATH . 'third_party/Xcall/Xcall.php'; class Xzcall extends HD_Controller { private $log_file; + private $admin_config = [ + 'app_id' => 1206, + 'app_key' => 'WX6HDVZX3AYSZDR1739332ZM' + ]; public function __construct() { @@ -64,29 +69,30 @@ class Xzcall extends HD_Controller $addData['customer_id'] = $row['cf_id']; } $this->mdOplogs->add($addData); - require_once COMMPATH . 'third_party/Xcall/Xcall.php'; - $xcall = new Xcall(); + $xcall = new Xcall($this->admin_config); //解绑 $xcall->SWunbind($data['to'], $data['virtualMobile']); } elseif ($row['cf_id'] && $row['cf_platform'] == 'api') { //狸车宝 - require_once COMMPATH . 'third_party/Xcall/Xcall.php'; - $xcall = new Xcall(); + $this->config->load('xcall'); + $params = [ + 'app_id' => $this->config->item('app_id'), + 'app_key' => $this->config->item('app_key'), + ]; + $xcall = new Xcall($params); //解绑 - $result = $xcall->SWunbind($data['to'], $data['virtualMobile']); + $result = $xcall -> AXBUnbind($data['to'],$data['from'],$data['virtualMobile']); + //删除redis + $cache_key = "XZ_LICHEB_MOBILEA_{$data['from']}_MOBILEB_{$data['to']}_{$row['cf_uid']}"; + $redis = &load_cache('redis'); + $redis->delete($cache_key); if ($row['cf_title'] == 'order') { //订单 $order = $this->orders_model->get(['id' => $row['cf_id']]); $cust = $this->customers_model->get(['id' => $order['rid']]); - //$this->load->library('receiver/orders_entity'); - //$this->orders_entity->add_log($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2); } else { //客户 $cust = $this->customers_model->get(['id' => $row['cf_id']]); } $this->load->library('receiver/customers_entity'); $this->customers_entity->add_log($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2); - //删除redis - $cache_key = "XZ_LICHEB_MOBILEB_{$cust['mobile']}_{$row['cf_uid']}"; - $redis = &load_cache('redis'); - $redis->delete($cache_key); } } else { debug_log("error: 未找到拨打记录", $this->log_file); @@ -106,8 +112,16 @@ class Xzcall extends HD_Controller if ($row) { $jsondata = json_decode($row['json_data'], true); if ($data['getFileUrl']) { - require_once COMMPATH . 'third_party/Xcall/Xcall.php'; - $xcall = new Xcall(); + if($data['id']==1206){ + $params = $this->admin_config; + }else{ + $this->config->load('xcall'); + $params = [ + 'app_id' => $this->config->item('app_id'), + 'app_key' => $this->config->item('app_key'), + ]; + } + $xcall = new Xcall($params); $result = $xcall->getFile($data['getFileUrl'], $data['mid'], $data['tag']); if ($result['code']) { //上传七牛 $this->load->library('qiniu'); diff --git a/api/controllers/wxapp/licheb/User.php b/api/controllers/wxapp/licheb/User.php index 3194da2c..f9ade980 100644 --- a/api/controllers/wxapp/licheb/User.php +++ b/api/controllers/wxapp/licheb/User.php @@ -89,10 +89,19 @@ class User extends Wxapp{ $group_arr = $this->app_user_model->get_group(); $group_name = $group_arr[$user['group_id']] ? $group_arr[$user['group_id']] : ''; + + //获取拨打电话 + $json = $this->session['jsondata'] ? json_decode($this->session['jsondata'], true) : array(); + $tel = $this->session['mobile']; + if ($json && $json['licheb'] && $json['licheb']['tel']) { + $tel = $json['licheb']['tel']; + } + $data = array( 'uid' => $uid, 'uname' => $user['uname'], 'mobile' => $user['mobile'], + 'tel' => $tel, 'group_id' => $user['group_id'], 'group_name' => $group_name, 'biz_name' => $biz['biz_name'] ? $biz['biz_name'] : '' @@ -144,4 +153,31 @@ class User extends Wxapp{ return $data; } + /** + * 更新联系手机号 + * @return array + * @throws Hd_Exception + */ + protected function put_tel() + { + $tel = $this->input_param('tel'); + if (!mobile_valid($tel)) { + throw new Hd_Exception('确认一下手机号是否正确', API_CODE_INVILD_PARAM); + } + + $uid = $this->session['uid']; + + $user = $this->app_user_model->get(array('id' => $uid)); + $json = $user['jsondata'] ? json_decode($user['jsondata'], true) : array(); + $json['licheb']['tel'] = $tel; + $upd = array('jsondata' => json_encode($json, JSON_UNESCAPED_UNICODE)); + $ret = $this->app_user_model->update($upd, array('id' => $uid)); + if (!$ret) { + throw new Hd_Exception('更新失败', API_CODE_FAIL); + } + + $data = array('tel' => $tel); + + return $data; + } } diff --git a/api/controllers/wxapp/licheb/Xz.php b/api/controllers/wxapp/licheb/Xz.php index ded3c83f..932c9800 100644 --- a/api/controllers/wxapp/licheb/Xz.php +++ b/api/controllers/wxapp/licheb/Xz.php @@ -9,6 +9,7 @@ defined('WXAPP_APP') OR exit('No direct script access allowed'); * Time: 10:17 */ require_once APPPATH.'controllers/wxapp/Wxapp.php'; +require_once COMMPATH.'third_party/Xcall/Xcall.php'; class Xz extends Wxapp{ function __construct($inputs, $app_key){ @@ -39,53 +40,31 @@ class Xz extends Wxapp{ throw new Hd_Exception('用户不存在', API_CODE_INVILD_PARAM); } $customer_mobile = $row['mobile']; + $user_mobile = $session['mobile']; + $json = $session['jsondata'] ? json_decode($session['jsondata'], true) : array(); + if ($json && $json['hdy'] && $json['hdy']['tel']) { + $user_mobile = $json['hdy']['tel']; + } $redis = &load_cache('redis'); - $cache_key = "XZ_LICHEB_MOBILEB_{$customer_mobile}_{$admin_id}"; + $cache_key = "XZ_LICHEB_MOBILEA_{$user_mobile}_MOBILEB_{$customer_mobile}_{$admin_id}"; $call_mobile = $redis->get($cache_key); if (!$call_mobile) { - $this->config->load('xcall', TRUE); - $mobile_list = $this->config->item('mobile_list', 'xcall');//晓智号码库 - require_once COMMPATH.'third_party/Xcall/Xcall.php'; + $this->config->load('xcall'); + $params = [ + 'app_id' => $this->config->item('app_id'), + 'app_key' => $this->config->item('app_key'), + ]; $seq_id = create_order_no(); $result = ''; //循环绑定 - $xcall = new Xcall(); - $maxBindingTime = 30 * 60;//绑定时间 - foreach($mobile_list as $key => $val){ - $mid_mobile = $val; - $result = $xcall -> SWbind($customer_mobile,$seq_id,$mid_mobile,$maxBindingTime); - if($result['code']){ - break; - } - } + $xcall = new Xcall($params); + $maxBindingTime = 10;//绑定时间 + $result = $xcall -> ABXbind($user_mobile, $customer_mobile,$seq_id,$maxBindingTime); if(!$result['code']){ //绑定失败 debug_log("xz_failed_bind:customer_mobile【{$customer_mobile}】", $this->log_file); debug_log("xz_result:" . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file); - //解绑并删除最早绑定手机号 - $redis_obj = $redis->redis(); - $lists = $redis_obj->keys("XZ_LICHEB_MOBILEB_*"); - $del_cache = ''; - $temp_time = $maxBindingTime; - foreach ($lists as $key => $val) { - $l_c_time = $redis_obj->TTL($val); - if ($l_c_time < $temp_time) { - $temp_time = $l_c_time; - $del_cache = $val; - } - } - if ($del_cache) { - $mid_mobile = $redis->get($del_cache); - //解绑 - $s_res = $xcall -> Searchbind($mid_mobile); - $bined_mobile = $s_res['data']['value'];//已绑定手机号 - if($bined_mobile){ - $xcall -> SWunbind($bined_mobile,$mid_mobile);//解绑 - $redis->delete($del_cache); - } - $result = $xcall -> SWbind($customer_mobile,$seq_id,$mid_mobile); - } - } - if ($result['code']) { + throw new Hd_Exception($result['msg'], API_CODE_FAIL); + }else{ $this->data['middlenumber'] = $result['data']['virtualMobile']; $add_data = [ 'call_id' => $seq_id, @@ -99,11 +78,7 @@ class Xz extends Wxapp{ ]; $this->receiver_xz_model->add($add_data); $call_mobile = $result['data']['virtualMobile']; - $redis->save($cache_key, $call_mobile, $maxBindingTime); - } else { - debug_log("xz_failed_bind:customer_mobile【{$customer_mobile}】", $this->log_file); - debug_log("xz_result:" . json_encode($result, JSON_UNESCAPED_UNICODE), $this->log_file); - throw new Hd_Exception($result['msg'], API_CODE_FAIL); + $redis->save($cache_key, $call_mobile, $maxBindingTime*60); } } $data['mobile'] = $call_mobile; diff --git a/common/third_party/Xcall/Xcall.php b/common/third_party/Xcall/Xcall.php index ba9b0eeb..dd675319 100644 --- a/common/third_party/Xcall/Xcall.php +++ b/common/third_party/Xcall/Xcall.php @@ -14,8 +14,11 @@ class Xcall{ private $ci; private $log_file = 'xcall.log'; - public function __construct(){ + public function __construct($params=[]){ $this -> ci = & get_instance(); + + $params['app_id'] && $this->id = $params['app_id']; + $params['app_key'] && $this->key = $params['app_key']; } /** * 商务号绑定 @@ -105,7 +108,7 @@ class Xcall{ } //绑定关系 - public function ABXbind($mobileA, $mobileB,$seq_id, $middleNumber='',$scene=''){ + public function ABXbind($mobileA, $mobileB,$seq_id,$bindTime=10,$middleNumber=''){ $url=$this->api_url.'autoCallTransferForSp.do'; $spId=$this->id; //teleii平台分配的商户id $spKey=$this->key; //teleii平台分配的商户key @@ -114,7 +117,7 @@ class Xcall{ $fm=$mobileA; //主叫号码 $tm=$mobileB; //被叫号码 $virtualMobile=$middleNumber; //虚拟号码.创建新关系时,虚拟号码为空,系统自行分配虚拟号码。 - $bindTime=10;//关系绑定10分钟 + $bindTime=$bindTime;//关系绑定时间(单位分钟) //Md5(key+id+seqId+timestamp+fm+tm); 生成签名 $sign_source=$spKey.$spId.$seqId.$timestamp.$fm.$tm;