Skip to content

Commit

Permalink
发布版本1.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhua10 committed Feb 10, 2022
1 parent 7935138 commit f993fa5
Show file tree
Hide file tree
Showing 9 changed files with 187 additions and 101 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,23 @@ CSDN 博客 :[Java版本中最好用的网易云音乐、qq音乐api请求工
本项目中使用到的依赖:
spring-web、lombok、fastjson
```xml
<!-- 爬虫框架jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<!-- spring-web依赖,这个工具需要使用里面的RestTemplate工具 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.2</version>
<version>5.3.14</version>
</dependency>
<!-- fastjson 工具类 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
<version>1.2.79</version>
</dependency>
<!-- lombok -->
<dependency>
Expand All @@ -41,7 +47,7 @@ gav坐标如下
<dependency>
<groupId>top.yumbo.music</groupId>
<artifactId>yumbo-music-utils</artifactId>
<version>1.2.1</version>
<version>1.2.3</version>
</dependency>
```
### 第二步、使用NeteaseCloudMusicInfo类和 QQMusicInfo类调用封装好的方法
Expand Down
57 changes: 48 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!--当前项目的gav坐标-->
<groupId>top.yumbo.music</groupId>
<artifactId>yumbo-music-utils</artifactId>
<version>1.2.1</version>
<version>1.2.3</version>
<packaging>jar</packaging><!--打包方式 jar/war/pom-->
<name>yumbo-music-utils</name><!--项目名称-->
<description>netease-cloud-music and qq-music api-utils</description>
Expand Down Expand Up @@ -59,6 +59,30 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
top.yumbo.util.NeteaseCloudMusicDemo
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<!-- 编译插件,设置源码以及编译的jdk版本 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down Expand Up @@ -135,23 +159,38 @@
</build>
<!--以上部分都不需要进行修改-->
<dependencies>
<!-- &lt;!&ndash; 爬虫框架jsoup &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.jsoup</groupId>-->
<!-- <artifactId>jsoup</artifactId>-->
<!-- <version>1.13.1</version>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.seleniumhq.selenium</groupId>-->
<!-- <artifactId>selenium-java</artifactId>-->
<!-- <version>4.0.0-alpha-7</version>-->
<!-- </dependency>-->

<!-- &lt;!&ndash; https://mvnrepository.com/artifact/org.apache.commons/commons-email &ndash;&gt;-->
<!-- <dependency>-->
<!-- <groupId>org.apache.commons</groupId>-->
<!-- <artifactId>commons-email</artifactId>-->
<!-- <version>1.5</version>-->
<!-- </dependency>-->

<!-- 爬虫框架jsoup -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.14.3</version>
</dependency>
<!-- spring-web依赖,这个工具需要使用里面的RestTemplate工具 -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.2</version>
<version>5.3.14</version>
</dependency>
<!-- fastjson 工具类 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.75</version>
<version>1.2.79</version>
</dependency>
<!-- lombok -->
<dependency>
Expand Down
109 changes: 70 additions & 39 deletions src/main/java/top/yumbo/util/NeteaseCloudMusicDemo.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,37 @@
package top.yumbo.util;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import top.yumbo.util.music.MusicEnum;
import top.yumbo.util.music.annotation.MusicService;
import top.yumbo.util.music.musicImpl.netease.NeteaseCloudMusicInfo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;


public class NeteaseCloudMusicDemo {

final static NeteaseCloudMusicInfo neteaseCloudMusicInfo = new NeteaseCloudMusicInfo();// 得到封装网易云音乐信息的工具类

public static void main(String[] args) {

// MusicEnum.setBASE_URL_163Music("http://localhost:3000");

final JSONObject jsonObject = new JSONObject();
jsonObject.put("phone", "18279774965");
jsonObject.put("password", "qvAUEmG2ABtXeCk");
final JSONObject login = neteaseCloudMusicInfo.loginCellphone(jsonObject);

System.out.println(login);

// final JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("id","557581284");
//
// final JSONObject jsonObject2 = neteaseCloudMusicInfo.songUrl(jsonObject1);
//
// System.out.println(jsonObject2.getJSONArray("data").getJSONObject(0).get("url"));

// final JSONObject jsonObject = new JSONObject();
// jsonObject.put("phone", "15727742367");
// jsonObject.put("password", "yjh123456");
// final JSONObject login = neteaseCloudMusicInfo.loginCellphone(jsonObject);
// System.out.println(login);
// final Object uid = login.getJSONObject("account").get("id");
// System.out.println(uid);
// final JSONObject param = new JSONObject();
// param.put("id","509512457");
// param.put("br","999000");
// final JSONObject songUrl = neteaseCloudMusicInfo.songUrl(param);
// System.out.println(songUrl);
// if (uid != null) {
// final JSONObject json = new JSONObject();
// json.put("uid",uid);
Expand All @@ -55,29 +57,29 @@ public static void main(String[] args) {
// String str = "[__csrf=a477072e738bf52da6a3d801fc5f3a47; Max-Age=1296010; Expires=Fri, 22 Jan 2021 18:39:15 GMT; Path=/;, __remember_me=true; Max-Age=1296000; Expires=Fri, 22 Jan 2021 18:39:05 GMT; Path=/;, NMTID=00OvgEvVmJMiskHd0_Fo-XEgTr10ccAAAF23iUnxg; Max-Age=315360000; Expires=Sun, 5 Jan 2031 18:39:05 GMT; Path=/;, MUSIC_U=7b27b6de49d6e80338be47f8ffeb967f298c85f75f738dd735af463ef19d96830931c3a9fbfe3df2; Max-Age=1296000; Expires=Fri, 22 Jan 2021 18:39:05 GMT; Path=/;]";


final JSONObject parameter = new JSONObject();// 请求参数
parameter.put("keywords", "我还年轻");
final JSONObject jsonObject = neteaseCloudMusicInfo.cloudsearch(parameter);// 调用网易云的热搜服务
final JSONArray result = jsonObject.getJSONObject("result").getJSONArray("songs");
final StringBuilder ids = new StringBuilder();
result.stream().map(s -> {
JSONObject song = (JSONObject) s;
final JSONObject music = new JSONObject();
final int id = song.getIntValue("id");
ids.append("," + id);
music.put("musicId", id);
music.put("songName", song.getString("name"));
music.put("mvId", song.get("mv"));// mv的id
final int dt = song.getIntValue("dt");
music.put("durationTime", dt);// 时长,单位毫秒
final JSONObject al = song.getJSONObject("al");
music.put("albumName", al.getString("name"));// 专辑名称
music.put("singer", song.getJSONArray("ar"));// 歌手

return music;
}).forEach(System.out::println);
final JSONObject jsonObject1 = new JSONObject();
jsonObject1.put("k1", "v1");
// final JSONObject parameter = new JSONObject();// 请求参数
// parameter.put("keywords", "我还年轻");
// final JSONObject jsonObject = neteaseCloudMusicInfo.cloudsearch(parameter);// 调用网易云的热搜服务
// final JSONArray result = jsonObject.getJSONObject("result").getJSONArray("songs");
// final StringBuilder ids = new StringBuilder();
// result.stream().map(s -> {
// JSONObject song = (JSONObject) s;
// final JSONObject music = new JSONObject();
// final int id = song.getIntValue("id");
// ids.append("," + id);
// music.put("musicId", id);
// music.put("songName", song.getString("name"));
// music.put("mvId", song.get("mv"));// mv的id
// final int dt = song.getIntValue("dt");
// music.put("durationTime", dt);// 时长,单位毫秒
// final JSONObject al = song.getJSONObject("al");
// music.put("albumName", al.getString("name"));// 专辑名称
// music.put("singer", song.getJSONArray("ar"));// 歌手
//
// return music;
// }).forEach(System.out::println);
// final JSONObject jsonObject1 = new JSONObject();
// jsonObject1.put("k1", "v1");
// collect.add(jsonObject1);
// System.out.println(collect);

Expand All @@ -99,4 +101,33 @@ public static void main(String[] args) {
// System.out.println(recommendSongs);

}

// private static void Imgcheck(WebDriver ptlogin_iframe) {
// try {
// try {
// TimeUnit.SECONDS.sleep(2);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// final WebDriver tcaptcha_iframe = ptlogin_iframe.switchTo().frame("tcaptcha_iframe");
// final WebElement tcaptcha_drag_button = tcaptcha_iframe.findElement(By.id("tcaptcha_drag_button"));
// final Random random = new Random(20);
// for (int i = 22; i < 190; i++) {
// try {
// final int i1 = random.nextInt();
// System.out.println(i1);
// TimeUnit.MICROSECONDS.sleep(i1);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// tcaptcha_drag_button.click();
// ((JavascriptExecutor) tcaptcha_iframe).executeScript("document.getElementById(\"slideBlock\").style.left='" + i + "px'");
// ((JavascriptExecutor) tcaptcha_iframe).executeScript("document.getElementById(\"tcaptcha_drag_button\").style.left='" + (i + 1) + "px'");
// }
//
//
// } catch (Exception e) {
// System.out.println("=====》报异常了");
// }
// }
}
8 changes: 2 additions & 6 deletions src/main/java/top/yumbo/util/OtherMusicDemo.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package top.yumbo.util;

import com.alibaba.fastjson.JSONObject;
import top.yumbo.util.music.musicImpl.other.OtherMusicInfo;

public class OtherMusicDemo {

public static void main(String[] args) {
final OtherMusicInfo otherMusicInfo = new OtherMusicInfo();
final JSONObject jsonObject = otherMusicInfo.noParameterMethod();
System.out.println(jsonObject);


}

}
18 changes: 12 additions & 6 deletions src/main/java/top/yumbo/util/QQMusicDemo.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package top.yumbo.util;

import com.alibaba.fastjson.JSONObject;
import org.springframework.web.client.RestTemplate;
import top.yumbo.util.music.musicImpl.qq.QQMusicInfo;

public class QQMusicDemo {
Expand All @@ -10,12 +11,17 @@ public static void main(String[] args) {
QQMusicInfo qqMusicInfo=new QQMusicInfo();
// 将cookie字符串复制到这个变量中,通过setCookieString给请求添加cookie
String cookie="pgv_si=s4824704000; pgv_pvi=1565352960; pgv_info=ssid=s774626425; pgv_pvid=8407309622; yqq_stat=0; ts_refer=www.dogedoge.com/; ts_uid=9112305655; _qpsvr_localtk=0.5849658206781931; RK=BQLlc4tDO+; ptcz=dc9cc74df2c3385602d0fa3a6039c369e0213fe241428ef02910b7af67e7bba5; uin=o1015770492; qqmusic_fromtag=6; qqmusic_uin=1015770492; gpqqcomrouteLine=cg10pc; eas_sid=Q1w6f0m9p0k9o8N1r4r7f47790; ied_qq=o1015770492; Qs_lvt_323937=1609098171; Qs_pv_323937=504240020140402900; qqmusic_key=@7i3RoudTf; skey=@Se84fEkYb; ts_last=y.qq.com/portal/radio.html; userAction=1";
qqMusicInfo.setCookieString(cookie);// 添加完cookie表示登录成功了,下面我们调用一个需要登录的接口测试一下
final JSONObject json = new JSONObject();
json.put("id","1015770492");// 这个接口需要传入qq号,也就是当初cookie对于的qq号信息
final JSONObject userSonglist = qqMusicInfo.userSonglist(json);
System.out.println(userSonglist);

// qqMusicInfo.setCookieString(cookie);// 添加完cookie表示登录成功了,下面我们调用一个需要登录的接口测试一下
// final JSONObject json = new JSONObject();
// json.put("id","1015770492");// 这个接口需要传入qq号,也就是启动qq服务器配置的qq号,cookie的qq与配置服务器的qq要一致,防止被他人登录
// final JSONObject userSonglist = qqMusicInfo.userSonglist(json);
// System.out.println(userSonglist);
String id="0039MnYb0qxYhV";
final RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject("https://c.y.qq.com/v8/fcg-bin/fcg_play_single_song.fcg?songmid=" + id + "&format=json", String.class);
final JSONObject jsonObject = JSONObject.parseObject(result);
final Object o = jsonObject.getJSONArray("data").getJSONObject(0).getJSONObject("file").get("media_mid");
System.out.println(o);

// final JSONObject jsonObject = qqMusicInfo.searchHot();
// System.out.println(jsonObject);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
import org.springframework.web.client.RestTemplate;
import top.yumbo.util.music.MusicEnum;
import top.yumbo.util.music.musicAbstract.AbstractMusic;
import top.yumbo.util.music.musicImpl.netease.NeteaseCloudMusicInfo;

import java.lang.reflect.Method;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;

public class YumboAnnotationUtils {



/**
* 发送请求并且注入json对象
*
Expand Down
Loading

0 comments on commit f993fa5

Please sign in to comment.