Skip to content

Commit ba62ae2

Browse files
committed
修复 tx 偶现搜索失败的问题
1 parent e35895d commit ba62ae2

3 files changed

Lines changed: 107 additions & 57 deletions

File tree

src/renderer/utils/musicSdk/tx/musicSearch.js

Lines changed: 63 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { httpFetch } from '../../request'
21
import { formatPlayTime, sizeFormate } from '../../index'
32
import { formatSingerName } from '../utils'
3+
import { signRequest } from './utils'
44

55
export default {
66
limit: 50,
@@ -10,71 +10,77 @@ export default {
1010
successCode: 0,
1111
musicSearch(str, page, limit, retryNum = 0) {
1212
if (retryNum > 5) return Promise.reject(new Error('搜索失败'))
13-
// searchRequest = httpFetch(`https://c.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&new_json=1&remoteplace=sizer.yqq.song_next&searchid=49252838123499591&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=${page}&n=${limit}&w=${encodeURIComponent(str)}&loginUin=0&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq&needNewCode=0`)
14-
// const searchRequest = httpFetch(`https://shc.y.qq.com/soso/fcgi-bin/client_search_cp?ct=24&qqmusic_ver=1298&remoteplace=txt.yqq.top&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=${page}&n=${limit}&w=${encodeURIComponent(str)}&cv=4747474&ct=24&format=json&inCharset=utf-8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0&uin=0&hostUin=0&loginUin=0`)
15-
const searchRequest = httpFetch('https://u.y.qq.com/cgi-bin/musicu.fcg', {
16-
method: 'post',
17-
headers: {
18-
'User-Agent': 'QQMusic 14090508(android 12)',
13+
const searchRequest = signRequest({
14+
comm: {
15+
ct: '11',
16+
cv: '14090508',
17+
v: '14090508',
18+
tmeAppID: 'qqmusic',
19+
phonetype: 'EBG-AN10',
20+
deviceScore: '553.47',
21+
devicelevel: '50',
22+
newdevicelevel: '20',
23+
rom: 'HuaWei/EMOTION/EmotionUI_14.2.0',
24+
os_ver: '12',
25+
OpenUDID: '0',
26+
OpenUDID2: '0',
27+
QIMEI36: '0',
28+
udid: '0',
29+
chid: '0',
30+
aid: '0',
31+
oaid: '0',
32+
taid: '0',
33+
tid: '0',
34+
wid: '0',
35+
uid: '0',
36+
sid: '0',
37+
modeSwitch: '6',
38+
teenMode: '0',
39+
ui_mode: '2',
40+
nettype: '1020',
41+
v4ip: '',
1942
},
20-
body: {
21-
comm: {
22-
ct: '11',
23-
cv: '14090508',
24-
v: '14090508',
25-
tmeAppID: 'qqmusic',
26-
phonetype: 'EBG-AN10',
27-
deviceScore: '553.47',
28-
devicelevel: '50',
29-
newdevicelevel: '20',
30-
rom: 'HuaWei/EMOTION/EmotionUI_14.2.0',
31-
os_ver: '12',
32-
OpenUDID: '0',
33-
OpenUDID2: '0',
34-
QIMEI36: '0',
35-
udid: '0',
36-
chid: '0',
37-
aid: '0',
38-
oaid: '0',
39-
taid: '0',
40-
tid: '0',
41-
wid: '0',
42-
uid: '0',
43-
sid: '0',
44-
modeSwitch: '6',
45-
teenMode: '0',
46-
ui_mode: '2',
47-
nettype: '1020',
48-
v4ip: '',
49-
},
50-
req: {
51-
module: 'music.search.SearchCgiService',
52-
method: 'DoSearchForQQMusicMobile',
53-
param: {
54-
search_type: 0,
55-
query: str,
56-
page_num: page,
57-
num_per_page: limit,
58-
highlight: 0,
59-
nqc_flag: 0,
60-
multi_zhida: 0,
61-
cat: 2,
62-
grp: 1,
63-
sin: 0,
64-
sem: 0,
65-
},
43+
req: {
44+
module: 'music.search.SearchCgiService',
45+
method: 'DoSearchForQQMusicMobile',
46+
param: {
47+
search_type: 0,
48+
searchid: Math.random().toString().slice(2),
49+
query: str,
50+
page_num: page,
51+
num_per_page: limit,
52+
highlight: 0,
53+
nqc_flag: 0,
54+
multi_zhida: 0,
55+
cat: 2,
56+
grp: 1,
57+
sin: 0,
58+
sem: 0,
6659
},
6760
},
6861
})
69-
// searchRequest = httpFetch(`http://ioscdn.kugou.com/api/v3/search/song?keyword=${encodeURIComponent(str)}&page=${page}&pagesize=${this.limit}&showtype=10&plat=2&version=7910&tag=1&correct=1&privilege=1&sver=5`)
70-
return searchRequest.promise.then(({ body }) => {
62+
return searchRequest.then(({ body }) => {
7163
// console.log(body)
72-
if (body.code != this.successCode || body.req.code != this.successCode) return this.musicSearch(str, page, limit, ++retryNum)
64+
if (!body || !body.req || body.code != this.successCode || body.req.code != this.successCode) {
65+
return this.musicSearch(str, page, limit, ++retryNum)
66+
}
7367
return body.req.data
7468
})
7569
},
70+
// randomInt(min, max) {
71+
// return Math.floor(Math.random() * (max - min + 1)) + min
72+
// },
73+
// getSearchId() {
74+
// const e = BigInt(this.randomInt(1, 20))
75+
// const t = e * 18014398509481984n
76+
// const n = BigInt(this.randomInt(0, 4194304)) * 4294967296n
77+
// const a = BigInt(Date.now())
78+
// const r = (a * 1000n) % (24n * 60n * 60n * 1000n)
79+
// return String(t + n + r)
80+
// },
7681
handleResult(rawList) {
77-
console.log(rawList)
82+
// console.log(rawList)
83+
if (!rawList || !Array.isArray(rawList)) return []
7884
const list = []
7985
rawList.forEach(item => {
8086
if (!item.file?.media_mid) return
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import crypto from 'node:crypto'
2+
3+
const PART_1_INDEXES = [23, 14, 6, 36, 16, 40, 7, 19]
4+
const PART_2_INDEXES = [16, 1, 32, 12, 19, 27, 8, 5]
5+
const SCRAMBLE_VALUES = [89, 39, 179, 150, 218, 82, 58, 252, 177, 52, 186, 123, 120, 64, 242, 133, 143, 161, 121, 179]
6+
7+
async function hashSHA1(data) {
8+
return crypto.createHash('sha1').update(data).digest('hex')
9+
}
10+
11+
function pickHashByIdx(hash, indexes) {
12+
return indexes.map((idx) => hash[idx]).join('')
13+
}
14+
15+
function base64Encode(data) {
16+
return Buffer.from(data)
17+
.toString('base64')
18+
.replace(/[\\/+=]/g, '')
19+
}
20+
21+
export async function zzcSign(text) {
22+
const hash = await hashSHA1(text)
23+
const part1 = pickHashByIdx(hash, PART_1_INDEXES)
24+
const part2 = pickHashByIdx(hash, PART_2_INDEXES)
25+
const part3 = SCRAMBLE_VALUES.map((value, i) => value ^ parseInt(hash.slice(i * 2, i * 2 + 2), 16))
26+
const b64Part = base64Encode(part3).replace(/[\\/+=]/g, '')
27+
return `zzc${part1}${b64Part}${part2}`.toLowerCase()
28+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
import { httpFetch } from '../../../request'
3+
import { zzcSign } from './crypto'
4+
5+
export const signRequest = async(data) => {
6+
// console.log(data)
7+
const sign = await zzcSign(JSON.stringify(data))
8+
// console.log('sign', sign)
9+
return httpFetch(`https://u.y.qq.com/cgi-bin/musics.fcg?sign=${sign}`, {
10+
method: 'post',
11+
headers: {
12+
'User-Agent': 'QQMusic 14090508(android 12)',
13+
},
14+
body: data,
15+
}).promise
16+
}

0 commit comments

Comments
 (0)