简体与繁体转换
目录
接口使用
我要查询
提示:请在下面的 Demo 中输入您要转换的文字,点击查询即可。
简体与繁体转换
查询说明
支持简体中文与繁体中文互转,转换结果为 GBK/繁体(Big5)字库对应文本。
接口描述
功能描述
接口一:简体中文转繁体中文
将简体中文转换为繁体中文,数据模块为 getCnToBig5。
接口二:繁体中文转简体中文
将繁体中文转换为简体中文,数据模块为 getBig5ToCn。
URL 示例
1)http 协议,POST 方式:
http://cha.ebaitian.cn/api/json?appid=xxx&module=getCnToBig5&words=xxx&sign=xxx
2)https 协议,POST 方式:
https://cha.ebaitian.cn/api/json?appid=xxx&module=getCnToBig5&words=xxx&sign=xxx
请求参数
数据包体
{
"type": "get",
"appid": "1000xxxx",
"module": "getCnToBig5",
"words": "我要查",
"sign": "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4"
}
参数说明
| 参数 | 必选 | 类型 | 描述 |
|---|---|---|---|
| type | 否 | string | 授权接口的请求方式 |
| appid | 是 | string | 授权接口的 AppID |
| module | 是 | string | 目标请求的数据模块:简体转繁体为 getCnToBig5;繁体转简体为 getBig5ToCn |
| words | 是 | string | 目标要转换的中文文字 |
| sign | 是 | string | 请求凭证,具体计算方式见下面的其他说明 |
其他说明
1)type:可选值 get,如果赋值 get,则以 get 方式提交数据;默认以 post 方式提交数据;
2)sign:签名校验,根据公式 $sign=sha256(appid=$appid&module=getCnToBig5&words=$words&appkey=$appkey) 生成;繁体转简体请将 module 替换为 getBig5ToCn 后计算。
响应参数
数据包体
{
"result":1,
"description":"TRUE",
"flag":"",
"words":{
"cn":"我要查",
"big5":"我要查"
}
}
参数说明
| 参数 | 必选 | 类型 | 描述 |
|---|---|---|---|
| result | 是 | string | 接口响应结果:0-失败;1-成功 |
| description | 是 | string | 接口响应描述:一般为 TURE(result=1) 与 FALSE(result=0) |
| flag | 否 | string | 错误说明,没有错误则返回空 |
| words | 是 | object | 转换结果,包含 cn(简体)与 big5(繁体)两个字段 |
SDK 及代码示例
PHP SDK
以 POST 方式请求数据:
//接口参数
$api_url='http://cha.ebaitian.cn/api/json';
$api_appid='1000xxxx';
$api_appkey='56cf61af4b7897e704f67deb88ae8f24';
//函数:简体转繁体
function getCnToBig5($words){
global $api_url,$api_appid,$api_appkey;
$data='appid='.$api_appid.'&module=getCnToBig5&words='.$words;
$sign=hash("sha256",$data.'&appkey='.$api_appkey);
$postdata=array("appid"=>$api_appid,"appkey"=>$api_appkey,"module"=>"getCnToBig5","words"=>$words,'sign'=>$sign);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$output = curl_exec($curl);
curl_close($curl);
$obj=json_decode($output);
if($obj->result==1){
return $obj->words->big5;
}else{
return $obj->flag;
}
}
//调用函数
echo getCnToBig5('我要查');
exit;
其他语言 SDK
Java / Python / Node.js / C# / JavaScript / ASP 等语言的调用方式与「手机号码查询」一致,仅需将参数 module 替换为 getCnToBig5(或 getBig5ToCn)、mobile 替换为 words 即可,返回结构为 words。
常见问题
API 接口参数为空
此错误返回 JSON 数据如下:
{
"result":0,
"description":"API接口参数为空",
"flag":"appid:sign"
}
解决方法:
1)请检查 appid 及 sign 是否为空;
2)确保 appid 是从官网获取到正确的接口授权;
3)确保 sign 计算生成是正确的。
API 接口参数无效
此错误返回 JSON 数据如下:
{
"result":0,
"description":"API接口参数无效",
"flag":"appid"
}
解决方法:
1)请检查 appid 是否正确;
2)确保 appid 是从官网获取到正确的接口授权。
API 接口授权已到期
此错误返回 JSON 数据如下:
{
"result":0,
"description":"API接口授权已到期",
"flag":"end:2018-12-31 23:59:59"
}
解决方法:
1)请检查 appid 对应接口授权的期限是否过期;
2)如果接口授权过期,请到官网更新(免费用户直接更新,无需续费)或续费(针对商业付费用户)。
签名错误
此错误返回 JSON 数据如下:
{
"result":0,
"description":"签名错误",
"flag":"getCnToBig5->sign"
}
解决方法:
1)请检查 sign 签名计算是否正确;
2)签名 sign 根据公式 $sign=sha256(appid=$appid&module=getCnToBig5&words=$words&appkey=$appkey) 生成。
请求受限
此错误返回 JSON 数据如下:
{
"result":0,
"description":"请求受限",
"flag":"getCnToBig5->daylimit"
}
解决方法:
1)授权接口已超出当前接口产品请求的最大限制;
2)请根据实际使用需求升级您的接口产品。
其他问题
如果您遇到其他的问题,请用以下方式联系我们,我们将为您提供 API 技术对接帮助。
请直接添加 QQ 技术交流群寻求我们帮助。
我要查API技术对接群①:
群号:821884327
扫码加入我要查API技术对接群①: