修复接口失效问题

This commit is contained in:
lyswhut
2019-08-29 00:53:05 +08:00
parent 4adc950e29
commit c392f7ee8d
28 changed files with 514 additions and 94 deletions
@@ -0,0 +1,44 @@
import { httpFatch } from '../../request'
import { requestMsg } from '../../message'
const api_internal = {
successCode: 2200,
// getMusicUrl(songInfo, type) {
// const requestObj = httpFatch(`http://play.taihe.com/data/music/songlink`, {
// method: 'post',
// headers: {
// Origin: 'http://play.taihe.com',
// },
// formData: {
// songIds: songInfo.songmid,
// },
// })
// requestObj.promise = requestObj.promise.then(({ body }) => {
// console.log(body)
// return Promise.reject()
// // if (body.error_code !== this.successCode) return this.getMusicUrl(songInfo, type)
// // return body.code === 200 ? Promise.resolve({ type, url: body.result.bitrate.file_link }) : Promise.reject(new Error(requestMsg.fail))
// })
// return requestObj
// },
getMusicInfo(songInfo, tryNum = 0) {
const requestObj = httpFatch(`http://tingapi.ting.baidu.com/v1/restserver/ting?from=webapp_music&method=baidu.ting.song.baseInfos&song_id=${songInfo.songmid}`)
requestObj.promise = requestObj.promise.then(({ body }) => {
if (body.error_code !== this.successCode) return tryNum > 5 ? Promise.reject(new Error(requestMsg.fail)) : this.getMusicInfo(songInfo, ++tryNum)
return body ? Promise.resolve(body.result.items[0]) : Promise.reject(new Error(requestMsg.fail))
})
return requestObj
},
getPic(songInfo) {
const requestObj = this.getMusicInfo(songInfo)
requestObj.promise = requestObj.promise.then(info => info.pic_premium)
return requestObj
},
getLyric(songInfo) {
const requestObj = this.getMusicInfo(songInfo)
requestObj.promise.then(info => httpFatch(info.lrclink).promise)
return requestObj
},
}
export default api_internal
+7 -3
View File
@@ -1,11 +1,13 @@
import { httpFatch } from '../../request'
import { requestMsg } from '../../message'
import { headers, timeout } from '../messoer'
const api_messoer = {
getMusicUrl(songInfo, type) {
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/url?id=${songInfo.songmid}&quality=${type.replace(/k$/, '')}&isRedirect=0`, {
method: 'get',
timeout: 5000,
timeout,
headers,
})
requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 200 ? Promise.resolve({ type, url: body.data }) : Promise.reject(new Error(requestMsg.fail))
@@ -15,7 +17,8 @@ const api_messoer = {
getPic(songInfo, size = '500') {
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/pic?id=${songInfo.songmid}&imageSize=${size}&isRedirect=0`, {
method: 'get',
timeout: 5000,
timeout,
headers,
})
requestObj.promise = requestObj.promise.then(({ body }) => {
return body.code === 200 ? Promise.resolve(body.data) : Promise.reject(new Error(requestMsg.fail))
@@ -25,7 +28,8 @@ const api_messoer = {
getLyric(songInfo) {
const requestObj = httpFatch(`https://v1.itooi.cn/baidu/lrc?id=${songInfo.songmid}&isRedirect=0`, {
method: 'get',
timeout: 5000,
timeout,
headers,
})
requestObj.promise = requestObj.promise.then(({ body }) => {
return body ? Promise.resolve(body) : Promise.reject(new Error(requestMsg.fail))
+14 -14
View File
@@ -4,9 +4,9 @@ import CryptoJS from 'crypto-js'
export default {
_requestObj_tags: null,
_requestObj_songList: null,
_requestObj_songListRecommend: null,
_requestObj_songListDetail: null,
_requestObj_list: null,
_requestObj_listRecommend: null,
_requestObj_listDetail: null,
limit_list: 20,
limit_song: 25,
successCode: 22000,
@@ -87,7 +87,7 @@ export default {
version: '10.1.8',
}, 'baidu.ting.ugcdiy.getChannels')
},
getSongListUrl(sortType, tagName, page) {
getListUrl(sortType, tagName, page) {
return this.createUrl({
channelname: tagName,
from: 'qianqianmini',
@@ -139,14 +139,14 @@ export default {
// 获取列表数据
getList(sortId, tagId, page) {
if (this._requestObj_songList) this._requestObj_songList.cancelHttp()
this._requestObj_songList = httpFatch(
this.getSongListUrl(sortId, tagId, page)
if (this._requestObj_list) this._requestObj_list.cancelHttp()
this._requestObj_list = httpFatch(
this.getListUrl(sortId, tagId, page)
)
return this._requestObj_songList.promise.then(({ body }) => {
return this._requestObj_list.promise.then(({ body }) => {
if (body.error_code !== this.successCode) return this.getSongList(sortId, tagId, page)
return {
list: this.filterSongList(body.diyInfo),
list: this.filterList(body.diyInfo),
total: body.nums,
page,
limit: this.limit_list,
@@ -164,7 +164,7 @@ export default {
if (num > 10000) return parseInt(num / 1000) / 10 + '万'
return num
},
filterSongList(rawData) {
filterList(rawData) {
return rawData.map(item => ({
play_count: this.formatPlayCount(item.listen_num),
id: item.list_id,
@@ -179,11 +179,11 @@ export default {
// 获取歌曲列表内的音乐
getListDetail(id, page) {
if (this._requestObj_songListDetail) {
this._requestObj_songListDetail.cancelHttp()
if (this._requestObj_listDetail) {
this._requestObj_listDetail.cancelHttp()
}
this._requestObj_songListDetail = httpFatch(this.getListDetailUrl(id, page))
return this._requestObj_songListDetail.promise.then(({ body }) => {
this._requestObj_listDetail = httpFatch(this.getListDetailUrl(id, page))
return this._requestObj_listDetail.promise.then(({ body }) => {
if (body.error_code !== this.successCode) return this.getListDetail(id, page)
let listData = this.filterData(body.result.songlist)
return {