-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshare.js
More file actions
28 lines (22 loc) · 711 Bytes
/
share.js
File metadata and controls
28 lines (22 loc) · 711 Bytes
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
const crypto = require('crypto');
const axios = require('axios');
function md5(str) {
return crypto.createHash('md5').update(str).digest('hex');
}
function sha256(str) {
return crypto.createHash('sha256').update(str).digest('hex');
}
function truncate(q) {
const len = q.length;
if (len <= 20) return q;
return q.substring(0, 10) + len + q.substring(len - 10, len);
}
exports.baiduSign = function (appid, key, query, salt) {
return md5(`${appid}${query}${salt}${key}`);
}
exports.youdaoSign = function (appKey, secKey, query, salt, curtime) {
return sha256(`${appKey}${truncate(query)}${salt}${curtime}${secKey}`);
}
exports.post = function (api, param) {
return axios.post(api, param);
}