vue-cli3 音乐播放器 接口说明(1)

轮播图接口

推荐页的歌单接口

params: {
        platform: 'yqq',
        hostUin: 0,
        sin: 0,
        ein: 29,
        sortId: 5,
        needNewCode: 0,
        categoryId: 10000000,
        rnd: Math.random(),
        format: 'json',
        // notice: 0,
        outCharset: "utf-8",
        inCharset: "utf-8"
            // g_tk: "1928093487"
    }
复制代码

备注:这个接口不能够直接请求,须要在项目中作后台数据的反向代理:代码以下:vue

//vue.config.js
 devServer: { //跨域配置
        before(app) {
            app.get('/api/getDiscList', (req, res) => {
                console.log(req.query)
                var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
                axios.get(url, {
                    headers: {
                        referer: 'https://c.y.qq.com/',
                        host: 'c.y.qq.com'
                    },
                    params: req.query    //须要前台返回数据,这里向qq音乐在发出请求
                }).then((response) => {
                    res.json(response.data)   //数据返给前台
                }).catch((e) => {
                    // console.log(e)
                })
            })

        }
复制代码

歌手列表接口

data: {
        channel: 'singer',
        page: 'list',
        key: 'all_all_all',
        pagesize: 100,
        pagenum: 1,
        hostUin: 0,
        needNewCode: 0,
        platform: 'yqq',
        g_tk: 1928093487,
        notice: 0,
        format: "jsonp",
        inCharset:"utf-8",
        outCharset:"utf-8"
    }
复制代码

歌手详情页接口

data: {
        inCharset: "utf-8",
        outCharset: "utf-8",
        notice: 0,
        pagesize: 100,
        pagenum: 1,
        hostUin: 0,
        needNewCode: 0,
        platform: 'yqq',
        g_tk: 1928093487,
        notice: 0,
        format: "jsonp",
        order: "listen",
        begin: 0,
        num: 80,
        songstatus: 1,
        singermid: "003Nz2So3XXYek"  //这个Id从歌手列表页获取
    }
复制代码
//index.js 方法的封装
import ajax from "./ajax";

export const getRecommendSwiper = () => ajax({
    url: "/api/musichall/fcgi-bin/fcg_yqqhomepagerecommend.fcg"
})

export const getDiscList = () => ajax({
    url: '/api/getDiscList',
    params: {
        platform: 'yqq',
        hostUin: 0,
        sin: 0,
        ein: 29,
        sortId: 5,
        needNewCode: 0,
        categoryId: 10000000,
        rnd: Math.random(),
        format: 'json',
        notice: 0,
        outCharset: "utf-8",
        inCharset: "utf-8",
        g_tk: "1928093487"
    }
})


export const getSinger = () => ajax({
    url: "/api/v8/fcg-bin/v8.fcg",
    params: {
        channel: 'singer',
        page: 'list',
        key: 'all_all_all',
        pagesize: 100,
        pagenum: 1,
        hostUin: 0,
        needNewCode: 0,
        platform: 'yqq',
        g_tk: 1928093487,
        notice: 0,
        format: "jsonp",
        inCharset: "utf-8",
        outCharset: "utf-8"
    }

})

export const getSingerDetail = () => ajax({
    url: "/api/v8/fcg-bin/fcg_v8_singer_track_cp.fcg",
    params: {
        inCharset: "utf-8",
        outCharset: "utf-8",
        notice: 0,
        pagesize: 100,
        pagenum: 1,
        hostUin: 0,
        needNewCode: 0,
        platform: 'yqq',
        g_tk: 1928093487,
        notice: 0,
        format: "jsonp",
        order: "listen",
        begin: 0,
        num: 80,
        songstatus: 1,
        singermid: "003Nz2So3XXYek"
    }
})
复制代码
//vue.config.js 关于接口的配置
const path = require('path');
const axios = require("axios")

module.exports = {
    devServer: { //跨域配置
        proxy: {
            '/api': {
                target: "https://c.y.qq.com/",
                ws: true,
                changOrigin: true,
                pathRewrite: {
                    '^/api': ''
                }
            }

        },
        before(app) {
            app.get('/api/getDiscList', (req, res) => {
                var url = 'https://c.y.qq.com/splcloud/fcgi-bin/fcg_get_diss_by_tag.fcg'
                axios.get(url, {
                    headers: {
                        referer: 'https://c.y.qq.com/',
                        host: 'c.y.qq.com'
                    },
                    params: req.query
                }).then((response) => {
                    res.json(response.data)
                }).catch((e) => {
                    // console.log(e)
                })
            })

        }

    }
}
复制代码
相关文章
相关标签/搜索