-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
搜索接口失效问题解决方案 #168
Comments
搜索接口失效问题解决方案搜索类型:默认为 0 // 0:单曲,1:歌手,2:专辑,3:歌单,7:歌词 module.exports = {
'/': async ({req, res, request, globalCookie, cache}) => {
const obj = {...req.query, ...req.body};
let { uin, qqmusic_key } = globalCookie.userCookie();
if (Number(obj.ownCookie)) {
uin = req.cookies.uin || uin;
}
const {
pageNo = 1,
pageSize = 20,
key,
t = 0, // 0:单曲,2:歌单,7:歌词,8:专辑,9:歌手,12:mv
raw
} = req.query;
let total = 0;
if (!key) {
return res.send({
result: 500,
errMsg: '关键词不能为空',
});
}
// 缓存
const cacheKey = `search_${key}_${pageNo}_${pageSize}_${t}`;
const cacheData = cache.get(cacheKey);
if (cacheData) {
res && res.send(cacheData);
return cacheData;
}
const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'
const typeMap = {
0: 'song',
2: 'album',
1: 'singer',
3: 'songlist',
7: 'lyric',
12: 'mv',
};
if (!typeMap[t]) {
return res.send({
result: 500,
errMsg: '搜索类型错误,检查一下参数 t',
});
}
const params = {
req_1: {
method: "DoSearchForQQMusicDesktop",
module: "music.search.SearchCgiService",
param: {
num_per_page: Number(pageSize),
page_num: Number(pageNo),
query: key,
search_type: Number(t)
}
}
}
let result = {}
try {
result = await request({
url,
method: 'POST',
data: params,
headers: {
Referer: 'https://y.qq.com'
},
});
} catch (error) {
return res.send({
result: 400,
error
})
}
// 直接返回原生数据
if (Number(raw)) {
return res.send(result);
}
const response = {
result: 100,
data: {
list: Number(t) === 0 ? formatSongList(result.req_1.data.body[typeMap[t]].list) : result.req_1.data.body[typeMap[t]].list,
pageNo,
pageSize,
total: result.req_1.data.meta.sum,
key: result.req_1.data.meta.query || key,
t,
type: typeMap[t],
},
}
res.send(response);
},
// 热搜词
'/hot': async ({req, res, request}) => {
const {raw} = req.query;
const result = await request({
url: 'https://c.y.qq.com/splcloud/fcgi-bin/gethotkey.fcg',
});
if (Number(raw)) {
return res.send(result);
}
res.send({
result: 100,
data: result.data.hotkey,
});
},
// 快速搜索
'/quick': async ({req, res, request}) => {
const {raw, key} = req.query;
if (!key) {
return res.send({
result: 500,
errMsg: 'key ?',
});
}
const result = await request(
`https://c.y.qq.com/splcloud/fcgi-bin/smartbox_new.fcg?key=${key}&g_tk=5381`,
);
if (Number(raw)) {
return res.send(result);
}
return res.send({
result: 100,
data: result.data,
});
},
}
function formatSongList(list) {
if (!Array.isArray(list)) {
return []
}
return list.map((item) => {
// 美化歌曲数据
return {
singer: item.singer, // 、
name: item.title,
songid: item.id,
songmid: item.mid,
songname: item.title,
albumid: item.album.id,
albummid: item.album.mid,
albumname: item.album.name,
interval: item.interval,
strMediaMid: item.file.media_mid,
size128: item.file.size_128mp3,
size320: item.file.size_320mp3,
sizeape: item.file.size_ape,
sizeflac: item.file.size_flac,
pay: item.pay || {}
}
})
} |
报404阿 |
|
|
额 不是覆盖代码就行了吗,不是搞nodejs的不知道咋判断.... |
|
那就奇怪了.我直接把\routes文件夹下的search.js里面的代码直接覆盖成了上面发的,就一直报404错误了 |
其他的接口能调用?检查一下代码复制完整没有,改完了重启服务。 |
我把服务器重启了下 好了,难道是缓存? 昨天项目重启了好几次都不行 真尴尬 |
你好,替换后,搜索类型为7,对应歌词,会直接崩溃;搜索类型12,对应MV,搜出来的数据为空,应该如何解决呢 |
有用 |
没有用过歌词和mv搜索,可以抓包看看对应类型的传参是否有变化 |
谢谢你,人间尤物🌹 |
No description provided.
The text was updated successfully, but these errors were encountered: