API 测试功能诊断'; // 1. 检查函数是否存在 echo '
✓ ' . $func . ' 存在
'; } else { echo '✗ ' . $func . ' 不存在
'; } } // 2. 检查是否有 API 配置 echo '⚠ 没有配置任何 API
'; } else { echo '✓ 已配置 ' . count($all_apis) . ' 个 API
'; foreach ($all_apis as $api) { echo '✓ wp_ajax_argon_ajax_test_unified_api 已注册
'; } else { echo '✗ wp_ajax_argon_ajax_test_unified_api 未注册
'; } // 4. 测试 nonce 生成 echo '生成的 nonce: ' . $nonce . '
验证结果: '; if (wp_verify_nonce($nonce, 'argon_test_unified_api')) { echo '✓ 验证通过
'; } else { echo '✗ 验证失败'; } // 5. 模拟 AJAX 请求测试 if (!empty($all_apis)) { echo '测试 API: ' . esc_html($test_api['name']) . '
'; // 模拟 $_POST 数据 $_POST['api_id'] = $test_api['id']; $_POST['nonce'] = wp_create_nonce('argon_test_unified_api'); echo '开始测试...
'; // 获取 API 配置 $api = argon_get_api_by_id($test_api['id']); if (!$api) { echo '✗ 无法获取 API 配置
'; } else { echo '✓ 成功获取 API 配置
'; // 获取默认端点 $default_endpoints = [ 'openai' => 'https://api.openai.com/v1/chat/completions', 'anthropic' => 'https://api.anthropic.com/v1/messages', 'deepseek' => 'https://api.deepseek.com/v1/chat/completions', 'xiaomi' => 'https://api.mimo.xiaomi.com/v1/chat/completions', 'qianwen' => 'https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions', 'wenxin' => 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions', 'doubao' => 'https://ark.cn-beijing.volces.com/api/v3/chat/completions', 'kimi' => 'https://api.moonshot.cn/v1/chat/completions', 'zhipu' => 'https://open.bigmodel.cn/api/paas/v4/chat/completions', 'siliconflow' => 'https://api.siliconflow.cn/v1/chat/completions' ]; $api_endpoint = !empty($api['api_endpoint']) ? $api['api_endpoint'] : $default_endpoints[$api['provider']]; $model = !empty($api['model']) ? $api['model'] : 'gpt-4o-mini'; echo 'API 端点: ' . esc_html($api_endpoint) . '
模型: ' . esc_html($model) . '
发送测试请求...
'; $start_time = microtime(true); $response = wp_remote_post($api_endpoint, [ 'headers' => [ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer ' . $api['api_key'] ], 'body' => json_encode($data), 'timeout' => 30 ]); $response_time = round((microtime(true) - $start_time) * 1000); if (is_wp_error($response)) { echo '✗ 请求失败: ' . $response->get_error_message() . '
'; } else { $status_code = wp_remote_retrieve_response_code($response); $body = wp_remote_retrieve_body($response); echo 'HTTP 状态码: ' . $status_code . '
响应时间: ' . $response_time . 'ms
✓ API 测试成功!
'; if (isset($result['choices'][0]['message']['content'])) { echo 'AI 回复: ' . esc_html($result['choices'][0]['message']['content']) . '
'; } } else { echo '✗ API 返回格式异常
'; echo '' . htmlspecialchars($body) . ''; } } else { echo '
✗ API 返回错误
'; echo '' . htmlspecialchars($body) . ''; } } } } echo '