-
分析部分
- 代碼實現部分
- 更具上面的分析,我們首先需要實現數據模型(好友和分組信息)
public class QQGroupMemberInfo
{public string QQ
{get;
set;
}
public string NickName
{get;
set;
}
}
/// <summary>/// QQ好友/// </summary>public class QQFriendMember : QQGroupMemberInfo
{public int FriendGroupId { get; set; }
}
/// <summary>/// 好友分組/// </summary>public class QQFiendGroup
{public string Name { get; set; }
public int GroupId { get; set; }
public int SortId { get; set; }
}
/// <summary>/// 好友信息返回模型/// </summary>public class QQFriendInfo
{public QQFriendInfo(){GroupInfos = new List<QQFiendGroup>();QQFriends = new List<QQFriendMember>();}
public List<QQFiendGroup> GroupInfos { get; set; }public List<QQFriendMember> QQFriends { get; set; }}
- 提交GET請求,獲取數據
string friendUrl = string.Format("http://r.cnc.qzone.qq.com/cgi-bin/tfriend/friend_mngfrd_get.cgi?uin={0}", _cleintKeyInfo.ClientUin);
string jsonF = GetWebData<string>(friendUrl);
- 使用Javascript運行時解析數據
- 獲取解析數據
StringBuilder script = new StringBuilder();script.AppendLine("function _Callback(o){return o; };");script.AppendLine(jsonF);
var data = JavaScriptEngine.Run(script.ToString()) as Dictionary<string, object>;
var gpnames = data["gpnames"] as object[];//組信息
var items = data["items"] as object[];//好友信息
//遍歷組foreach (var g in gpnames)
{var gitem = (g as Dictionary<string, object>);
qfi.GroupInfos.Add(new QQFiendGroup(){GroupId = int.Parse(gitem["gpid"].ToString()),
Name = gitem["gpname"].ToString(),SortId = int.Parse(gitem["sortid"].ToString())
});
}
//遍歷成員foreach (var f in items)
{var fitem = (f as Dictionary<string, object>);
qfi.QQFriends.Add(new QQFriendMember(){FriendGroupId = int.Parse(fitem["groupid"].ToString()),
NickName = fitem["name"].ToString(),QQ = fitem["uin"].ToString()});
}
- 更具上面的分析,我們首先需要實現數據模型(好友和分組信息)
- 總結
- 其實QQ的數據是比較好獲取的,只是登陸比較困難而已,關於登陸部分實現,我blog前面的一些文章已經實現過了,這里不再羅嗦
- 對於HTTP協議的數據分析,主要使用HTTP協議分析工具來解析,再結合瀏覽器的控制台來分析





