chore: 清理所有测试文件

- 删除 test-xiaomi-mimo-api.php
- 删除 test-api-test-function.php
- 删除 test-ai-query-component.php
- 删除 test-api-connection-debug.php
This commit is contained in:
2026-01-27 10:52:41 +08:00
parent 734822883e
commit dca4680565
4 changed files with 0 additions and 764 deletions

View File

@@ -1,276 +0,0 @@
<?php
/**
* AI 查询组件测试脚本
*
* 使用方法:
* 1. 将此文件放在 WordPress 主题目录
* 2. 在浏览器访问http://your-site.com/wp-content/themes/argon/test-ai-query-component.php
* 3. 查看测试结果
*/
// 加载 WordPress
require_once('../../../wp-load.php');
// 检查权限
if (!current_user_can('manage_options')) {
die('权限不足');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>AI 查询组件测试</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 1200px;
margin: 40px auto;
padding: 20px;
background: #f5f5f5;
}
.test-section {
background: white;
padding: 20px;
margin-bottom: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.test-section h2 {
margin-top: 0;
color: #333;
border-bottom: 2px solid #0073aa;
padding-bottom: 10px;
}
.success {
color: #46b450;
font-weight: bold;
}
.error {
color: #dc3232;
font-weight: bold;
}
.info {
color: #0073aa;
}
pre {
background: #f0f0f0;
padding: 15px;
border-radius: 4px;
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 10px;
}
table th, table td {
padding: 10px;
text-align: left;
border-bottom: 1px solid #ddd;
}
table th {
background: #f9f9f9;
font-weight: bold;
}
</style>
</head>
<body>
<h1>🧪 AI 查询组件测试</h1>
<?php
global $wpdb;
$table_name = $wpdb->prefix . 'argon_ai_query_log';
// 测试 1检查数据表是否存在
echo '<div class="test-section">';
echo '<h2>测试 1数据表检查</h2>';
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
if ($table_exists) {
echo '<p class="success">✓ 数据表已存在:' . $table_name . '</p>';
// 显示表结构
$columns = $wpdb->get_results("DESCRIBE $table_name");
echo '<p class="info">表结构:</p>';
echo '<table>';
echo '<tr><th>字段名</th><th>类型</th><th>允许空值</th><th>键</th><th>默认值</th></tr>';
foreach ($columns as $column) {
echo '<tr>';
echo '<td>' . esc_html($column->Field) . '</td>';
echo '<td>' . esc_html($column->Type) . '</td>';
echo '<td>' . esc_html($column->Null) . '</td>';
echo '<td>' . esc_html($column->Key) . '</td>';
echo '<td>' . esc_html($column->Default) . '</td>';
echo '</tr>';
}
echo '</table>';
} else {
echo '<p class="error">✗ 数据表不存在,尝试创建...</p>';
argon_create_ai_query_log_table();
$table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name;
if ($table_exists) {
echo '<p class="success">✓ 数据表创建成功</p>';
} else {
echo '<p class="error">✗ 数据表创建失败</p>';
}
}
echo '</div>';
// 测试 2检查记录函数
echo '<div class="test-section">';
echo '<h2>测试 2记录函数测试</h2>';
if (function_exists('argon_log_ai_query')) {
echo '<p class="success">✓ argon_log_ai_query 函数存在</p>';
// 插入测试记录
argon_log_ai_query(
'openai',
'gpt-4o-mini',
'test',
100,
500,
150,
1234,
'success',
'',
['post_id' => 1, 'user_id' => 1]
);
// 查询最新记录
$latest = $wpdb->get_row("SELECT * FROM $table_name ORDER BY id DESC LIMIT 1");
if ($latest) {
echo '<p class="success">✓ 测试记录插入成功</p>';
echo '<p class="info">最新记录:</p>';
echo '<pre>' . print_r($latest, true) . '</pre>';
} else {
echo '<p class="error">✗ 测试记录插入失败</p>';
}
} else {
echo '<p class="error">✗ argon_log_ai_query 函数不存在</p>';
}
echo '</div>';
// 测试 3检查统计函数
echo '<div class="test-section">';
echo '<h2>测试 3统计函数测试</h2>';
if (function_exists('argon_get_ai_query_stats')) {
echo '<p class="success">✓ argon_get_ai_query_stats 函数存在</p>';
$stats = argon_get_ai_query_stats();
echo '<p class="info">统计结果:</p>';
echo '<pre>' . print_r($stats, true) . '</pre>';
} else {
echo '<p class="error">✗ argon_get_ai_query_stats 函数不存在</p>';
}
echo '</div>';
// 测试 4检查统一查询接口
echo '<div class="test-section">';
echo '<h2>测试 4统一查询接口测试</h2>';
if (function_exists('argon_ai_query')) {
echo '<p class="success">✓ argon_ai_query 函数存在</p>';
// 检查是否配置了 AI 服务商
$provider = get_option('argon_ai_summary_provider', 'openai');
$config = argon_get_ai_provider_config($provider);
if ($config && !empty($config['api_key'])) {
echo '<p class="info">当前服务商:' . esc_html($provider) . '</p>';
echo '<p class="info">API 密钥:' . esc_html(substr($config['api_key'], 0, 10)) . '...</p>';
echo '<p class="info">模型:' . esc_html($config['model']) . '</p>';
echo '<p class="info">⚠️ 跳过实际 API 调用测试(避免消耗 tokens</p>';
echo '<p class="info">如需测试实际调用,请手动调用 argon_ai_query() 函数</p>';
} else {
echo '<p class="error">✗ 未配置 AI 服务商或 API 密钥</p>';
}
} else {
echo '<p class="error">✗ argon_ai_query 函数不存在</p>';
}
echo '</div>';
// 测试 5查看最近的查询记录
echo '<div class="test-section">';
echo '<h2>测试 5最近的查询记录</h2>';
$recent_queries = $wpdb->get_results("SELECT * FROM $table_name ORDER BY query_time DESC LIMIT 10");
if ($recent_queries) {
echo '<p class="success">✓ 找到 ' . count($recent_queries) . ' 条记录</p>';
echo '<table>';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>时间</th>';
echo '<th>服务商</th>';
echo '<th>模型</th>';
echo '<th>场景</th>';
echo '<th>响应时间</th>';
echo '<th>状态</th>';
echo '</tr>';
foreach ($recent_queries as $query) {
echo '<tr>';
echo '<td>' . esc_html($query->id) . '</td>';
echo '<td>' . esc_html($query->query_time) . '</td>';
echo '<td>' . esc_html($query->provider) . '</td>';
echo '<td>' . esc_html($query->model) . '</td>';
echo '<td>' . esc_html($query->scenario) . '</td>';
echo '<td>' . esc_html($query->response_time) . 'ms</td>';
echo '<td class="' . ($query->status === 'success' ? 'success' : 'error') . '">' . esc_html($query->status) . '</td>';
echo '</tr>';
}
echo '</table>';
} else {
echo '<p class="info">暂无查询记录</p>';
}
echo '</div>';
// 测试 6检查 AI 摘要生成函数
echo '<div class="test-section">';
echo '<h2>测试 6AI 摘要生成函数检查</h2>';
if (function_exists('argon_generate_ai_summary')) {
echo '<p class="success">✓ argon_generate_ai_summary 函数存在</p>';
echo '<p class="success">✓ 已使用统一的 argon_ai_query 接口</p>';
} else {
echo '<p class="error">✗ argon_generate_ai_summary 函数不存在</p>';
}
echo '</div>';
// 测试 7检查垃圾评论检测函数
echo '<div class="test-section">';
echo '<h2>测试 7垃圾评论检测函数检查</h2>';
if (function_exists('argon_detect_spam_comment_sync')) {
echo '<p class="success">✓ argon_detect_spam_comment_sync 函数存在</p>';
echo '<p class="success">✓ 已使用统一的 argon_ai_query 接口</p>';
} else {
echo '<p class="error">✗ argon_detect_spam_comment_sync 函数不存在</p>';
}
echo '</div>';
?>
<div class="test-section">
<h2>📝 测试总结</h2>
<p>测试完成!请检查上述结果。</p>
<p><strong>下一步:</strong></p>
<ul>
<li>如果数据表创建成功,可以在 WordPress 后台生成 AI 摘要或检测垃圾评论来测试实际功能</li>
<li>查询记录会自动保存到数据库,可以通过统计函数查看</li>
<li>可以在后台添加统计页面来可视化展示这些数据</li>
</ul>
</div>
<p style="text-align: center; color: #666; margin-top: 40px;">
<a href="<?php echo admin_url('themes.php?page=argon-theme-options'); ?>">返回主题设置</a>
</p>
</body>
</html>

View File

@@ -1,172 +0,0 @@
<?php
/**
* 测试 API 连通性调试脚本
*/
// 加载 WordPress
require_once('../../../wp-load.php');
// 检查是否登录且有管理员权限
if (!is_user_logged_in() || !current_user_can('manage_options')) {
die('需要管理员权限');
}
echo '<h1>API 连通性调试</h1>';
echo '<style>body{font-family:monospace;padding:20px;} .success{color:green;} .error{color:red;} .info{color:blue;} pre{background:#f5f5f5;padding:10px;border-radius:4px;}</style>';
// 1. 检查是否有 API 配置
echo '<h2>1. 检查 API 配置</h2>';
$apis = get_option('argon_ai_apis', []);
if (empty($apis)) {
echo '<p class="error">✗ 没有配置任何 API</p>';
die();
} else {
echo '<p class="success">✓ 找到 ' . count($apis) . ' 个 API 配置</p>';
echo '<pre>' . print_r($apis, true) . '</pre>';
}
// 2. 获取第一个 API 进行测试
$test_api = $apis[0];
$api_id = $test_api['id'];
echo '<h2>2. 测试 API: ' . esc_html($test_api['name']) . '</h2>';
echo '<p class="info">API ID: ' . esc_html($api_id) . '</p>';
echo '<p class="info">提供商: ' . esc_html($test_api['provider']) . '</p>';
echo '<p class="info">模型: ' . esc_html($test_api['model']) . '</p>';
// 3. 测试 argon_get_api_by_id 函数
echo '<h2>3. 测试 argon_get_api_by_id 函数</h2>';
$api = argon_get_api_by_id($api_id);
if ($api) {
echo '<p class="success">✓ 成功获取 API 配置</p>';
echo '<pre>' . print_r($api, true) . '</pre>';
} else {
echo '<p class="error">✗ 无法获取 API 配置</p>';
die();
}
// 4. 获取默认端点
echo '<h2>4. 获取 API 端点</h2>';
$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'] : (isset($default_endpoints[$api['provider']]) ? $default_endpoints[$api['provider']] : '');
if (empty($api_endpoint)) {
echo '<p class="error">✗ 未配置 API 端点</p>';
die();
} else {
echo '<p class="success">✓ API 端点: ' . esc_html($api_endpoint) . '</p>';
}
// 5. 构建测试请求
echo '<h2>5. 构建测试请求</h2>';
$model = !empty($api['model']) ? $api['model'] : 'gpt-4o-mini';
$data = [
'model' => $model,
'messages' => [
[
'role' => 'user',
'content' => '你好,这是一个测试。请回复"测试成功"。'
]
],
'max_tokens' => 50,
'stream' => false
];
echo '<p class="info">请求数据:</p>';
echo '<pre>' . json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . '</pre>';
// 6. 发送请求
echo '<h2>6. 发送 API 请求</h2>';
$start_time = microtime(true);
$response = wp_remote_post($api_endpoint, [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $api['api_key'],
'Accept' => 'application/json'
],
'body' => json_encode($data, JSON_UNESCAPED_UNICODE),
'timeout' => 30,
'sslverify' => true
]);
$response_time = round((microtime(true) - $start_time) * 1000);
echo '<p class="info">响应时间: ' . $response_time . 'ms</p>';
// 7. 检查响应
echo '<h2>7. 检查响应</h2>';
if (is_wp_error($response)) {
echo '<p class="error">✗ 请求失败: ' . $response->get_error_message() . '</p>';
die();
}
$status_code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
echo '<p class="info">HTTP 状态码: ' . $status_code . '</p>';
echo '<p class="info">响应内容:</p>';
echo '<pre>' . esc_html($body) . '</pre>';
// 8. 解析响应
echo '<h2>8. 解析响应</h2>';
if ($status_code === 200) {
$result = json_decode($body, true);
if (json_last_error() !== JSON_ERROR_NONE) {
echo '<p class="error">✗ JSON 解析失败: ' . json_last_error_msg() . '</p>';
} else {
echo '<p class="success">✓ JSON 解析成功</p>';
echo '<pre>' . print_r($result, true) . '</pre>';
if (isset($result['choices'][0]['message']['content']) || isset($result['content'])) {
echo '<p class="success">✓✓✓ API 测试成功!</p>';
} else {
echo '<p class="error">✗ API 返回格式异常(缺少 content 字段)</p>';
}
}
} else {
echo '<p class="error">✗ HTTP 状态码错误: ' . $status_code . '</p>';
$result = json_decode($body, true);
if ($result && isset($result['error'])) {
echo '<p class="error">错误信息: ' . print_r($result['error'], true) . '</p>';
}
}
// 9. 模拟 AJAX 调用
echo '<h2>9. 模拟 AJAX 函数调用</h2>';
echo '<p class="info">现在模拟调用 argon_ajax_test_unified_api 函数...</p>';
// 设置 POST 数据
$_POST['api_id'] = $api_id;
$_POST['nonce'] = wp_create_nonce('argon_test_unified_api');
// 捕获输出
ob_start();
try {
argon_ajax_test_unified_api();
} catch (Exception $e) {
echo '<p class="error">✗ 函数执行异常: ' . $e->getMessage() . '</p>';
}
$ajax_output = ob_get_clean();
echo '<p class="info">AJAX 函数输出:</p>';
echo '<pre>' . esc_html($ajax_output) . '</pre>';
// 尝试解析 JSON
$ajax_result = json_decode($ajax_output, true);
if (json_last_error() === JSON_ERROR_NONE) {
echo '<p class="success">✓ AJAX 返回有效 JSON</p>';
echo '<pre>' . print_r($ajax_result, true) . '</pre>';
} else {
echo '<p class="error">✗ AJAX 返回不是有效 JSON: ' . json_last_error_msg() . '</p>';
}

