1+ import com .alibaba .fastjson2 .*
2+
3+ HEADERS = new HashMap ()
4+ HEADERS .put ("referer" , "http://aqqmusic.tc.qq.com/" )
5+ HEADERS .put ("user-agent" , "Mozilla/5.0 Chrome/92.0.4515.105 Safari/537.36" )
6+
7+ BASE_URL = "http://aqqmusic.tc.qq.com/"
8+ API_URL = "http://u.y.qq.com/cgi-bin/musicu.fcg"
9+ PIC_URL = "http://y.gtimg.cn/music/photo_new/T002R500x500M000"
10+ LYRIC_URL = "http://c.y.qq.com/lyric/fcgi-bin/fcg_query_lyric_new.fcg?format=json&nobase64=1"
11+
12+ search (name ) {
13+ return """
14+ {"comm": {
15+ "ct": "19",
16+ "cv": "1882",
17+ "uin": "3449496653"
18+ }, "searchMusic": {
19+ "method": "DoSearchForQQMusicDesktop",
20+ "module": "music.search.SearchCgiService",
21+ "param": {
22+ "grp": 1,
23+ "num_per_page": 1,
24+ "page_num": 1,
25+ "query": "${name}",
26+ "search_type": 0
27+ }
28+ }
29+ }"""
30+ }
31+
32+ purl (id ) {
33+ return """
34+ {"comm": {
35+ "ct": "11",
36+ "cv": "22060004",
37+ "tmeAppID": "ztelite",
38+ "OpenUDID": "nouid",
39+ "uid": "3449496653"
40+ }, "request": {
41+ "module": "music.qqmusiclite.MtLimitFreeSvr",
42+ "method": "Obtain",
43+ "param": {
44+ "songid": [${id}],
45+ "need_ppurl": true
46+ }
47+ }
48+ }"""
49+ }
50+
51+ getVkey (name , mid ) {
52+ return """
53+ {"comm": {
54+ "ct": "11",
55+ "cv": "22060004",
56+ "tmeAppID": "ztelite",
57+ "OpenUDID": "nouid",
58+ "uid": "3449496653"
59+ }, "request": {
60+ "module": "music.vkey.GetVkey",
61+ "method": "UrlGetVkey",
62+ "param": {
63+ "guid": "yun",
64+ "songmid": ["${mid}"],
65+ "filename": ["M500${name}.mp3"]
66+ }
67+ }
68+ }"""
69+ }
70+
71+ vkey (mid , purl ) {
72+ return """
73+ {"request": {
74+ "module": "music.vkey.GetVkey",
75+ "method": "CgiGetTempVkey",
76+ "param": {
77+ "guid": "yun",
78+ "songlist": [{
79+ "mediamid": "yun",
80+ "tempVkey": "${purl}",
81+ "songMID": "${mid}"
82+ }]
83+ }
84+ }
85+ }"""
86+ }
87+
88+ send_Music (talker , title , author , musicUrl , albumUrl , lyric ) {
89+ sendCard (talker ,
90+ """<msg>
91+ <appmsg appid="wx1c37343fc2a86bc4">
92+ <title>${escape(title)}</title>
93+ <des>${escape(author)}</des>
94+ <action>view</action>
95+ <type>76</type>
96+ <url>${escape(musicUrl)}</url>
97+ <dataurl>${escape(musicUrl)}</dataurl>
98+ <songalbumurl>${escape(albumUrl)}</songalbumurl>
99+ <songlyric>${escape(lyric)}</songlyric>
100+ <musicShareItem>
101+ <mvCoverUrl>${escape(albumUrl)}</mvCoverUrl>
102+ <mvSingerName>${escape(author)}</mvSingerName>
103+ <mid>getlinkmid_</mid>
104+ </musicShareItem>
105+ </appmsg>
106+ </msg>""" )
107+ }
108+
109+ escape (s ) {
110+ if (s == null ) return ""
111+ return s .replace ("&" , "&" )
112+ .replace ("<" , "<" )
113+ .replace (">" , ">" )
114+ .replace ("\" " , """ )
115+ .replace ("'" , "'" )
116+ }
117+
118+ music (talker , song ) {
119+ get (API_URL + "?data=${search(song)}" , resp -> {
120+ if (resp == null ) return sendText (talker , "请求失败" )
121+ search = JSON .parseObject (resp )
122+ if (search .getIntValue ("code" ) != 0 ) return sendText (talker , "发生错误" )
123+ music = JSONPath .eval (search , "$.searchMusic.data.body.song.list[0]" )
124+ if (music == null ) return sendText (talker , "未搜到" )
125+ mid = music .getString ("mid" )
126+ id = music .getString ("id" )
127+ name = music .getString ("name" )
128+ singer = JSONPath .eval (music , "$.singer[0].name" )
129+ mediamid = JSONPath .eval (music , "$.file.media_mid" )
130+ pic = PIC_URL + JSONPath .eval (music , "$.album.pmid" ) + ".jpg"
131+ post (API_URL , "${purl(id)}" , resp -> {
132+ if (resp == null ) return
133+ result = JSON .parseObject (resp )
134+ pUrl = JSONPath .eval (result , "$.request.data.tracks[0].control.ppurl" )
135+ get (LYRIC_URL + "&songmid=${mid}" , resp -> {
136+ lyric = JSONPath .eval (resp , "$.lyric" )
137+ if (!pUrl .isEmpty ()) {
138+ post (API_URL , "${vkey(mid, pUrl)}" , resp -> {
139+ url = JSONPath .eval (resp , "$.request.data.data.yun.purl" )
140+ send_Music (talker , name , singer , url , pic , lyric )
141+ })
142+ } else
143+ post (API_URL , "${getVkey(mediamid, mid)}" , resp -> {
144+ url = JSONPath .eval (resp , "$.request.data.midurlinfo[0].flowurl" )
145+ if (!url .isEmpty ()) {
146+ send_Music (talker , name , singer , BASE_URL + url , pic , lyric )
147+ } else sendText (talker , "该曲可能是数字专辑" )
148+ })
149+ }, HEADERS )
150+ })
151+ }, HEADERS )
152+ }
0 commit comments