127 lines
4.7 KiB
PHP
127 lines
4.7 KiB
PHP
<?php
|
||
|
||
namespace addon\aikefu\event;
|
||
|
||
use addon\aikefu\model\Config as KefuConfigModel;
|
||
|
||
/**
|
||
* 获取智能客服配置信息
|
||
*/
|
||
class KefuGetInfo
|
||
{
|
||
/**
|
||
* 处理获取配置信息事件
|
||
* @param array $data 事件数据
|
||
* @return array
|
||
*/
|
||
public function handle($data)
|
||
{
|
||
$site_id = $data['site_id'] ?? 0;
|
||
$member_id = $data['member_id'] ?? 0;
|
||
$client_info = $data['client_info'] ?? [];
|
||
|
||
try {
|
||
// 获取智能客服配置
|
||
$kefu_config_model = new KefuConfigModel();
|
||
$config_info = $kefu_config_model->getConfig($site_id);
|
||
|
||
$response_data = [
|
||
'service_info' => [
|
||
'name' => '智能客服',
|
||
'version' => '1.0.0',
|
||
'enabled' => false,
|
||
'status' => 'disabled'
|
||
],
|
||
'features' => [],
|
||
'limits' => [
|
||
'max_message_length' => 4000,
|
||
'max_conversation_history' => 100,
|
||
'rate_limit' => [
|
||
'requests_per_minute' => 60,
|
||
'requests_per_hour' => 1000
|
||
]
|
||
],
|
||
'endpoints' => [
|
||
'chat' => '/api/chat',
|
||
'chat_stream' => '/api/chatStream',
|
||
'create_conversation' => '/api/createConversation',
|
||
'get_history' => '/api/getHistory',
|
||
'clear_conversation' => '/api/clearConversation',
|
||
'health' => '/api/health',
|
||
'info' => '/api/info'
|
||
],
|
||
'client_info' => $client_info,
|
||
'server_info' => [
|
||
'php_version' => PHP_VERSION,
|
||
'server_time' => date('Y-m-d H:i:s'),
|
||
'timezone' => date_default_timezone_get()
|
||
]
|
||
];
|
||
|
||
// 处理配置信息
|
||
if (!empty($config_info['data']['value'])) {
|
||
$config = $config_info['data']['value'];
|
||
|
||
// 服务状态
|
||
$response_data['service_info']['enabled'] = $config['status'] == 1;
|
||
$response_data['service_info']['status'] = $config['status'] == 1 ? 'enabled' : 'disabled';
|
||
|
||
// 可用功能
|
||
if ($config['status'] == 1) {
|
||
$response_data['features'] = [
|
||
'chat' => true,
|
||
'chat_stream' => true,
|
||
'conversation_management' => true,
|
||
'history_management' => true
|
||
];
|
||
}
|
||
|
||
// API端点信息(仅在启用时显示详细配置)
|
||
if ($config['status'] == 1) {
|
||
$response_data['api_config'] = [
|
||
'base_url' => $config['base_url'] ?? '',
|
||
'chat_endpoint' => $config['chat_endpoint'] ?? '',
|
||
'supports_streaming' => true,
|
||
'authentication' => 'bearer_token'
|
||
];
|
||
}
|
||
|
||
// 限制配置(如果有的话)
|
||
if (isset($config['max_message_length'])) {
|
||
$response_data['limits']['max_message_length'] = intval($config['max_message_length']);
|
||
}
|
||
if (isset($config['rate_limit_per_minute'])) {
|
||
$response_data['limits']['rate_limit']['requests_per_minute'] = intval($config['rate_limit_per_minute']);
|
||
}
|
||
}
|
||
|
||
// 添加使用统计信息(如果需要的话)
|
||
if ($member_id > 0) {
|
||
$response_data['user_stats'] = [
|
||
'can_use_service' => $response_data['service_info']['enabled'],
|
||
'member_id' => $member_id,
|
||
'site_id' => $site_id
|
||
];
|
||
}
|
||
|
||
return [
|
||
'code' => 0,
|
||
'message' => '获取配置信息成功',
|
||
'data' => $response_data
|
||
];
|
||
|
||
} catch (\Exception $e) {
|
||
return [
|
||
'code' => -1,
|
||
'message' => '获取配置信息失败:' . $e->getMessage(),
|
||
'data' => [
|
||
'service_info' => [
|
||
'name' => '智能客服',
|
||
'status' => 'error'
|
||
],
|
||
'error' => $e->getMessage()
|
||
]
|
||
];
|
||
}
|
||
}
|
||
} |