标签:
本篇主要是: 获取好友列表,群列表
我会尽量详细一点,尽我所知的分享一些可能大家已经掌握的或者还不清楚的经验
利于大家阅读,文章样式不再复杂化,根据内容取固定色
P = function (b, j) { for (var a = j + "password error", i = "", E = []; ;) if (i.length <= a.length) { if (i += b, i.length == a.length) break; } else { i = i.slice(0, a.length); break } for (var c = 0; c < i.length; c++) E[c] = i.charCodeAt(c) ^ a.charCodeAt(c); a = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; i = ""; for (c = 0; c < E.length; c++) i += a[E[c] >> 4 & 15], i += a[E[c] & 15]; return i }
传入了2个参数:QQ号码
、ptwebqq(文章2中从cookie中拿到)
http://s.web2.qq.com/api/get_user_friends2
http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1
string.Format("r={{\"vfwebqq\":\"{0}\",\"hash\":\"{1}\"}}", this.VfWebQQ, this.Hash);
返回json对象由两部分组成:retcode
、result
,前者表示请求是否成功不提,我们主要看result,里面包含了这些东西:
index
可以看做分组表的主键,sort
排序,name
该组的别名。《我的好友》分组默认是index:0flag
表示默认头像序号,后文同不提,uin
是贯穿全文的参数,是在网页关闭前,浏览器客户端的唯一标识,categories
对应上面分组信息nick
,uin
对应唯一标识uin
对应唯一标识,markname
对应备注名称,这里要说的是,如果没有备注,在这里是不显示的class JsonFriendModel { public int retcode { get; set; } public paramResult result = new paramResult(); public class paramResult { /// /// 分组信息 /// public List categories = new List(); /// /// 好友汇总 /// public List friends = new List(); /// /// 好友信息 /// public List info = new List(); /// /// 备注 /// public List marknames = new List(); /// /// 分组 /// public class paramCategories { public string index { get; set; } public int sort { get; set; } public string name { get; set; } } /// /// 好友汇总 /// public class paramFriends { public string flag { get; set; } public string uin { get; set; } public string categories { get; set; } } /// /// 好友信息 /// public class paramInfo { public string face { get; set; } public string nick { get; set; } public string uin { get; set; } } /// /// 备注 /// public class paramMarkNames { public string uin { get; set; } public string markname { get; set; } } } }
var query = from f in model.result.friends join i in model.result.info on f.uin equals i.uin into table1 from t1 in table1.DefaultIfEmpty() join m in model.result.marknames on f.uin equals m.uin into table2 from t2 in table2.DefaultIfEmpty() select new Friend() { Uin = f.uin, Face = t1 == null ? string.Empty : t1.face, Category = f.categories, Nick = t1 == null ? string.Empty : t1.nick, MarkName = t2 == null ? string.Empty : t2.markname };
以上是使用了left join 多表进行关联查询,model即对应了返回json的result属性
http://s.web2.qq.com/api/get_group_name_list_mask2
http://s.web2.qq.com/proxy.html?v=20130916001&callback=1&id=1
string.Format("r={{\"vfwebqq\":\"{0}\",\"hash\":\"{1}\"}}", this.VfWebQQ, this.Hash);
结构和获取好友有些类似,不同的是:群的唯一标识是gid,好友的是uin,名称不同。以下是对应的实体类:
class JsonGroupModel { public int retcode { get; set; } public paramResult result = new paramResult(); public class paramResult { public List gnamelist = new List(); public class paramGnamelist { public string flag { get; set; } public string gid { get; set; } public string code { get; set; } public string name { get; set; } } } }
使用C#模拟http请求可以参考猛戳这里
您有没有对这篇文章感兴趣呢?
.
一步一步来做WebQQ机器人-(四)(获取好友列表和群列表)
标签:
原文地址:http://www.cnblogs.com/lianmin/p/4237723.html