资源简介
java调用网易云音乐接口,并解析接口数据! 暂时只做了通过关键字搜索相关的歌曲
http请求用的是httpclient4.0以上的版本
代码片段和文件信息
package com.betawoo.core.controller;
import com.betawoo.core.commons.base.baseController;
import com.betawoo.core.commons.result.Result;
import com.betawoo.core.service.MusicLibService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.wordnik.swagger.annotations.ApiParam;
import me.uding.util.baseHttpClientUtils;
import me.uding.util.EncryptUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.BasicHttpEntity;
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.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.io.ByteArrayInputStream;
import java.util.HashMap;
/**
* Created by HuangGongguo on 2016/10/14.
*/
@Controller
@RequestMapping(value = “music“)
public class MusicLibController extends baseController {
@Autowired
MusicLibService musicLibService;
/**
* http://blog.csdn.net/qujunjie/article/details/34422379
* @param pageSize
* @param page
* @param keyWord
* @return
* @throws Exception
*/
@RequestMapping(value = “search“ method = RequestMethod.POST produces = “application/json;charset=UTF-8“)
@ResponseBody
public String searchMusic(@RequestParam(value = “pageSize“ required = true) int pageSize
@RequestParam(value = “page“ required = true) int page
@RequestParam(value = “keyWord“ required = true) String keyWord) throws Exception {
Result result = musicLibService.searchMusic(keyWord page pageSize);
return mapper.writeValueAsString(result);
// return musicLibService.searchMusic(keyWord page pageSize);
}
@RequestMapping(value = “detail“ method = RequestMethod.POST produces = “application/json;charset=UTF-8“)
@ResponseBody
public String getDetail() throws Exception {
String url = “http://music.163.com/api/song/detail/?id=287939&ids=[287939]“;
String responseJSON = baseHttpClientUtils.GET_REQUEST(url);
System.out.println(responseJSON);
return responseJSON;
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2016-10-24 09:56 第三方音乐库\
文件 2694 2016-10-15 14:05 第三方音乐库\MusicLibController.java
文件 4091 2016-10-14 17:08 第三方音乐库\MusicLibService.java
文件 774 2016-10-08 15:04 第三方音乐库\Result.java
评论
共有 条评论