qq群分组
完整源码下载
点击下载完整源码
如果对你有用,请给个Star,你的支持,是我最大的动力
1 获取所有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 + "]";
}
}
以上仅供学习参考。
相关阅读
打微信电话、QQ电话,对方听不到你的声音怎么办?微信和QQ是目前两款我们用的比较多的社交软件,软件功能多,其中一个就是可以用开打视
AFL技术实现分析 设计说明 American Fuzzy Lop(AFL)设计原理是不把注意力集中在任意单一的操作,也不是对任何的理论进行概念性
1.需求 2.前言 我们可以快速的实现该工作审批流程,比如通过多个if-else去判断,但是当我们审批对象发生改变了,那我们的代码又
最近有个Web项目要用离线地图,项目是在内网环境,找了很多资料,踩了很多坑,好在已经实现了,下面把资料整理一下。 首先是百度离线地图开
功能: 滚动到第二屏才出现“返回顶部”按钮; 点击“返回顶部”按钮会返回顶部,而且速度越来越慢; 在返回顶部的途中如果用鼠标滚一