Simple call of Baidu Translate API

Translate API HTTP address

http://api.fanyi.baidu.com/api/trans/vip/translate

You need to send the following fields to this address via POST or GET method to access the service

field name Types of Required parameters describe Remark
q TEXT AND request translation query UTF-8 encoding
from TEXT AND Translation source language Language list (can be set to auto)
to TEXT AND target language Language list (cannot be set to auto)
appid INT AND APP ID Can be viewed in the admin console
salt INT AND random number
sign TEXT AND sign appid+q+salt+MD5 value of key
The returned result is in json format and contains the following fields

field name Types of describe
from TEXT Translation source language
to TEXT target language
trans_result MIXED LIST translation result
src TEXT original
dst TEXT translation

generate sign

>concatenated string 1

Splicing appid=2015063000000001 + q=apple + salt=1435660288 + key=12345678

get string 1 = 2015063000000001 apple 1435660288 12345678

>Calculate signature sign (encrypt string 1 with md5, note that string 1 must be UTF-8 encoded before calculating md5)


The above is the calling parameters and format

This is the url request I wrote

http://api.fanyi.baidu.com/api/trans/vip/translate?q=apple&from=auto&to=zh&appid=20160413000018571&salt=1435660288&sign=39c436658c2f20730931b5139094c0a7

This is the return content json (I finally know what this format is called)

{"from":"en","to":"zh","trans_result":[{"src":"apple","dst":"\u82f9\u679c"}]}
\u82f9\u679c is unicode encoding to convert Chinese to apple
API Documentation http://api.fanyi.baidu.com/api/trans/product/apidoc


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325412946&siteId=291194637