-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyapiserver.js
96 lines (74 loc) · 2.3 KB
/
myapiserver.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const express = require('express')
const axios = require('axios')
const app = express()
// const history = require("connect-history-api-fallback");
const headers = {
referer: 'https://y.qq.com/',
origin: 'https://y.qq.com/',
'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'
}
const getSecuritySign = require("./src/api/sign");
const commonParams = {
g_tk: 5381,
loginUin: 0,
hostUin: 0,
inCharset: "utf8",
outCharset: "utf-8",
notice: 0,
needNewCode: 0,
format: "json",
platform: "yqq.json",
};
app.get('/api/getSingerDetail', function (req, res) {
console.log("getSingerDetail服务端路由匹配到了!")
console.log("请求参数是==》", req.query)
const data = JSON.stringify({
comm: { ct: 24, cv: 0 },
singerSongList: {
method: "GetSingerSongList",
param: { order: 1, singerMid: req.query.id, begin: 0, num: 100 },
module: "musichall.song_list_server",
},
});
const randomKey = getRandomVal("getSingerSong");
const sign = getSecuritySign(data);
const url = 'https://u.y.qq.com/cgi-bin/musics.fcg'
axios.get(url, {
headers,
params: Object.assign({}, commonParams, {
sign,
"-": randomKey,
data,
})
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
// 获取一个随机数值
function getRandomVal(prefix = "") {
return prefix + (Math.random() + "").replace("0.", "");
}
// app.use(history())
const port = 3800
const portfinder = require("portfinder");
module.exports = (() => {
portfinder.basePort = port
portfinder.getPort((err, newport) => {
if (err) {
return;
}
app.listen(newport, error => {
if (error) {
console.log(error);
return;
}
if (newport !== port) {
console.log(`预定端口${port}被占用!`);
console.log(`分配新端口${newport},Listening on http://localhost:${newport}\n`);
}
console.log(`${newport}端口可用,Listening on http://localhost:${newport}\n`);
});
});
})();