音乐播放地址失效,按照老师issue111去fix,遇到post501
来源:7-8 播放器歌曲播放功能实现
慕用3095910
2018-11-28
export function getSongsUrl(songs) {
const url = debug ? '/api/getPurlUrl' : 'http://ustbhuangyi.com/music/api/getPurlUrl'
let mids = []
let types = []
songs.forEach((song) => {
mids.push(song.mid)
types.push(0)
})
const urlMid = genUrlMid(mids, types)
const data = Object.assign({}, commonParams, {
g_tk: 5381,
format: 'json',
platform: 'h5',
needNewCode: 1,
uin: 0
})
return new Promise((resolve, reject) => {
let tryTime = 3
function request() {
return axios.post(url, {
comm: data,
url_mid: urlMid
}).then((response) => {
const res = response.data
if (res.code === ERR_OK) {
let urlMid = res.url_mid
if (urlMid && urlMid.code === ERR_OK) {
const info = urlMid.data.midurlinfo[0]
if (info && info.purl) {
resolve(res)
} else {
retry()
}
} else {
retry()
}
} else {
retry()
}
})
}
function retry() {
if (--tryTime >= 0) {
request()
} else {
reject(new Error('Can not get the songs url'))
}
}
request()
})
}
import { createSong, isValidMusic, processSongsUrl } from 'common/js/song'
_getDetail(){
if(!this.Singer.id){
this.$router.push('/singer')
return
}
getSingerDetail(this.Singer.id).then((res) => {
if (res.code === ERR_OK) {
processSongsUrl(this._normalizeSongs(res.data.list)).then((songs) => {
this.songs = songs
})
// this.songs = this._normalizeSongs(res.data.list)
}
})
},
这是webpack.dev.conf.js
app.use(bodyParser.urlencoded({extended: true}))
const querystring = require('querystring')
app.post('/api/getPurlUrl', bodyParser.json(), function (req, res) {
const url = 'https://u.y.qq.com/cgi-bin/musicu.fcg'
axios.post(url, req.body, {
headers: {
referer: 'https://y.qq.com/',
origin: 'https://y.qq.com',
'Content-type': 'application/x-www-form-urlencoded'
}
}).then((response) => {
res.json(response.data)
}).catch((e) => {
console.log(e)
})
})
}
写回答
1回答
-
ustbhuangyi
2018-11-29
501 代表 server 端出现了错误,所以你要检查一下你的接口代理部分是否写的有问题
022018-11-29