机器翻译API
接口描述
机器翻译接口。
请求说明
URL
https://openapi.sys303.com/api/cognitive/translation
参数
Header参数
| 参数 | 值 |
|---|---|
| Content-Type | application/json |
| X-Secret | 点击获取 |
Body参数
| 参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
|---|---|---|---|---|
| sourceLang | 是 | int | [0, 1] | 待翻译语言类型 【0:藏文,1:中文】 |
| destLang | 是 | int | [0, 1] | 目标翻译语言类型 【0:藏文,1:中文】 |
| inputText | 是 | string | - | 待翻译文字【unicode 长度3000字以内】 |
请求样例
- bash
- python
- C#
- Java
curl --request POST \
--url https://openapi.sys303.com/api/cognitive/translation \
--header 'Content-Type: application/json' \
--header 'X-Secret: {X-Secret}' \
--data '{
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}'
import requests
url = "https://openapi.sys303.com/api/cognitive/translation"
headers = {
"Content-Type": "application/json",
"X-Secret": "你的X-Secret"
}
data = {
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.text)
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var url = "https://openapi.sys303.com/api/cognitive/translation";
var secret = "你的X-Secret";
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("X-Secret", secret);
var json = """
{
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}
""";
var content = new StringContent(
json,
Encoding.UTF8,
"application/json"
);
var response = await client.PostAsync(url, content);
var result = await response.Content.ReadAsStringAsync();
Console.WriteLine($"Status: {response.StatusCode}");
Console.WriteLine(result);
}
}
import okhttp3.*;
import java.io.IOException;
public class TranslationDemo {
public static void main(String[] args) throws IOException {
String url = "https://openapi.sys303.com/api/cognitive/translation";
String secret = "你的X-Secret";
OkHttpClient client = new OkHttpClient();
String json = """
{
"sourceLang": 1,
"destLang": 0,
"inputText": "你好"
}
""";
RequestBody body = RequestBody.create(
json,
MediaType.parse("application/json")
);
Request request = new Request.Builder()
.url(url)
.addHeader("Content-Type", "application/json")
.addHeader("X-Secret", secret)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
System.out.println("Status: " + response.code());
System.out.println(response.body().string());
}
}
}
返回说明
参数说明
| 字段 | 是否必选 | 类型 | 状态 | 说明 |
|---|---|---|---|---|
| traceId | 是 | String | - | 唯一的traceId,用于问题定位 |
| msgId | 是 | String | - | 业务状态码 |
| msg | 是 | String | 错误描述 | |
| data | 是 | String | - | 翻译结果 |
返回样例
成功
{
"traceId": "0HNL06O44AV58:00000001",
"msgId": "2000000",
"msg": "success",
"data": "ཁྱོད་བདེ་མོ།"
}
失败
认证失败:
{
"traceId": "0HNLN3J9DCJSE:00000001",
"msgId": "4011001",
"msg": "AuthFailed",
"data": null
}
传入参数错误:
{
"traceId": "0HNL06O44AUV9:00000001",
"msgId": "500",
"msg": "Specified argument was out of the range of valid values. (Parameter 'source') Actual value was BoAll.",
"data": null
}
字符长度超长:
{
"traceId": "0HNL06O44AUVB:00000001",
"msgId": "4004002",
"msg": "InputTooLong",
"data": null
}
翻译字符数不足:
{
"traceId": "0HNL06O44AUO9:00000001",
"msgId": "2001001",
"msg": "InsufficientInventory",
"data": null
}