View File

@@ -1,164 +0,0 @@
<?php
/**
* 测试 API 测试功能
* 访问: http://your-site.com/wp-content/themes/argon/test-api-test-function.php
*/
require_once('../../../wp-load.php');
if (!current_user_can('manage_options')) {
wp_die('权限不足');
}
echo '<h1>API 测试功能诊断</h1>';
// 1. 检查函数是否存在
echo '<h2>1. 函数存在性检查</h2>';
$functions = [
'argon_ajax_test_unified_api',
'argon_get_api_by_id',
'argon_get_all_apis'
];
foreach ($functions as $func) {
if (function_exists($func)) {
echo '<p style="color: green;">✓ ' . $func . ' 存在</p>';
} else {
echo '<p style="color: red;">✗ ' . $func . ' 不存在</p>';
}
}
// 2. 检查是否有 API 配置
echo '<h2>2. API 配置检查</h2>';
$all_apis = argon_get_all_apis();
if (empty($all_apis)) {
echo '<p style="color: orange;">⚠ 没有配置任何 API</p>';
} else {
echo '<p style="color: green;">✓ 已配置 ' . count($all_apis) . ' 个 API</p>';
foreach ($all_apis as $api) {
echo '<div style="margin: 10px 0; padding: 10px; background: #f5f5f5; border-left: 4px solid #5e72e4;">';
echo '<strong>' . esc_html($api['name']) . '</strong><br>';
echo 'ID: ' . esc_html($api['id']) . '<br>';
echo '提供商: ' . esc_html($api['provider']) . '<br>';
echo '模型: ' . esc_html($api['model']) . '<br>';
echo '</div>';
}
}
// 3. 检查 AJAX action 是否注册
echo '<h2>3. AJAX Action 注册检查</h2>';
global $wp_filter;
if (isset($wp_filter['wp_ajax_argon_ajax_test_unified_api'])) {
echo '<p style="color: green;">✓ wp_ajax_argon_ajax_test_unified_api 已注册</p>';
} else {
echo '<p style="color: red;">✗ wp_ajax_argon_ajax_test_unified_api 未注册</p>';
}
// 4. 测试 nonce 生成
echo '<h2>4. Nonce 生成测试</h2>';
$nonce = wp_create_nonce('argon_test_unified_api');
echo '<p>生成的 nonce: <code>' . $nonce . '</code></p>';
echo '<p>验证结果: ';
if (wp_verify_nonce($nonce, 'argon_test_unified_api')) {
echo '<span style="color: green;">✓ 验证通过</span></p>';
} else {
echo '<span style="color: red;">✗ 验证失败</span></p>';
}
// 5. 模拟 AJAX 请求测试
if (!empty($all_apis)) {
echo '<h2>5. 模拟 AJAX 请求测试</h2>';
$test_api = $all_apis[0];
echo '<p>测试 API: ' . esc_html($test_api['name']) . '</p>';
// 模拟 $_POST 数据
$_POST['api_id'] = $test_api['id'];
$_POST['nonce'] = wp_create_nonce('argon_test_unified_api');
echo '<p>开始测试...</p>';
// 获取 API 配置
$api = argon_get_api_by_id($test_api['id']);
if (!$api) {
echo '<p style="color: red;">✗ 无法获取 API 配置</p>';
} else {
echo '<p style="color: green;">✓ 成功获取 API 配置</p>';
// 获取默认端点
$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 '<p>API 端点: <code>' . esc_html($api_endpoint) . '</code></p>';
echo '<p>模型: <code>' . esc_html($model) . '</code></p>';
// 构建测试请求
$data = [
'model' => $model,
'messages' => [
[
'role' => 'user',
'content' => '你好,这是一个测试。请回复"测试成功"。'
]
],
'max_tokens' => 50
];
echo '<p>发送测试请求...</p>';
$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 '<p style="color: red;">✗ 请求失败: ' . $response->get_error_message() . '</p>';
} else {
$status_code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
echo '<p>HTTP 状态码: <code>' . $status_code . '</code></p>';
echo '<p>响应时间: <code>' . $response_time . 'ms</code></p>';
if ($status_code === 200) {
$result = json_decode($body, true);
if (isset($result['choices'][0]['message']['content']) || isset($result['content'])) {
echo '<p style="color: green;">✓ API 测试成功!</p>';
if (isset($result['choices'][0]['message']['content'])) {
echo '<p>AI 回复: ' . esc_html($result['choices'][0]['message']['content']) . '</p>';
}
} else {
echo '<p style="color: red;">✗ API 返回格式异常</p>';
echo '<pre>' . htmlspecialchars($body) . '</pre>';
}
} else {
echo '<p style="color: red;">✗ API 返回错误</p>';
echo '<pre>' . htmlspecialchars($body) . '</pre>';
}
}
}
}
echo '<hr>';
echo '<h2>测试完成</h2>';
echo '<p><a href="' . admin_url('themes.php?page=argon-theme-options') . '">返回设置页</a></p>';
?>

