88 lines
3.4 KiB
PHP
88 lines
3.4 KiB
PHP
<?php
|
|
defined('WXAPP_APP') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Created by Vim.
|
|
* User: lcc
|
|
* Desc: 晓致虚拟号
|
|
* Date: 2021/07/26
|
|
* 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){
|
|
parent::__construct($inputs, $app_key);
|
|
|
|
$this->login_white = array();//登录白名单
|
|
|
|
$this->load->model('receiver/receiver_customers_model','customers_model');
|
|
$this->load->model('receiver/order/receiver_orders_model','orders_model');
|
|
|
|
$this->load->model('receiver/receiver_xz_model');
|
|
$this->log_file = 'call.log';
|
|
}
|
|
protected function get(){
|
|
$id = $this->input_param('id');
|
|
$type = intval($this->input_param('type'));
|
|
!$type && $type = 0;
|
|
$session = $this->session;
|
|
$admin_id = $session['uid'];
|
|
$cf_title = 'customer';
|
|
$cus_id = $id;
|
|
if($type==1){ //订单
|
|
$order = $this->orders_model->get(['id'=>$id]);
|
|
$cus_id = $order['rid'];
|
|
}
|
|
$row = $this->customers_model->get(['id'=>$cus_id]);
|
|
if(!$row || !$row['mobile']){
|
|
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_MOBILEA_{$user_mobile}_MOBILEB_{$customer_mobile}_{$admin_id}";
|
|
$call_mobile = $redis->get($cache_key);
|
|
if (!$call_mobile) {
|
|
$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($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);
|
|
throw new Hd_Exception($result['msg'], API_CODE_FAIL);
|
|
}else{
|
|
$this->data['middlenumber'] = $result['data']['virtualMobile'];
|
|
$add_data = [
|
|
'call_id' => $seq_id,
|
|
'display_number' => $result['data']['virtualMobile'],
|
|
'cf_id' => $cus_id,
|
|
'cf_uid' => $admin_id,
|
|
'cf_title' => $cf_title,
|
|
'cf_platform' => 'api',
|
|
'json_data' => json_encode(['uname'=>$session['uname']],JSON_UNESCAPED_UNICODE),
|
|
'c_time' => time()
|
|
];
|
|
$this->receiver_xz_model->add($add_data);
|
|
$call_mobile = $result['data']['virtualMobile'];
|
|
$redis->save($cache_key, $call_mobile, $maxBindingTime*60);
|
|
}
|
|
}
|
|
$data['mobile'] = $call_mobile;
|
|
return $data;
|
|
}
|
|
}
|