test(addon/aikefu): 还原原先的kefu.app 方便测试
This commit is contained in:
@@ -206,6 +206,64 @@ class Kefu extends BaseApi
|
|||||||
|
|
||||||
return $ip;
|
return $ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除会话历史
|
||||||
|
*/
|
||||||
|
public function clearConversation()
|
||||||
|
{
|
||||||
|
// 获取请求参数
|
||||||
|
$conversation_id = $this->params['conversation_id'] ?? '';
|
||||||
|
$user_id = $this->params['user_id'] ?? $this->member_id;
|
||||||
|
|
||||||
|
// (可选)获取站点ID和会员ID,可以通过事件数据传递
|
||||||
|
$site_id = $this->params['uniacid'] ?? $this->site_id; // 使用 uniacid, 方便以后迁移,而且uniacid 是唯一的, site_id 不是,同时被params给过滤了
|
||||||
|
$member_id = $this->params['member_id'] ?? $this->member_id;
|
||||||
|
$token = $this->params['token'] ?? $this->token;
|
||||||
|
|
||||||
|
// 验证参数(conversation_id 和 user_id 至少需要一个)
|
||||||
|
if (empty($conversation_id) && empty($user_id)) {
|
||||||
|
return $this->response($this->error('会话ID或用户ID不能为空'));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 准备事件数据
|
||||||
|
$event_data = [
|
||||||
|
'conversation_id' => $conversation_id,
|
||||||
|
'user_id' => $user_id,
|
||||||
|
'site_id' =>$site_id,
|
||||||
|
'member_id' => $member_id,
|
||||||
|
'token' => $token,
|
||||||
|
];
|
||||||
|
|
||||||
|
// 触发清除会话事件
|
||||||
|
$result = Event::trigger('KefuClearConversation', $event_data);
|
||||||
|
|
||||||
|
// 处理事件结果
|
||||||
|
$response = [
|
||||||
|
'code' => 0,
|
||||||
|
'message' => 'success',
|
||||||
|
'data' => []
|
||||||
|
];
|
||||||
|
|
||||||
|
if (is_array($result) && !empty($result)) {
|
||||||
|
foreach ($result as $res) {
|
||||||
|
if (isset($res['code']) && $res['code'] < 0) {
|
||||||
|
$response = $res;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (isset($res['data'])) {
|
||||||
|
$response['data'] = array_merge($response['data'], $res['data']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->response($response);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->response($this->error('请求失败:' . $e->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 智能客服聊天接口
|
* 智能客服聊天接口
|
||||||
* @return \think\response\Json
|
* @return \think\response\Json
|
||||||
|
|||||||
Reference in New Issue
Block a user