chore(addon/aikefu): 优化请求参数说明
This commit is contained in:
@@ -201,7 +201,10 @@ class Kefu extends BaseApi
|
||||
$stream = $this->params['stream'] ?? false;
|
||||
|
||||
// 验证参数并获取配置
|
||||
$config = $this->validateAndGetConfig($message);
|
||||
$config = $this->validateAndGetConfig([
|
||||
'message' => ['required' => true, 'message' => '请求参数 `query` 不能为空. 为消息内容', 'description' => '消息内容, message 参数,上流为 query'],
|
||||
'user_id' => ['required' => true, 'message' => '请求参数 `user_id` 不能为空', 'description' => '用户ID, user_id 参数,上流为 user_id']
|
||||
]);
|
||||
if ($config instanceof \think\response\Json) {
|
||||
return $config;
|
||||
}
|
||||
@@ -229,14 +232,25 @@ class Kefu extends BaseApi
|
||||
|
||||
/**
|
||||
* 验证参数并获取配置
|
||||
* @param string $message 用户消息
|
||||
* @param array $params_rules 参数验证规则
|
||||
* [
|
||||
* 'message' => ['required' => true, 'message' => '请输入消息内容'],
|
||||
* ]
|
||||
* @return array|\think\response\Json
|
||||
*/
|
||||
private function validateAndGetConfig($message)
|
||||
private function validateAndGetConfig($params_rules = [])
|
||||
{
|
||||
// 参数验证规则
|
||||
$rules = [];
|
||||
|
||||
// 合并参数验证规则
|
||||
$rules = array_merge($rules, $params_rules);
|
||||
|
||||
// 验证参数
|
||||
if (empty($message)) {
|
||||
return $this->response($this->error('请输入消息内容'));
|
||||
foreach ($rules as $field => $rule) {
|
||||
if (isset($rule['required']) && $rule['required'] && empty($this->params[$field])) {
|
||||
return $this->response($this->error($rule['message']));
|
||||
}
|
||||
}
|
||||
|
||||
// 获取智能客服配置
|
||||
@@ -442,7 +456,7 @@ class Kefu extends BaseApi
|
||||
{
|
||||
// 只允许info、error级别
|
||||
if (!in_array($level, ['info', 'error'])) {
|
||||
return;
|
||||
return;
|
||||
}
|
||||
log_write($message, $level, '', 2);
|
||||
}
|
||||
|
||||
@@ -339,7 +339,10 @@ class Kefu extends BaseApi
|
||||
|
||||
// 验证参数
|
||||
if (empty($query)) {
|
||||
return $this->response($this->error('请输入消息内容,参数项: query'));
|
||||
return $this->response($this->error('参数错误,请检查 `query` 参数是否设置正确'));
|
||||
}
|
||||
if (empty($site_id)) {
|
||||
return $this->response($this->error('参数错误,请检查 `uniacid` 参数是否设置正确'));
|
||||
}
|
||||
|
||||
// 验证事件是否存在
|
||||
@@ -348,8 +351,8 @@ class Kefu extends BaseApi
|
||||
}
|
||||
|
||||
try {
|
||||
// 是否启用流式响应
|
||||
$enable_stream = $stream && $response_mode == 'streaming';
|
||||
// 是否启用流式响应 (stream 参数为 true 或 response_mode 为 streaming)
|
||||
$enable_stream = $stream || $response_mode == 'streaming';
|
||||
|
||||
// 准备事件数据
|
||||
$event_data = [
|
||||
|
||||
Reference in New Issue
Block a user