The use of the new version of Baidu translation api, java, android

I believe that the students who read this article also encountered the same problem as me. The new version of Baidu Translate API is not well debugged, and the Chinese translation to English always returns 54001. Then this article can solve your problem. The following is an example of Chinese translation to English.

  • Example: Translate "Apple" from Chinese to English:
    Request parameter:
    q="Apple"
    from=zh
    to=en
    appid=2015063000000001
    salt=1435660288Key
    distributed by the platform: 12345678

  • Generate sign:
    concatenate string 1 Make
    sure the text q to be translated is UTF-8 encoded.
    new String(q.getBytes(),"utf-8")
    Splicing strings: String str=appId+new String(q.getBytes(),"utf-8")+salt+token;
    generate MD5: String sign= MD5Encoder.encode(str.toString());
    note that after MD5, you will get a 32-bit lowercase sign, not uppercase or 16-bit

  • Before sending a request, you must URL encode q before
    splicing request.
    URLEncoder.encode(q,"utf-8")

Please go to the following link to download the demo:
https://github.com/viceqiu/BaiDuTranslate/tree/master

Guess you like

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