首页 > Windows开发 > 详细

搜狗翻译 API nodejs

时间:2021-01-29 10:38:23      阅读:25      评论:0      收藏:0      [点我收藏+]
var md5 = require(‘md5‘);
const axios = require(‘axios‘);

function api(query, source_langauge, target_language) {
  var url = "http://fanyi.sogou.com:80/reventondc/api/sogouTranslate"

  let pid = ‘自己填‘
  let key = ‘自己填‘

  var salt = Math.floor(Date.now() / 1000);
  var q = query
  var sign = md5(pid + q + salt + key)
  var from = source_langauge
  var to = target_language
  var payload = "from=" + from + "&to=" + to + "&pid=" + pid + "&q=" + encodeURIComponent(q) + "&sign=" + sign + "&salt=" + salt

  return axios({
    method: ‘post‘,
    url,
    timeout: 5000,
    headers: {
      ‘Accept‘: ‘application/json‘,
      ‘Content-Type‘: ‘application/x-www-form-urlencoded;charset=UTF-8‘,
      "Cache-Control": "no-cache", // 避免 Chrome 把请求 Stalled 20 秒
    },
    data: payload
  }).then(response => {
    return response.data
  })
}

exports.api = api

搜狗翻译 API nodejs

原文:https://www.cnblogs.com/wlor/p/14343230.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!