Files
spacestation/api/controllers/wxapp/licheb/Yx.php
T
2024-06-04 21:11:42 +08:00

73 lines
2.8 KiB
PHP

<?php
defined('WXAPP_APP') or exit('No direct script access allowed');
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
require_once COMMPATH . 'third_party/Ycall/Ycall.php';
class Yx 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/receiver_yx_model');
$this->log_file = 'call.log';
}
protected function get()
{
$id = $this->input_param('id');
$session = $this->session;
$admin_id = $session['uid'];
$cf_title = 'customer';
$cus_id = $id;
$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) {
$seq_id = create_order_no();
$ycall = new Ycall();
$maxBindingTime = 10;//绑定时间
$result = $ycall->ABXbind($user_mobile, $customer_mobile, $seq_id, $maxBindingTime);
if ($result['result'] != '000000') { //绑定失败
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['message'], API_CODE_FAIL);
} else {
$call_mobile = $result['middleNumber'];
$add_data = [
'call_id' => $seq_id,
'display_number' => $call_mobile,
'biz_id' => $row['biz_id'],
'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_yx_model->add($add_data);
$redis->save($cache_key, $call_mobile, $maxBindingTime * 60);
}
}
$data['mobile'] = $call_mobile;
return $data;
}
}