首页>代码>spring boot+spring mvc+spring整合开发QQ音乐微信小程序(含简单服务端)>/music源码/后端源码/music/src/main/java/com/xin/music/controller/SongController.java
package com.xin.music.controller;
import com.xin.music.constant.Constant;
import com.xin.music.utils.ResultVOUtils;
import com.xin.music.utils.SongUtils;
import com.xin.music.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* 音乐接口
*/
@RestController
@RequestMapping(Constant.prefixRequest + "song")
@Slf4j
public class SongController {
/**
* 热门歌曲
*/
@GetMapping(value = "/popular/songs/tid/{tid}")
public String popularSongs(@PathVariable("tid") String tid) throws IOException {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
String url = "https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg?disstid="+tid;
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Content-Type","application/jsonp");
httpGet.setHeader("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
httpGet.setHeader("referer", "https://c.y.qq.com/qzone/fcg-bin/fcg_ucc_getcdinfo_byids_cp.fcg");
CloseableHttpResponse response = httpclient.execute(httpGet);
try {
HttpEntity entity = response.getEntity();
//打印目标网站输出内容
return EntityUtils.toString(entity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
/**
* 解析热门歌曲列表
*/
@GetMapping(value = "/analy/songs/tid/{tid}")
public ResultVO analySongs(@PathVariable("tid")String tid) throws IOException {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
String url = "https://y.qq.com/n/m/detail/taoge/index.html?ADTAG=myqq&from=myqq&channel=10007100&id="+tid;
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Content-Type","application/jsonp");
CloseableHttpResponse response = httpclient.execute(httpGet);
try {
HttpEntity entity = response.getEntity();
String songs = SongUtils.analySongs(EntityUtils.toString(entity));
return ResultVOUtils.success(songs);
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
/**
* 音乐搜索
* @param key
* @return
* @throws IOException
*/
@GetMapping(value = "/search/song/key/{key}")
public ResultVO searchMusic(@PathVariable("key")String key) throws IOException {
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
String url = "https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp?_=1555419255194&g_tk=5381&uin=0&format=json&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=h5&needNewCode=1&w="+key+"&zhidaqu=1&catZhida=1&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1&remoteplace=txt.mqq.all";
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("Content-Type","application/jsonp");
httpGet.setHeader("user-agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36");
httpGet.setHeader("origin","http://c.y.qq.com");
httpGet.setHeader("referer", "https://c.y.qq.com/soso/fcgi-bin/search_for_qq_cp");
CloseableHttpResponse response = httpclient.execute(httpGet);
try {
HttpEntity entity = response.getEntity();
//打印目标网站输出内容
return ResultVOUtils.success(EntityUtils.toString(entity));
// EntityUtils.consume(entity);
} finally {
response.close();
}
} finally {
httpclient.close();
}
}
}
最近下载更多
最近浏览更多
cxz2132132 LV11
10月10日
微信网友_7044194812350464 LV8
9月8日
1140717565 LV2
7月18日
空中飞尘 LV13
7月8日
sgm123456 LV14
5月26日
dushine LV3
4月14日
ma406805131 LV19
2月21日
lvyga1 LV2
1月6日
krispeng LV15
2024年12月18日
yinianhuakai4 LV8
2024年12月16日

