增加平安外呼系统

This commit is contained in:
lcc
2025-08-08 14:07:29 +08:00
parent 32b8397ac8
commit 4a598a7233
4 changed files with 152 additions and 1 deletions
+3
View File
@@ -13,6 +13,9 @@ class Welcome extends CI_Controller
public function test()
{
$this->load->library('carHome/callOut');
$callOut = new CallOut();
// $callOut->call();
// $this->load->model('receiver/receiver_customers_model', 'customers_model');
// $rid = 17418;
// $bizId = 57;
+17
View File
@@ -0,0 +1,17 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
/**
* 平安电话推送地址
*/
class CallBack extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
}
}
+1 -1
View File
@@ -1105,7 +1105,7 @@ class Customers extends Wxapp
$customer_id = $this->customers_model->add($addData);
if ($customer_id) {
//初始门店更改-1,理车宝过滤
$this->customers_model->update(['cs_biz_id' => -1], ["id" => $id]);
// $this->customers_model->update(['cs_biz_id' => -1], ["id" => $id]);
//删除未回访计划
$this->mdCustomerVisitData->delete(['c_id' => $id, 'biz_id' => $re['biz_id'], 'status<>' => 2, 't_day >=' => date('Y-m-d')]);
//同步客户标签
+131
View File
@@ -0,0 +1,131 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
/**
* 汽车之家外呼接口
*/
class CallOut
{
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
protected $baseUrl = 'http://202.105.128.251:18082/bas_car_home_ping_tai/car/v1/call'; //正式接口地址
protected $aesKey = 'AmUFhqX2IOI48BwdgAXVsQgvncCD0f5X'; //AES秘钥
protected $ctiType = 'QCZJ'; //平台类型,固定QCZJ
protected $ci;
protected $client;
// 生产环境:
// 汽车之家外呼接口(互联网主线): http://202.105.128.251:18082/bas_car_home_ping_tai/car/v1/call
// 汽车之家外呼接口(互联网备线): http://218.18.234.155:18082/bas_car_home_ping_tai/car/v1/call
// 测试环境:
// 汽车之家外呼接口(互联网主线): http://202.105.128.251:18081/bas_car_home_ping_tai/car/v1/call
// 汽车之家外呼接口(互联网备线): http://218.18.234.155:18081/bas_car_home_ping_tai/car/v1/call
public function __construct()
{
$this->ci = &get_instance();
$this->client = new Client();
if (!is_product()) { //测试环境
$this->baseUrl = 'http://202.105.128.251:18081/bas_car_home_ping_tai/car/v1/call';
$this->aesKey = 'JKCDlCxTvwNumLQVAMQltfpuOSCSa6J9';
}
}
public function call()
{
try {
$agentPhoneNo = '18350451617';
$customerPhoneNo = '13365081602';
$enAgentPhoneNo = $this->aesEcbPkcs5Encrypt($agentPhoneNo, $this->aesKey);
$enCustomerPhoneNo = $this->aesEcbPkcs5Encrypt($customerPhoneNo, $this->aesKey);
$params = [
'orderId' => md5(time()), //必选 String 订单号
'agentPhoneNo' => $enAgentPhoneNo, //必选 String 坐席分机。坐席分机如采用AES加密,汽车之家系统传加密后的号码
'customerPhoneNo' => $enCustomerPhoneNo, //必选 String 客户手机号码。加密规则与坐席分机一致
// 'agentId' => '', //备选 String 坐席工号(汽车之家上报开通的中兴平台唯一cti号码)
// 'agentUm' => '', //备选 String 坐席Um(汽车之家人员um账号)
'displayedPhoneNo' => '0', //必选 String 外显号码(传“0”和空值均为云中继外显)
];
$reqParams = [
'ctiType' => $this->ctiType,
'requestId' => time(),
'para' => $params
];
$req = $this->send($this->baseUrl, $reqParams, self::METHOD_POST);
print_r($req);
} catch (\Exception $e) {
}
}
/**
* AES-ECB模式加密,使用PKCS5Padding填充
* @param string $data 待加密的数据
* @param string $key 加密密钥(16/24/32字节,对应AES-128/192/256
* @return string 加密后的base64字符串
*/
function aesEcbPkcs5Encrypt($data, $key)
{
// 检查密钥长度
$keyLength = strlen($key);
if (!in_array($keyLength, [16, 24, 32])) {
throw new InvalidArgumentException("密钥长度必须是16、24或32字节");
}
// 根据密钥长度确定AES模式
$cipher = 'AES-' . ($keyLength * 8) . '-ECB';
// 执行加密,OPENSSL_RAW_DATA表示输出原始二进制,默认使用PKCS5填充
$encrypted = openssl_encrypt($data, $cipher, $key, OPENSSL_RAW_DATA, '');
// 返回base64编码结果(也可根据需要改为bin2hex输出16进制)
return bin2hex($encrypted);
}
/**
* AES-ECB模式解密,对应HEX格式的加密数据
* @param string $hexData 加密后的十六进制字符串
* @param string $key 解密密钥(与加密密钥相同)
* @return string 解密后的原始数据
*/
function aesEcbPkcs5DecryptFromHex($hexData, $key)
{
$keyLength = strlen($key);
if (!in_array($keyLength, [16, 24, 32])) {
throw new InvalidArgumentException("密钥长度必须是16、24或32字节");
}
$cipher = 'AES-' . ($keyLength * 8) . '-ECB';
// 先将十六进制转回二进制,再解密
$decrypted = openssl_decrypt(hex2bin($hexData), $cipher, $key, OPENSSL_RAW_DATA, '');
return $decrypted;
}
public function send($url, $data = [], $type = self::METHOD_GET)
{
try {
$options = [
'headers' => [
'Content-Type' => 'application/json'
],
];
if ($data) {
$options['json'] = $data;
}
$response = $this->client->request($type, $url, $options);
// $response = $this->client->post($url, [
// 'form_params' => $data,
// // 可选:设置超时时间
// 'timeout' => 5.0,
// ]);
return [$response->getBody()->getContents(), $options, $response->getStatusCode()];
} catch (Exception $e) {
debug_log($e->getMessage() . ' URL: ' . $url . ' Data: ' . json_encode($data));
throw $e;
}
}
}