-
Notifications
You must be signed in to change notification settings - Fork 7
/
songDetail.go
55 lines (49 loc) · 1.34 KB
/
songDetail.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package api
import (
"encoding/json"
"github.com/XiaoMengXinX/Music163Api-Go/types"
"github.com/XiaoMengXinX/Music163Api-Go/utils"
)
// SongDetailAPI 歌曲详细信息 API
const SongDetailAPI = "/api/v3/song/detail"
// SongDetailReq SongDetail API 的 body json
type SongDetailReq struct {
C string `json:"c"`
ER string `json:"e_r"`
Header string `json:"header"`
}
type songIDs struct {
Id int `json:"id"`
}
// CreateSongDetailReqJson 创建请求 body json
func CreateSongDetailReqJson(ids []int) string {
var songID []songIDs
for i := 0; i < len(ids); i++ {
songID = append(songID, songIDs{
Id: ids[i],
})
}
songIDJson, _ := json.Marshal(songID)
reqBody := SongDetailReq{
C: string(songIDJson),
Header: "{}",
ER: "true",
}
reqBodyJson, _ := json.Marshal(reqBody)
return string(reqBodyJson)
}
// GetSongDetail 获取歌曲详细信息
func GetSongDetail(data utils.RequestData, ids []int) (result types.SongsDetailData, err error) {
var options utils.EapiOption
options.Path = SongDetailAPI
options.Url = "https://music.163.com/eapi/v3/song/detail"
reqBodyJson := CreateSongDetailReqJson(ids)
options.Json = reqBodyJson
resBody, _, err := utils.EapiRequest(options, data)
if err != nil {
return result, err
}
err = json.Unmarshal([]byte(resBody), &result)
result.RawJson = resBody
return result, err
}