1+ <?php
2+ /**
3+ * Created by PhpStorm.
4+ * User: Kilingzhang <slight@kilingzhang.com>
5+ * Date: 2017/8/19
6+ * Time: 19:22
7+ */
8+
9+ namespace NeteaseCloudMusicApiSdk ;
10+
11+ use PhpBoot \Application ;
12+ use PhpBoot \DI \Traits \EnableDIAnnotations ;
13+ use Utils \Request ;
14+ use Utils \Snoopy ;
15+
16+ class Dj
17+ {
18+
19+ use EnableDIAnnotations;
20+
21+ /**
22+ * 电台-推荐
23+ * 说明:登陆后调用此接口,可获得推荐电台
24+ *
25+ * 接口地址:
26+ * /dj/recommend
27+ *
28+ * 调用例子:
29+ * /dj/recommend
30+ *
31+ * @route GET /dj/recommend
32+ * @return string json
33+ */
34+ public function recommend ()
35+ {
36+ $ Request = new Request ();
37+ $ data = array (
38+ 'csrf_token ' => '' ,
39+ );
40+ $ response = $ Request ->createWebAPIRequest (
41+ "http://music.163.com " ,
42+ "/weapi/djradio/recommend/v1 " ,
43+ 'POST ' ,
44+ $ data
45+ );
46+ return json_decode ($ response , true );
47+ }
48+
49+
50+ /**
51+ * 电台-分类
52+ * 说明:登陆后调用此接口,可获得电台类型
53+ *
54+ * 接口地址:
55+ * /dj/catelist
56+ *
57+ * 调用例子:
58+ * /dj/catelist
59+ *
60+ * @route GET /dj/catelist
61+ * @return string json
62+ */
63+ public function catelist ()
64+ {
65+ $ Request = new Request ();
66+ $ data = array (
67+ 'csrf_token ' => '' ,
68+ );
69+ $ response = $ Request ->createWebAPIRequest (
70+ "http://music.163.com " ,
71+ "/weapi/djradio/category/get " ,
72+ 'POST ' ,
73+ $ data
74+ );
75+ return json_decode ($ response , true );
76+ }
77+
78+
79+ /**
80+ * 电台-分类推荐
81+ * 说明:登陆后调用此接口,可获得推荐电台
82+ *
83+ * 必选参数:
84+ * type: 电台类型,数字,可通过/dj/catelist获取,对应关系为 id 对应 此接口的 type, name 对应类型意义
85+ *
86+ * 接口地址:
87+ * /dj/recommend/type
88+ *
89+ * 调用例子:
90+ * /dj/recommend/type?type=1
91+ *
92+ * @route GET /dj/recommend/type
93+ * @param int $type
94+ * @return string json
95+ */
96+ public function type ($ type )
97+ {
98+ $ Request = new Request ();
99+ $ data = array (
100+ 'csrf_token ' => '' ,
101+ 'cateId ' => $ type ,
102+ );
103+ $ response = $ Request ->createWebAPIRequest (
104+ "http://music.163.com " ,
105+ "/weapi/djradio/recommend " ,
106+ 'POST ' ,
107+ $ data
108+ );
109+ return json_decode ($ response , true );
110+ }
111+
112+
113+ /**
114+ * 电台-订阅
115+ * 说明:登陆后调用此接口,传入rid,可订阅 dj,dj 的 rid 可通过搜索指定 type='1009'获取其 id,如/search?keywords=代码时间&type=1009
116+ *
117+ * 必选参数:
118+ * rid: 电台 的 id
119+ *
120+ * 接口地址:
121+ * /dj/sub
122+ *
123+ * 调用例子:
124+ * /dj/sub?rid=336355127&t=1 (对应关注'代码时间')
125+ * /dj/sub?rid=336355127&t=0 (对应取消关注'代码时间')
126+ *
127+ * @route GET /dj/sub
128+ * @param int $rid
129+ * @return string json
130+ */
131+ public function sub ($ rid , $ t = 1 )
132+ {
133+ $ Request = new Request ();
134+ $ data = array (
135+ 'csrf_token ' => '' ,
136+ 'id ' => $ rid ,
137+ );
138+ $ action = $ t == 1 ? 'sub ' : 'unsub ' ;
139+ $ response = $ Request ->createWebAPIRequest (
140+ "http://music.163.com " ,
141+ "/weapi/djradio/ {$ action }" ,
142+ 'POST ' ,
143+ $ data
144+ );
145+ return json_decode ($ response , true );
146+ }
147+
148+
149+ /**
150+ * 电台-详情
151+ * 说明:登陆后调用此接口,传入rid,可获得对应电台的详情介绍
152+ *
153+ * 必选参数:
154+ * rid: 电台 的 id
155+ *
156+ * 接口地址:
157+ * /dj/detail?rid=336355127
158+ *
159+ * 调用例子:
160+ * /dj/detail?rid=336355127 (对应'代码时间'的详情介绍)
161+ *
162+ * @route GET /dj/detail
163+ * @param int $rid
164+ * @return string json
165+ */
166+ public function detail ($ rid )
167+ {
168+ $ Request = new Request ();
169+ $ data = array (
170+ 'csrf_token ' => '' ,
171+ 'id ' => $ rid ,
172+ );
173+ $ response = $ Request ->createWebAPIRequest (
174+ "http://music.163.com " ,
175+ "/weapi/djradio/get " ,
176+ 'POST ' ,
177+ $ data
178+ );
179+ return json_decode ($ response , true );
180+ }
181+
182+
183+ /**
184+ * 电台-节目
185+ * 说明:登陆后调用此接口,传入rid,可查看对应电台的电台节目以及对应的 id, 需要注意的是这个接口返回的 mp3Url 已经无效,都为 null, 但是通过调用 /music/url 这个接口,传入节目 id 仍然能获取到节目音频,如 /music/url?id=478446370 获取代码时间的一个节目的音频
186+ *
187+ * 必选参数:
188+ * rid: 电台 的 id
189+ *
190+ * 接口地址:
191+ * /dj/sub
192+ *
193+ * 调用例子:
194+ * /dj/program?rid=336355127 (对应'代码时间'的节目列表)
195+ *
196+ * @route GET /dj/program
197+ * @param int $rid
198+ * @return string json
199+ */
200+ public function program ($ rid , $ limit = 30 , $ offset = 0 )
201+ {
202+ $ Request = new Request ();
203+ $ data = array (
204+ 'csrf_token ' => '' ,
205+ 'asc ' => '' ,
206+ 'radioId ' => $ rid ,
207+ 'limit ' => $ limit ,
208+ 'offset ' => $ offset ,
209+ );
210+ $ response = $ Request ->createWebAPIRequest (
211+ "http://music.163.com " ,
212+ "/weapi/dj/program/byradio " ,
213+ 'POST ' ,
214+ $ data
215+ );
216+ return json_decode ($ response , true );
217+ }
218+
219+ }
0 commit comments