@jswork/next-fanyi-api-sign

1.0.2 • Public • Published

next-fanyi-api-sign

Get baidu translate api sign.

version license size download

installation

npm install -S @jswork/next-fanyi-api-sign

usage

const options = { q: 'pear' };
const res = nx.fanyiApiSign(options);
const url = `http://api.fanyi.baidu.com/api/trans/vip/translate?from=en&to=zh&${nx.param(res)}`;

fetch(url)
  .then((response) => response.json())
  .then((response) => {
    expect(response).toEqual({
      from: 'en',
      to: 'zh',
      trans_result: [{ src: 'pear', dst: '梨' }]
    });
  });

descriptions

  1. 拼接字符串1
    1. appid=2015063000000001
    2. q=apple
    3. salt=1435660288
    4. 密钥=12345678
    5. 得到字符串1:“2015063000000001apple143566028812345678”
  2. 计算签名:(对字符串1做md5加密)
    1. sign=md5(2015063000000001apple143566028812345678)
    2. sign=f89f9594663708c1605f3d736d01d2d4

resources

license

Code released under the MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i @jswork/next-fanyi-api-sign

Homepage

js.work

Weekly Downloads

3

Version

1.0.2

License

MIT

Unpacked Size

6.19 kB

Total Files

6

Last publish

Collaborators

  • afeiship