问题如下参考链接:https://segmentfault.com/q/1010000010051040

用jsonp抓取qq音乐总是说回调函数没有定义,

我的要实现时候的步骤
1。第一步

我要实现的目的

问题:如题

我的部分代码:

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 definedgetHotSongList(this.disc.dissid).then((res) => {if (res.code === ERR_OK) {// 问题 不能打印出来console.log(res.cdlist[0].songlist)}})

不知道为甚么,折腾一天了,还是没解决,是QQ音乐的接口变了吗,(前两天同样的代码还能正常运行的,昨天就不行了),希望有大神帮忙看看是怎么回事,先谢谢大家了。

补充
回调函数的名称里边处理好了,对其他接口(歌曲图片,歌手,都是用jsonp获取没有问题),_jp1是一个默认名称而已。请求第二个它就变成_jp2,如此类推

处理的部分代码

// 库它自己定义的名字
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++));

该库的地址:https://github.com/webmodules...


再次补充
修改options回调函数名字貌似不行,需要再次设置反向代理,即可解决问题,建议大家看一下MJingv的github相关反向代理设置,地址:https://github.com/MJingv/vue...

单纯这个错误Uncaught ReferenceError: jp2 is not defined,

export function getSongList (disstid) {const url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'const data = Object.assign({}, commonParams, {disstid,type: 1,json: 1,utf8: 1,onlysong: 0,hostUin: 0,g_tk: 487535770,platform: 'yqq',needNewCode: 0})return jsonp(url, data, options)
}

利用如下方法解决

仔细阅读一下第三方库jsonp,里面的opts是一个对象,prefix属性表示callback返回的名字,即传参时候的val值,默认是"__jp",param属性表示的是传参时候的key值。

修改方法,把options定义为:

export function getSongList (disstid) {const url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'const data = Object.assign({}, commonParams, {disstid,type: 1,json: 1,utf8: 1,onlysong: 0,hostUin: 0,g_tk: 487535770,platform: 'yqq',needNewCode: 0})const options = {param: 'jsonpCallback',prefix: 'playlistinfoCallback'}return jsonp(url, data, options)
}

这样把问题解决了,但是还是获取不到数据

确实不能通过jsonp的方式了,参照以前的接口,用node做转发层。

app.get('/api/getSongList', function (req, res) {var url = 'https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg'axios.get(url, {headers: {referer: 'https://y.qq.com/',host: 'c.y.qq.com'},params: req.query}).then((response) => {var ret = response.dataif (typeof ret === 'string') {// var reg = /^\w+\(({[^()]+})\)$/var reg = /{.*}/var matches = ret.match(reg)           if (matches) {ret = JSON.parse(matches[0])}}res.json(ret)}).catch((e) => {console.log(e)})})

在请求接口的地方用axios请求

export function getSongList(disstid) {const url = '/api/getSongList'const data = Object.assign({}, commonParams, {disstid,type: 1,json: 1,utf8: 1,onlysong: 0,platform: 'yqq',hostUin: 0,needNewCode: 0,g_tk: 67232076})return axios.get(url, {params: data}).then(res => {return Promise.resolve(res.data)})
}

就可以获取到了,songlist是放在获取的结果中的
res.cdlist[0].songlist

Uncaught ReferenceError: jp2 is not defined,用jsonp抓取qq音乐总是说回调函数没有定义相关推荐

  1. Uncaught ReferenceError: data is not defined

    问题: 使用jQuery jsonp解决跨域问题时报错 Uncaught ReferenceError: data is not defined 解决: 在function()的括号里添加上data ...

  2. Uncaught ReferenceError: angular is not defined

    搞了一天关于angularJS的Uncaught ReferenceError: angular is not defined 错误 查了好多资料   有人说是加载引入js顺序的问题   但是把他换做 ...

  3. vue中解决Uncaught ReferenceError: regeneratorRuntime is not defined问题

    问题产生 在使用babel编译es6时,遇到报错Uncaught ReferenceError: regeneratorRuntime is not defined问题 问题原因 脚本使用了ES7的 ...

  4. JS报错修改日记(1):Uncaught ReferenceError: showQRcode is not defined

    为了加一个查看二维码的功能,如: //页面内按钮 <a class="manipulate-btn" href="#" οnclick="sho ...

  5. JS问题Uncaught ReferenceError:XXXX is not defined

    背景: html中一个table,table中进行分页.每行后面有一系列操作,如删除,修改.现在以删除为例说明问题. 实现方式: 使用button,在onclick中调用js函数,js函数中传递参数如 ...

  6. Uncaught ReferenceError: layer is not defined

    今天在写项目的时候,从git上重新下拉,部署tomcat之后出现这样的问题 上面图片中,下拉框的箭头不见了, 而且点击不了. 我回到myeclipse中检查主界面代码是不是写错了,发现根本就没有报错, ...

  7. Electron中 提示:Uncaught ReferenceError: process is not defined

    场景 用HTML和CSS和JS构建跨平台桌面应用程序的开源库Electron的介绍以及搭建HelloWorld: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/a ...

  8. (网页)Uncaught ReferenceError: pageImport is not defined

    在js开发中,很多人遇到类似问题,都找不到解决方法.Uncaught ReferenceError: $ is not defined,在这里给大家提供几个解决方法. 1.出现这个错误,最可能的是引用 ...

  9. 解决 VUE前端项目报错: Uncaught ReferenceError : initPage is not defined (initPage 方法是有的,依旧报错找不到)

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 1. 明明代码中定义了 initPage 这个方法,,却一直报找不到这个方法: Uncaught R ...

最新文章

  1. 不用额外变量交换两个整数的值
  2. 最小二乘法least square
  3. 一逛淘宝就停不下来?秘密在于首屏设计...
  4. antd的table进行列筛选时,更新dataSource,为什么table显示暂无数据?
  5. CSDN博客如何显示空白符
  6. maven打包不用eclipse插件
  7. 如何优雅的使用 phpStorm
  8. Spring学习笔记专题三
  9. 解决redis-cli command not found问题
  10. empinfo Oracle数据库,Oracle:其他数据库对象
  11. 推荐几个手机网站在线预览测试工具
  12. c语言过程化程序设计方法,程序的设计基础(C语言入门及编程环境)(修改).ppt
  13. c 语言 宏 可变 参数,利用C可变参数和宏定义来实现自己的日志系统
  14. mongodb数据库显示obj_MongoDB创建和查看数据库
  15. 基础总结篇之八:创建及调用自己的ContentProvider
  16. ios上传图片遇见了一个TimeoutError(DOM Exception 23)异常
  17. 万字精选长文,深入解读房地产土地投资测算路径(附下载)
  18. 那些好用的阅读软件(Windows Android)
  19. Landsat卫星数据介绍及下载方法
  20. 麒麟v10安装达梦数据库

热门文章

  1. transformer序列预测示例
  2. 如何设置Scratch进入全屏
  3. python与西门子PLC通讯
  4. 中电金信源启数据资产管理平台助力金融机构加速数据资产化过程(下)
  5. 软件测试常见面试题及解答
  6. 授人以鱼,不如授人以渔
  7. 安卓自动滑屏脚本_手机屏幕滑动脚本2
  8. uni-app开发微信公众号扫码功能(1)-测试环境
  9. 正则表达式中的数量词概念
  10. c4d如何把文字贴在物体表面_c4d材质贴图想给材质加字(c4d 材质贴图怎么贴?)...