Skip to content

🌐 HTTP API

所有 API 函数封装在 src/api/index.ts,基于 Axios 实现。

🔧 HTTP 封装

📁 文件位置src/utils/http.ts

ts
import axios from 'axios'

const instance = axios.create({
  baseURL: import.meta.env.VITE_APP_BASE_API,
  timeout: 1000000,
  withCredentials: true,
})

// 请求拦截器:自动添加时间戳
instance.interceptors.request.use((config) => {
  config.params = {
    ...config.params,
    timestamp: Date.now(),
  }
  return config
})

export const httpGet = <T>(url: string, params?: object): Promise<T> =>
  instance.get(url, { params })

export const httpPost = <T>(url: string, data?: object): Promise<T> =>
  instance.post(url, data)

🔐 登录相关

loginCellphone

手机号登录

ts
loginCellphone(params: {
  phone: string
  password?: string
  md5_password?: string
  captcha?: string
  countrycode?: string
})

loginEmail

邮箱登录

ts
loginEmail(params: {
  email: string
  password?: string
  md5_password?: string
})

二维码登录

ts
// 获取二维码 key
qrLoginKey()

// 生成二维码
qrLoginCreate(params: { key: string; qrimg?: boolean })

// 检查扫码状态
qrLoginCheck(params: { key: string; noCookie?: boolean })

验证码

ts
// 发送验证码
captchaSent(params: { phone: string; ctcode?: number })

// 验证验证码
captchaVerify(params: { phone: string; captcha: string; ctcode?: number })

🔑 其他

ts
loginRefresh()      // 刷新登录状态
loginStatus()       // 获取登录状态
loginAnonymous()    // 匿名登录

🔍 搜索相关

search / cloudSearch

搜索(cloudSearch 为云搜索,结果更全)

ts
search(params: {
  keywords: string
  limit?: number
  offset?: number
  type?: 1 | 10 | 100 | 1000 | 1002 | 1004 | 1006 | 1009 | 1014 | 1018 | 2000
})

type 参数说明

类型
1单曲
10专辑
100歌手
1000歌单
1002用户
1004MV
1006歌词
1009电台
1014视频
1018综合
2000声音

搜索建议

ts
searchSuggest(params: { keywords: string; type?: 'mobile' })
searchHot()           // 热搜简略
searchHotDetail()     // 热搜详细
searchDefault()       // 默认搜索词
searchMultimatch(params: { keywords: string })  // 多类型匹配

🎵 歌曲相关

songDetail

获取歌曲详情

ts
songDetail(params: { ids: string })  // 多个 ID 用逗号分隔

songUrl / songUrlV1

获取歌曲播放地址

ts
songUrl(params: { id: string; br?: number })

songUrlV1(params: {
  id: string
  level?: 'standard' | 'higher' | 'exhigh' | 'lossless' | 'hires' | 'jyeffect' | 'sky' | 'jymaster'
})

lyric

获取歌词

ts
lyric(params: { id: number | string })

返回值包含:

  • lrc.lyric - 原文歌词
  • tlyric.lyric - 翻译歌词
  • romalrc.lyric - 罗马音

checkMusic

检查歌曲是否可用

ts
checkMusic(params: { id: string; br?: number })

songDownloadUrl

获取下载地址

ts
songDownloadUrl(params: { id: string; br?: number })

📋 歌单相关

playlistDetail

歌单详情

ts
playlistDetail(params: { id: number; s?: number })

playlistTrackAll

歌单全部歌曲

ts
playlistTrackAll(params: { id: number; limit?: number; offset?: number })

userPlaylist

用户歌单

ts
userPlaylist(params: { uid: number; limit?: number; offset?: number })

topPlaylist

热门歌单

ts
topPlaylist(params: {
  order?: 'new' | 'hot'
  cat?: string
  limit?: number
  offset?: number
})

playlistCatlist

歌单分类

ts
playlistCatlist()

🎤 艺术家相关

artistList

艺术家列表

ts
artistList(params?: {
  type?: number     // -1:全部 1:男 2:女 3:乐队
  area?: number     // -1:全部 7:华语 96:欧美 8:日本 16:韩国
  initial?: string  // 首字母
  limit?: number
  offset?: number
})

artistDetail

艺术家详情

ts
artistDetail(params: { id: number })

artistTopSong

艺术家热门歌曲

ts
artistTopSong(params: { id: number })

artistAlbum

艺术家专辑

ts
artistAlbum(params: { id: number; limit?: number; offset?: number })

artistMv

艺术家 MV

ts
artistMv(params: { id: number; limit?: number; offset?: number })

artistDesc

艺术家简介

ts
artistDesc(params: { id: number })

topArtists

热门艺术家

ts
topArtists(params?: { limit?: number; offset?: number })

💿 专辑相关

albumDetail

专辑详情

ts
albumDetail(params: { id: number | string })

albumNew

新碟上架

ts
albumNew(params?: {
  area?: 'ALL' | 'ZH' | 'EA' | 'KR' | 'JP'
  limit?: number
  offset?: number
})

albumNewest

最新专辑

ts
albumNewest()

🎬 MV 相关

mvDetail

MV 详情

ts
mvDetail(params: { mvid: number | string })

mvUrl

MV 播放地址

ts
mvUrl(params: { id: number | string; r?: number })  // r: 分辨率

mvAll

所有 MV

ts
mvAll(params: {
  area?: string
  type?: string
  order?: string
  limit?: number
  offset?: number
})

simiMv

相似 MV

ts
simiMv(params: { mvid: number | string })

📊 排行榜相关

toplist

所有榜单

ts
toplist()

toplistDetail

榜单详情

ts
toplistDetail()

topSong

新歌榜

ts
topSong(params: { type: 0 | 7 | 96 | 8 | 16 })
// 0:全部 7:华语 96:欧美 8:日本 16:韩国

✨ 推荐相关

personalized

推荐歌单

ts
personalized(params?: { limit?: number })

personalizedNewsong

推荐新歌

ts
personalizedNewsong(params?: { limit?: number })

personalizedMv

推荐 MV

ts
personalizedMv()

recommendSongs

每日推荐歌曲(需登录)

ts
recommendSongs()

recommendResource

每日推荐歌单(需登录)

ts
recommendResource()

personalFm

私人 FM

ts
personalFm()

💬 评论相关

commentMusic

歌曲评论

ts
commentMusic(params: {
  id: number
  limit?: number
  offset?: number
  before?: number
})

commentNew

新版评论接口

ts
commentNew(params: {
  id: number
  type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
  sortType?: 1 | 2 | 3
  pageNo?: number
  pageSize?: number
  cursor?: number
})

type 参数说明

类型
0歌曲
1MV
2歌单
3专辑
4电台
5视频
6动态
7电台节目

commentHot

热门评论

ts
commentHot(params: {
  id: number
  type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
  limit?: number
  offset?: number
  before?: number
})

commentSend

发送评论

ts
commentSend(params: {
  t: 1 | 2        // 1:发送 2:回复
  type: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7
  id?: number
  threadId?: string
  content: string
  commentId?: number
})

🛠️ 其他

轮播图

ts
banner(params?: { type?: 0 | 1 | 2 | 3 })
// 0:pc 1:android 2:iphone 3:ipad

recordRecentSong

最近播放歌曲

ts
recordRecentSong(params?: { limit?: number })

基于 PolyForm-Noncommercial-1.0.0 许可发布