<?php
/**
 * AI API 测试脚本
 */

header('Content-Type: text/plain; charset=utf-8');

echo "========== AI API 测试 ==========\n\n";

// 测试硅基流动
echo "[1] 测试硅基流动 API...\n";
echo "URL: https://api.siliconflow.cn/v1/chat/completions\n";

$SILICONFLOW_API_KEY = 'sk-bcczdchfdqzvrdcaozkubiypsmgathqotfsdgjshowosyumg';
$message = "你好";

$data = [
    'model' => 'deepseek-ai/DeepSeek-V4-Flash',
    'messages' => [
        ['role' => 'user', 'content' => $message]
    ],
    'temperature' => 0.7,
    'max_tokens' => 2048
];

$ch = curl_init('https://api.siliconflow.cn/v1/chat/completions');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode($data),
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $SILICONFLOW_API_KEY
    ]
]);

echo "发送请求...\n";
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($response === false) {
    echo "错误: $error\n";
} else {
    echo "HTTP状态码: $httpCode\n";
    echo "响应: $response\n";
}

echo "\n";

// 测试豆包
echo "[2] 测试豆包 API...\n";
echo "URL: https://ark.cn-beijing.volces.com/api/v3/chat/completions\n";

$DOUBAO_API_KEY = 'ark-2383016b-22c3-48a8-9613-f9e437f6b624-8c249';
$DOUBAO_ENDPOINT_ID = 'ep-20260615150332-wcskh';

$data = [
    'model' => $DOUBAO_ENDPOINT_ID,
    'messages' => [
        ['role' => 'user', 'content' => $message]
    ],
    'temperature' => 0.7,
    'max_tokens' => 2048
];

$ch = curl_init('https://ark.cn-beijing.volces.com/api/v3/chat/completions');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_SSL_VERIFYPEER => false,
    CURLOPT_SSL_VERIFYHOST => false,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode($data),
    CURLOPT_HTTPHEADER => [
        'Content-Type: application/json',
        'Authorization: Bearer ' . $DOUBAO_API_KEY
    ]
]);

echo "发送请求...\n";
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$error = curl_error($ch);
curl_close($ch);

if ($response === false) {
    echo "错误: $error\n";
} else {
    echo "HTTP状态码: $httpCode\n";
    echo "响应: $response\n";
}

echo "\n========== 测试完成 ==========\n";
