Files
ai-shiliu/legacy/test_dify_v2.php
figmar 81115dc23d 初始提交:识流 AI 助手项目
微信自动回复机器人,基于截图+OCR识别消息,支持关键词规则和 AI(OpenAI/DeepSeek/Dify)自动回复。
技术栈:PySide6 + Flask + Vue3 + RapidOCR + SQLite

注:OCR大模型文件(.onnx / .pdiparams)不纳入版本控制,需单独下载。

🤖 Generated with [Qoder][https://qoder.com]
2026-05-30 15:09:40 +08:00

82 lines
2.4 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/config.php';
echo "=== 测试Dify配置 ===\n\n";
echo "AI_PROVIDER: " . AI_PROVIDER . "\n";
echo "DIFY_API_KEY: " . DIFY_API_KEY . "\n";
echo "DIFY_API_BASE: " . DIFY_API_BASE . "\n";
echo "DIFY_USER: " . DIFY_USER . "\n\n";
// 测试请求
$url = rtrim(DIFY_API_BASE, '/') . '/chat-messages';
echo "请求URL: {$url}\n\n";
$headers = [
'Content-Type: application/json',
'Authorization: Bearer ' . DIFY_API_KEY,
];
$payload = [
'inputs' => (object)[], // 空对象
'query' => '你好',
'response_mode' => 'blocking',
'user' => DIFY_USER,
];
echo "请求数据:\n";
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n\n";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload, JSON_UNESCAPED_UNICODE));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_VERBOSE, true); // 开启详细输出
echo "发送请求...\n";
$response = curl_exec($ch);
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);
echo "HTTP状态码: {$statusCode}\n";
echo "响应内容长度: " . strlen($response) . " 字节\n";
if ($error) {
echo "cURL错误: {$error}\n";
}
echo "\n响应内容:\n";
if (empty($response)) {
echo "(空响应)\n\n";
} else {
echo $response . "\n\n";
}
if ($statusCode == 200) {
if (empty($response)) {
echo "✗ 响应为空\n\n";
echo "可能的原因:\n";
echo "1. Dify应用未发布或已停用\n";
echo "2. API Key不正确\n";
echo "3. response_mode='blocking' 不支持(试试改成 'streaming'\n";
echo "4. Dify服务器问题\n";
} else {
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo "✗ JSON解析失败: " . json_last_error_msg() . "\n";
} elseif (isset($data['answer'])) {
echo "✓ 成功AI回复: " . $data['answer'] . "\n";
} else {
echo "✗ 响应格式错误\n";
echo "JSON内容: " . print_r($data, true) . "\n";
}
}
} else {
echo "✗ 请求失败HTTP {$statusCode}\n";
}