乐斗获取好友信息十分简单,只需要携带cookie访问 http://fight.pet.qq.com/cgi-bin/petpk?cmd=view&kind=1&sub=1就可以了
比较难的是分析个参数的意义,需要多个好友相互对比
服务器返回如下:
{result:'0',msg:'',info:[{uin:'xxxxxxxx',flag:'0',yflag:'0',qqflag:'0',name:'乐斗菜菜', lilian:'19',enable:'1', factionid:'0'},{uin:'xxxxxxxx',flag:'0',yflag:'0',qqflag:'0',name:'乐斗小王子', lilian:'37',enable:'2', factionid:'10007'},{uin:'xxxxxxxx',flag:'0',yflag:'0',qqflag:'2',name:'Going_Down', lilian:'32',enable:'1', factionid:'235884'},................
其中uin为好友的QQ号码 ,flag没去研究 yflag为会员黄钻等信息 name为网名 lilian为等级 enable为0则已经和他打斗过 1 没有打斗过 2他有拳套,没有打斗过
factionid为帮派ID
给出代码:
获取好友
public Dictionary<string,QchongEntity> getAllFriend(){
Dictionary<string,QchongEntity> entitys =new Dictionary<string,QchongEntity>();
HttpHelper.Encoding = Encoding.GetEncoding("gb2312");
string result = HttpHelper.GetHtml("http://fight.pet.qq.com/cgi-bin/petpk?cmd=view&kind=1&sub=1", user.Cookie);
result = result.Replace("", "");
if (result !="")
{
//历练导致少取到5个号码
Regex r =new Regex("(uin:')(?<qq>[0-9]{5,11}?)(',flag:'[0-9]{1}',yflag:'[0-9]{1}',qqflag:')(?<qqflag>[0-9]{1}?)(',name:')"
+"(?<name>.+?)(',lilian:')(?<lilian>[0-9]{1,2}?)(',enable:')(?<enable>[0-9]{1}?)(',factionid:')(?<factionid>[0-9]{1,6}?)(')", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
MatchCollection m = r.Matches(result);
for (int i =0; i < m.Count; i++)
{
try
{
QchongEntity entity =new QchongEntity();
entity.UserName = m[i].Groups["qq"].Value;
entity.Qqflag = Convert.ToInt32(m[i].Groups["qqflag"].Value);
entity.NickName = m[i].Groups["name"].Value;
entity.Liliang = m[i].Groups["lilian"].Value;
entity.Factionid = m[i].Groups["factionid"].Value;
entity.Enable = Convert.ToInt32(m[i].Groups["enable"].Value);
entitys.Add(entity.UserName,entity);
}
catch (Exception)
{
continue;
}
}
}
AllFriend = entitys;
return entitys;
}