Using jsonp to capture qq music always says that the callback function is not defined,
My steps to achieve
1. first step
What I want to achieve
Question: As in the title
Part of my code:
import originJSONP from 'jsonp'
export default function (url, data, option) {
url += (url.indexOf('?') < 0 ? '?' : '&') + param(data)
return new Promise((resolve, reject) => {
originJSONP(url, option, (err, data) => {
if (!err) {
resolve(data)
} else {
reject(err)
}
})
})
}
// 将 data 拼接到 url 上
function param(data) {
let url = ''
for (let i in data) {
let value = data[i] !== undefined ? data[i] : ''
url += `&${i}=${encodeURIComponent(value)}`
}
return url
}
// 热门歌单详情歌曲
export function getHotSongList(disstid) {
const url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'
const data = Object.assign({}, commonParam, {
type: 1,
json: 1,
utf8: 1,
onlysong: 0,
disstid,
// jsonpCallback: 'playlistinfoCallback',
loginUin: 0,
hostUin: 0,
inCharset: 'utf8',
platform: 'yqq',
needNewCode: 0
})
return jsonp(url, data, options)
}
// this.disc.dissid我已经正确获取了,通过自己服务端代理,代码太多就不贴了。
// TODO 报错ReferenceError: jp1() is not defined
getHotSongList(this.disc.dissid).then((res) => {
if (res.code === ERR_OK) {
// 问题 不能打印出来
console.log(res.cdlist[0].songlist)
}
})
I don’t know why. I’ve been struggling for a day and still haven’t solved it. Has the interface of QQ Music changed? (The same code was still running normally two days ago, but not yesterday). I hope someone can help me find out. What's going on? Thank you all in advance.
Supplement
The name of the callback function has been processed. For other interfaces (song pictures, singers, all can be obtained using jsonp without any problem), _jp1 is just a default name. Request the second one and it becomes _jp2, and so on
Part of the processing code
// 库它自己定义的名字
var prefix = opts.prefix || '__jp';
// use the callback name that was passed if one was provided.
// otherwise generate a unique name by incrementing our counter.
var id = opts.name || (prefix + (count++));
The address of this library: https://github.com/webmodules...
Have you defined the jp1 function? How could it be successful if not?
It is recommended to take a look at the principle of jsonp