-
Notifications
You must be signed in to change notification settings - Fork 11
/
youdaoAPI.js
70 lines (60 loc) · 1.97 KB
/
youdaoAPI.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var request = require('request');
var crypto = require('crypto');
var $ = require('jquery');
let text = "hello";
// MD5算法
var md5 = crypto.createHash('md5');
// 先获取salt和sign参数
let salt = "" + ((new Date).getTime() + parseInt(10 * Math.random(), 10));
// let str = "fanyideskweb" + text + salt + "rY0D^0'nM0}g5Mm1z%1G4";
let str = "fanyideskweb" + "hello" + "1507817910839" + "rY0D^0'nM0}g5Mm1z%1G4";
let sign = md5.update(str).digest('hex');
console.log(sign);
var e = {"action":"FY_BY_CLICKBUTTION",
"client":"fanyideskweb",
"doctype":"json",
"from":"AUTO",
"i":"hello",
"keyfrom":"fanyi.web",
"salt":"1507884640456",
"sign":"4b324e531753f05f39fe718e28df61a7",
"smartresult":"dict",
"to":"AUTO",
"typoResult":true,
"version":"2.1"
};
let youdaoUrl = "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule";
$.ajax({
type: "POST",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
url: "http://fanyi.youdao.com/translate_o?smartresult=dict&smartresult=rule",
data: e,
dataType: "json",
success: function (e) {
console.log(e);
},
error: function (e) {
console.log(e);
}
});
// request.post(youdaoUrl, {
// form: {
// i: text, from: "AUTO", to: "AUTO", smartresult: "dict"
// , client: "fanyideskweb", salt: salt, sign: sign, doctype: "json", version: "2.1", keyfrom: "fanyi.web", action: "FY_BY_CLICKBUTTION", typoResult: "true"
// }
// }, function (e, r, body) {
// // console.log(r);
// console.log(body);
// // if (body.trim() != "") {
// // let result = JSON.parse(body.trim());
// // let smartResult = result.smartResult;
// // if (smartResult) {
// // let texts = smartResult.entries;
// // let jointexts = texts.join(";\n");
// // resolve(jointexts);
// // } else {
// // let text = result.translateResult[0][0].tgt;
// // resolve(text);
// // }
// // }
// });