获取所有QQ好友列表以及好友信息

完整源码下载

点击下载完整源码
如果对你有用,请给个Star,你的支持,是我最大的动力

1 获取所有QQ

这里主要通过抓包,抓取QQ空间中的数据
记得将访问空间权限改为QQ好友

接口地址:
https://h5.qzone.qq.com/proxy/domain/base.qzone.qq.com/cgi-bin/right/get_entryuinlist.cgi?uin=741047261&fupdate=1&action=1&offset=0&g_tk=847821819&qzonetoken=24dd9cbc92e1ba657addcd982f7f4d0fa1a9ee8ba7b8d52863703a10274f08f9325d1298e5afac11

这里uin 为你的QQ号
offset 偏移量 ,每次增加 50 即可
g_tk是从cookie中获取的 p_skey 再通过算法获得;

java版实现此算法:

1
2
3
4
5
6
7
8
9
10
11
public class GetTk {

public static String getTk(String skey) {
int hash = 5381;
for(int i = 0, len = skey.length(); i < len; ++i){
hash += (hash << 5) + (int)(char)skey.charAt(i);
}
return (hash & 0x7fffffff)+"";
}

}

完整版java实现:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.pibigstar.qq.main;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.pibigstar.qq.domain.User;
import com.pibigstar.qq.utils.GetCookies;
import com.pibigstar.qq.utils.GetTk;
import com.pibigstar.qq.utils.JSONUtil;

/**
* 获取所有的QQ用户列表
* @author pibigstar
*
*/
public class GetAllUser {

public static List<User> getAll(Map<String, String> cookies) throws IOException{
List<User> allUser = new ArrayList<>();
String qq = cookies.get("o_cookie");
String pskey = cookies.get("p_skey");

String g_tk = GetTk.getTk(pskey);

for(int i=0;;) {
Document document = Jsoup.connect("https://h5.qzone.qq.com/proxy/domain/base.qzone.qq.com/cgi-bin/right/get_entryuinlist.cgi?uin=741047261&fupdate=1&action=1&offset="+i+"&g_tk="+g_tk).cookies(cookies).header("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36").timeout(10000).ignoreContentType(true).get();
String strJson = document.getElementsByTag("body").text().replace("_Callback(", "").replace(");", "");
JSONObject jsonObject = new JSONObject(strJson);
String jsonData =((JSONObject) jsonObject.get("data")).get("uinlist").toString();
List<User> users = JSONUtil.JSONToList(jsonData, User.class);
if (users==null||users.size()==0) {
break;
}
allUser.addAll(users);
i+=50;
}
return allUser;
}

}

2 获得QQ信息

接口地址:
http://cgi.find.qq.com/qqfind/buddy/search_v3

post请求,需要两个参数:
keyword : 你要查询的QQ号码
lwd : g_tk 值

注意:此g_tk 的值为 cookie中 skey 计算得来的 而不是 p_skey

java实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.pibigstar.qq.main;

import java.io.IOException;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import com.pibigstar.qq.domain.User;
import com.pibigstar.qq.utils.GetTk;
import com.pibigstar.qq.utils.JSONUtil;

public class GetInfo{
public static User getInfo(String qq,Map<String, String> cookies) {

User user = new User();
Map<String, String> data = new HashMap<>();
//注意这里,获得信息是用的skey 而获得全部好友使用的为p_skey
String skey = cookies.get("skey");
String g_tk = GetTk.getTk(skey);

data.put("keyword", qq);
data.put("ldw", g_tk);

Document document;
try {
document = Jsoup.connect("http://cgi.find.qq.com/qqfind/buddy/search_v3").cookies(cookies).header("user-agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36").ignoreContentType(true).data(data).timeout(10000).post();
String allJson = document.getElementsByTag("body").text();
System.out.println(allJson);
JSONObject result = (JSONObject) new JSONObject(allJson).get("result");
JSONObject buddy = (JSONObject) result.get("buddy");
JSONArray jsonArray = buddy.getJSONArray("info_list");

JSONObject dataJson = (JSONObject) jsonArray.get(0);
user = JSONUtil.jSONToObject(dataJson.toString(), User.class);
JSONObject birthdayJson = (JSONObject) dataJson.get("birthday");
String year = birthdayJson.get("year").toString();
String month = birthdayJson.get("month").toString();
String day = birthdayJson.get("day").toString();
String birthday = year+"-"+month+"-"+day;
user.setBirthday(birthday);

Calendar calendar = Calendar.getInstance();
int now = calendar.get(Calendar.YEAR);

if (year!=null&&year.length()>0) {
int age = now - Integer.parseInt(year);
user.setAge(age);
}
} catch (IOException e) {
e.printStackTrace();
}
return user;
}

}

把user的bean也放一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package com.pibigstar.qq.domain;

public class User {

private String data;//QQ号

private String label;//用户名/备注名

private String nick;//昵称

private String gender;//性别 1为男 2为女

private String city;//城市

private String country;//国家

private String lnick;//个性签名

private String personal;//个人说明

private String college;//学校

private String birthday;//生日

private String email;//邮箱

private String phone;//手机

private String uin;//qq号

private int age;


public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public String getUin() {
return uin;
}

public void setUin(String uin) {
this.uin = uin;
}

public String getData() {
return data;
}

public void setData(String data) {
this.data = data;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public String getNick() {
return nick;
}

public void setNick(String nick) {
this.nick = nick;
}

public String getGender() {
return gender;
}

public void setGender(String gender) {
this.gender = gender;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getCountry() {
return country;
}

public void setCountry(String country) {
this.country = country;
}

public String getLnick() {
return lnick;
}

public void setLnick(String lnick) {
this.lnick = lnick;
}

public String getPersonal() {
return personal;
}

public void setPersonal(String personal) {
this.personal = personal;
}

public String getCollege() {
return college;
}

public void setCollege(String college) {
this.college = college;
}

public String getBirthday() {
return birthday;
}

public void setBirthday(String birthday) {
this.birthday = birthday;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

@Override
public String toString() {
return "User [data=" + data + ", label=" + label + ", nick=" + nick + ", gender=" + gender + ", city=" + city
+ ", country=" + country + ", lnick=" + lnick + ", personal=" + personal + ", college=" + college
+ ", birthday=" + birthday + ", email=" + email + ", phone=" + phone + "]";
}


}
-------------本文结束感谢您的阅读-------------