菜鸟笔记
提升您的技术认知

获取所有qq好友列表以及好友信息-ag真人游戏

完整源码下载

点击下载完整源码
如果对你有用,请给个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 getall(map cookies) throws ioexception{
  
		list 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 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 cookies) {
  
		
		user user = new user();
		map 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也放一下

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   "]";
	}
	
	
}
网站地图