1.跨域接口
webpack.base.conf.js
文件:
const devWebpackConfig = merge(baseWebpackConfig, {
...devServer: {clientLogLevel: 'warning',...watchOptions: {poll: config.dev.poll,},before(app) {app.get('/api/getPlaySongVkey', function (req, res) {var url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'axios.get(url, {headers: {referer: 'https://u.y.qq.com',host: 'u.y.qq.com'},params: req.query}).then((response) => {res.json(response.data)}).catch((e)=>{console.log(e)})})}...}
}
2.获取视频vid
1.查看QQ音乐官网数据,获取视频的vid
2.查看接口
version_id
版本,area_id
区域。
发现显示的每首歌vid:
3.search.js
api接口:
这里没传区域和版本id,是直接拿区域(全部)和版本(全部)。
export function getMvList() {const url = '/api/getPlaySongVkey'const data = Object.assign({}, {g_tk: 5381,// loginUin: 2093181912,hostUin: 0,format: 'json',notice: 0,platform: 'yqq.json',needNewCode: 0,data: {'comm': {'ct': 24}, 'mv_tag': {'module': 'MvService.MvInfoProServer', 'method': 'GetAllocTag', 'param': {}}, 'mv_list': {'module': 'MvService.MvInfoProServer', 'method': 'GetAllocMvInfo', 'param': {'start': 0, 'size': 20, 'version_id': 7, 'area_id': 15, 'order': 1}}}})// return jsonp(url, data)return axios.get(url, {params: data}).then((res) => {return Promise.resolve(res)})
}
4.vue组件:
export const ERR_OK = 0
data() {return {MvList: []}},created() {this._getMvList()},methods: {_getMvList(){getMvList().then((res) => {// if (res.code === ERR_OK) {this.MvList = res.data.mv_list.data.list// console.log(res)// }})}
5.查看回来的数据
3.获取视频
1.search.js
api接口:
export function getMVUrl(vid) {const url = '/api/getPlaySongVkey'const data = Object.assign({}, {g_tk: 5381,// loginUin: 2093181912,hostUin: 0,format: 'json',notice: 0,platform: 'yqq.json',needNewCode: 0,data: {'getMVInfo': {'module': 'video.VideoDataServer', 'method': 'get_video_info_batch', 'param': {'vidlist': [vid], 'required': ['vid', 'sid', 'gmid', 'type', 'name', 'cover_pic', 'video_switch', 'msg'], 'from': 'h5.playsong'}}, 'getMVUrl': {'module': 'gosrf.Stream.MvUrlProxy', 'method': 'GetMvUrls', 'param': {'vids': [vid], 'from': 'h5.playsong'}, 'request_typet': 10001}}})// return jsonp(url, data)return axios.get(url, {params: data}).then((res) => {return Promise.resolve(res)})
}
2.查看接收数据
mp4[0]
是空的
3.vue组件:
data() {return {mvUrl: [],mp4Url: []}},created() {this._getMVUrl()},methods: {_getMVUrl() {getMVUrl(this.vid).then((res) => {// if (res.code === ERR_OK) {if (res.data && res.data.getMVUrl && res.data.getMVUrl.data) {this.mvUrl = res.data.getMVUrl.datafor (var key in this.mvUrl) {var value = this.mvUrl[key]if (!value) {continue}var mp4 = value["mp4"]if (mp4) {// console.log(mp4[1].freeflow_url[0])this.mp4Url = mp4[1].freeflow_url[0]this.setMvUrl(this.mp4Url)return this.mp4Url}}}// }})}}
4.查看数据:
ps:
1.视频封面和名字,跟获取视频一样操作
2.感谢大佬帮助