75 lines
1.9 KiB
Lua
Raw Normal View History

2023-03-09 19:42:41 +08:00
local M = {}
2023-03-09 19:42:41 +08:00
local baidu = require('Trans').conf.engine.baidu
local appid = baidu.appid
local app_passwd = baidu.app_passwd
local salt = tostring(math.random(bit.lshift(1, 15)))
local uri = 'https://fanyi-api.baidu.com/api/trans/vip/translate'
2023-03-09 19:42:41 +08:00
M.request_headers = function(data)
local tmp = appid .. data.str .. salt .. app_passwd
local sign = require('Trans.util.md5').sumhexa(tmp)
return {
2023-03-09 19:42:41 +08:00
q = data.str,
from = data.from,
to = data.to,
appid = appid,
salt = salt,
sign = sign,
}
end
2023-03-09 19:42:41 +08:00
M.query = function(data)
data.engine = 'baidu'
require('Trans.wrapper.curl').POST {
}
end
2023-02-07 16:44:22 +08:00
2023-03-09 19:42:41 +08:00
return M
-- local post = require('Trans.util.curl').POST
-- ---返回一个channel
-- ---@param word string
-- ---@return table
-- return function(word)
-- local isEn = word:isEn()
-- local query = get_field(word, isEn)
-- local result = {}
-- post(uri, {
-- data = query,
-- headers = {
-- content_type = "application/x-www-form-urlencoded",
-- },
-- callback = function(str)
-- local ok, res = pcall(vim.json.decode, str)
-- if ok and res and res.trans_result then
-- result[1] = {
-- title = { word = word },
-- [isEn and 'translation' or 'definition'] = res.trans_result[1].dst,
-- }
-- if result.callback then
-- result.callback(result[1])
-- end
-- else
-- result[1] = false
-- end
-- end,
-- })
-- return result
-- end
2023-02-07 16:44:22 +08:00
2023-03-09 19:42:41 +08:00
-- -- NOTE :free tts:
-- -- https://zj.v.api.aa1.cn/api/baidu-01/?msg=我爱你&choose=0&su=100&yd=5
-- -- 选择转音频的人物女生1 输入0 女生2输入5男生1 输入1男生2 输入2男生3 输入3