开发者 API

用几行代码把翻译能力接入你的产品。

接口地址

POSThttps://你的域名/api/translate.php

Content-Type: application/json

请求参数

字段类型必填说明
textstring是待翻译文本,最长 5000 字
fromstring否源语言:auto / zh / en / ja / ko / fr / de / es / ru,默认 auto
tostring是目标语言:zh / en / ja / ko / fr / de / es / ru

返回:{ "result": "译文" };失败时返回 { "error": "原因" }。

cURL 示例

curl -X POST https://你的域名/api/translate.php \
  -H "Content-Type: application/json" \
  -d '{"text": "你好,世界", "from": "auto", "to": "en"}'

PHP 示例

$ch = curl_init('https://你的域名/api/translate.php');
curl_setopt_array($ch, [
    CURLOPT_POST => true,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
    CURLOPT_POSTFIELDS => json_encode([
        'text' => '你好,世界',
        'from' => 'auto',
        'to'   => 'en',
    ], JSON_UNESCAPED_UNICODE),
]);
$result = json_decode(curl_exec($ch), true);
echo $result['result'] ?? $result['error'];

JavaScript 示例

fetch('https://你的域名/api/translate.php', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ text: '你好,世界', from: 'auto', to: 'en' })
})
.then(r => r.json())
.then(d => console.log(d.result));

频率限制

接口按客户端 IP 限流(与全站聊天接口共用阈值,可在后台调整)。请勿并发轰炸,长文请分段发送。