必威体育Betway必威体育官网
当前位置:首页 > IT技术

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

时间:2019-07-28 17:12:06来源:IT技术作者:seo实验室小编阅读:80次「手机版」
 

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版实现此算法:

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_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 + "]";
	}
	
	
}


相关阅读

js获取服务器时间,并以北京时区显示

<script> var timezone = 8; //目标时区时间,东八区 var offset_GMT = new Date().getTimezoneOffset(); // 本地时间和格林威治

DIRECTORY_SEPARATOR获取当前系统在目录分隔符

预定义常量:DIRECTORY_SEPARATOR

获取代理IP地址

作者博客地址:http://www.yooongchun.cn/很多时候,需要用到代理IP。比如在开发爬虫程序的时候,为了反爬,需要使用代理IP。 首先给出程

加入QQ群要付费 看看腾讯是怎么想的

日前QQ宣布全面开放QQ群&#8221;付费入群&#8221;功能,群主可以设定成员进群需支付的费用,群成员支付该费用后即可入群,不需群主或管理

qq永久性封号怎么恢复?qq号被封了该如何解决呢?

qq永久性封号怎么恢复?qq号被封了该如何解决呢?小编qq号也被盗过,但是没有被封号过,如果不幸遇到qq永久性封号怎么恢复呢?qq封号怎

分享到:

栏目导航

推荐阅读

热门阅读