next-fanyi-api-sign
Get baidu translate api sign.
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
- appid=2015063000000001
- q=apple
- salt=1435660288
- 密钥=12345678
- 得到字符串1:“2015063000000001apple143566028812345678”
- 计算签名:(对字符串1做md5加密)
- sign=md5(2015063000000001apple143566028812345678)
- sign=f89f9594663708c1605f3d736d01d2d4
resources
license
Code released under the MIT license.