基于DifyAI智能客服系统,支持图文,支持汇总统计用户问题分类。翻看网上多篇文章觉得没有我这篇最直白,最好的博文!个人极力推荐

发布时间:2026/5/25 3:20:42

基于DifyAI智能客服系统,支持图文,支持汇总统计用户问题分类。翻看网上多篇文章觉得没有我这篇最直白,最好的博文!个人极力推荐 利用dify做的一个机器人聊天支持图文支持汇总统计用户问题。后端代码非常简单public function index(RequestKaTeX parse error: Expected }, got EOF at end of input: … if (!request-isPost()) {Log::error(‘Dify请求方法错误仅支持POST当前方法’.$request-method());return json([‘code’ 405, ‘msg’ ‘接口仅支持POST请求’])-code(405);}$fromSource $request-header(X-From); if ($fromSource ! Dify) { Log::error(非Dify来源请求拒绝访问请求头X-From.$fromSource); return json([code 403, msg 拒绝访问仅支持Dify请求])-code(403); } $jsonData file_get_contents(php://input); $allParams is_array(json_decode($jsonData, true)) ? json_decode($jsonData, true) : []; Log::info(Dify传过来的所有参数, $allParams); if (empty($allParams)) { Log::error(Dify JSON参数解析为空原始数据.$jsonData); return json([code 400, msg 请求参数为空])-code(400); } $hasValidImageData false; if (isset($allParams[llm2_text]) is_array($allParams[llm2_text]) !empty($allParams[llm2_text])) { $imageResult $allParams[llm2_text]; if (isset($imageResult[image_text], $imageResult[has_text])) { $imageResult[key_info] is_array($imageResult[key_info]) ? $imageResult[key_info] : []; $imageResult[image_text] trim($imageResult[image_text] ?: ); $imageResult[image_desc] trim($imageResult[image_desc] ?: ); $hasValidImageData true; $allParams[image_result] $imageResult; Log::info(【有效图片识别】核心结果, [ 是否识别到文字 $imageResult[has_text], 提取文字长度 strlen($imageResult[image_text]), 图片描述 $imageResult[image_desc] ]); } else { Log::error(【无效图片内容】llm2_text字段格式错误缺少核心字段); } } else { Log::info(【纯文字请求】无图片识别内容用户问题.$allParams[user_question]); } return json([ code 200, msg $hasValidImageData ? 图片识别内容接收成功 : 参数接收成功, data $allParams, has_valid_image $hasValidImageData ])-code(200)-options(JSON_UNESCAPED_UNICODE); }另外我的另外一个项目 证件照制作的也是轻量级项目复制连接看下效果吧 临时邮箱https://www.nimail.cn/

相关新闻