獲取QQ好友列表、QQ分組資訊、QQ群成員資料介面實現
阿新 • • 發佈:2018-12-13
完整原始碼下載
點選下載完整原始碼
如果對你有用,請給個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 + "]";
}
}
以上僅供學習參考。QQ好友列表獲取軟體 qq群交流:573714756