View File

@@ -1,152 +0,0 @@
<?php
/**
* 小米 Mimo API 测试脚本
* 用于诊断 API 请求失败的问题
*/
// 加载 WordPress
require_once('../../wp-load.php');
// 测试配置
$test_api_key = 'YOUR_API_KEY_HERE'; // 替换为实际的 API 密钥
$test_endpoint = 'https://api.mimo.xiaomi.com/v1/chat/completions';
$test_model = 'MiMo-V2-Flash';
echo "<h2>小米 Mimo API 测试</h2>\n";
echo "<pre>\n";
// 测试 1: 基本请求
echo "=== 测试 1: 基本 API 请求 ===\n";
$data = [
'model' => $test_model,
'messages' => [
['role' => 'system', 'content' => '你是一个有帮助的助手。'],
['role' => 'user', 'content' => '你好,请用一句话介绍你自己。']
],
'temperature' => 0.7,
'max_tokens' => 100
];
echo "请求端点: $test_endpoint\n";
echo "模型: $test_model\n";
echo "请求数据:\n";
echo json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
$response = wp_remote_post($test_endpoint, [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $test_api_key
],
'body' => json_encode($data),
'timeout' => 30
]);
if (is_wp_error($response)) {
echo "❌ 请求失败: " . $response->get_error_message() . "\n";
} else {
$status_code = wp_remote_retrieve_response_code($response);
$body = wp_remote_retrieve_body($response);
$headers = wp_remote_retrieve_headers($response);
echo "状态码: $status_code\n";
echo "响应头:\n";
foreach ($headers as $key => $value) {
echo " $key: $value\n";
}
echo "\n响应体:\n";
$json_body = json_decode($body, true);
if ($json_body) {
echo json_encode($json_body, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
} else {
echo $body . "\n";
}
}
echo "\n";
// 测试 2: 不同的请求格式
echo "=== 测试 2: 简化的请求格式 ===\n";
$data2 = [
'model' => $test_model,
'messages' => [
['role' => 'user', 'content' => '你好']
]
];
echo "请求数据:\n";
echo json_encode($data2, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n\n";
$response2 = wp_remote_post($test_endpoint, [
'headers' => [
'Content-Type' => 'application/json',
'Authorization' => 'Bearer ' . $test_api_key
],
'body' => json_encode($data2),
'timeout' => 30
]);
if (is_wp_error($response2)) {
echo "❌ 请求失败: " . $response2->get_error_message() . "\n";
} else {
$status_code2 = wp_remote_retrieve_response_code($response2);
$body2 = wp_remote_retrieve_body($response2);
echo "状态码: $status_code2\n";
echo "响应体:\n";
$json_body2 = json_decode($body2, true);
if ($json_body2) {
echo json_encode($json_body2, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
} else {
echo $body2 . "\n";
}
}
echo "\n";
// 测试 3: 获取模型列表
echo "=== 测试 3: 获取模型列表 ===\n";
$models_endpoint = 'https://api.mimo.xiaomi.com/v1/models';
echo "请求端点: $models_endpoint\n\n";
$response3 = wp_remote_get($models_endpoint, [
'headers' => [
'Authorization' => 'Bearer ' . $test_api_key
],
'timeout' => 30
]);
if (is_wp_error($response3)) {
echo "❌ 请求失败: " . $response3->get_error_message() . "\n";
} else {
$status_code3 = wp_remote_retrieve_response_code($response3);
$body3 = wp_remote_retrieve_body($response3);
echo "状态码: $status_code3\n";
echo "响应体:\n";
$json_body3 = json_decode($body3, true);
if ($json_body3) {
echo json_encode($json_body3, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE) . "\n";
} else {
echo $body3 . "\n";
}
}
echo "\n";
// 测试 4: 使用 cURL 直接测试
echo "=== 测试 4: cURL 命令示例 ===\n";
echo "你可以在命令行中运行以下命令来测试 API:\n\n";
echo "curl -X POST https://api.mimo.xiaomi.com/v1/chat/completions \\\n";
echo " -H \"Content-Type: application/json\" \\\n";
echo " -H \"Authorization: Bearer YOUR_API_KEY\" \\\n";
echo " -d '{\n";
echo " \"model\": \"MiMo-V2-Flash\",\n";
echo " \"messages\": [\n";
echo " {\"role\": \"user\", \"content\": \"你好\"}\n";
echo " ]\n";
echo " }'\n";
echo "</pre>\n";