完整源码下载
点击下载完整源码
如果对你有用,请给个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版实现此算法:
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实现:
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实现
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_skeyString 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也放一下
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;}@Overridepublic 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 + "]";}}
以上仅供学习参考。
QQ好友列表获取软件 qq群交流:573714756