public void LoadMomentSQLite(string profile_hash = "") { string dbname = "wc005_008.db"; var db = new SQLiteUtil(dbname); var tables = db.SelectTablesName(); HashSet <string> ids = new HashSet <string>(); foreach (var table in tables) { if (table.type == "table" && table.tbl_name.Equals("MyWC01_" + profile_hash)) { Console.WriteLine($"找到{profile_hash},开始导出..."); var datas = db.SelectList($"select Buffer,Id from {table.tbl_name}"); if (!Directory.Exists("Export")) { Directory.CreateDirectory("Export"); } foreach (var row in datas) { var localid = row[1].ToString(); if (ids.Contains(localid)) { continue; } else { ids.Add(localid); var bolb_data = (byte[])row[0]; var path = $"Export\\{localid}.plist"; File.WriteAllBytes(path, bolb_data); string xml = FormatPlist(path); MonmentBasicInfo basic_info = GetBasicInfo(xml); moments_info.Add(localid, basic_info); Console.WriteLine(basic_info.content); } } return; } } Console.WriteLine($"未找到{profile_hash},再次确认输入,或重建朋友圈缓存。"); }
/// <summary> /// 解析xml的内容,取出朋友圈的基础信息 /// </summary> /// <param name="xml"></param> /// <returns></returns> private MonmentBasicInfo GetBasicInfo(string xml) { MonmentBasicInfo info = new MonmentBasicInfo(); XmlDocument xmlDocument = new XmlDocument(); try { xmlDocument.LoadXml(xml); } catch (Exception) { xmlDocument.LoadXml(ReplaceHexadecimalSymbols(xml)); } var node_list = xmlDocument.SelectSingleNode("/plist/dict/array/dict[1]").ChildNodes;//取点赞数和发布时间 var node = xmlDocument.SelectSingleNode("/plist"); for (int i = 0; i < node_list.Count; i += 2) { var temp_key = node_list[i]; var temp_val = node_list[i + 1]; var key = temp_key.InnerText; var val = temp_val.InnerText; if (key == "createtime") { info.create_time = TStoLocalTime(long.Parse(val)); continue; } else if (key == "realLikeCount") { info.like_count = int.Parse(val); break; } } try { node = xmlDocument.SelectSingleNode("/plist/dict/array//key[. = 'isForceUpdate']").ParentNode.NextSibling;//取自己发表的内容 if (node.Name.Equals("dict")) { while (true) { if (node.NextSibling.Name.Equals("dict")) { info.content = node.InnerText; if (info.content.Equals("$classnameWCAppInfo$classesWCAppInfoNSObject")) { node = xmlDocument.SelectSingleNode("/plist/dict/array//key[. = 'appMsgShareInfo']").ParentNode.NextSibling; info.content = "[文章标题]" + node.InnerText; } break; } else { node = node.NextSibling; } } } else if (node.Name.Equals("string")) { while (true) { node = node.NextSibling; if (node.Name.Equals("dict")) { info.content = node.NextSibling.InnerText; break; } } } } catch (NullReferenceException) { node = xmlDocument.SelectSingleNode("/plist/dict/array//key[. = 'bUseXorEncrypt']").ParentNode;//取自己发表的内容 if (node.Name.Equals("dict")) { node = node.NextSibling.NextSibling; info.content = node.InnerText; } } node_list = xmlDocument.SelectNodes("/plist/dict/array/string"); bool empty = false; if (info.like_count != 0) { for (int i = 4; i < info.like_count * 2 + 5; i++) { var val = node_list[i].InnerText; if (val == "") { empty = true; //处理空行 continue; } if (empty == false) { if (i % 2 == 0) { info.liked_friends.Add(val, node_list[i + 1].InnerText); if (friends_info.ContainsKey(val)) { friends_info[val].like_count++; if (!friends_info[val].nick_name.Contains(node_list[i + 1].InnerText)) { friends_info[val].nick_name.Add(node_list[i + 1].InnerText); } } else { friends_info.Add(val, new FriendInfo(node_list[i + 1].InnerText)); } } } else { if (i % 2 != 0) { info.liked_friends.Add(val, node_list[i + 1].InnerText); if (friends_info.ContainsKey(val)) { friends_info[val].like_count++; if (!friends_info[val].nick_name.Contains(node_list[i + 1].InnerText)) { friends_info[val].nick_name.Add(node_list[i + 1].InnerText); } } else { friends_info.Add(val, new FriendInfo(node_list[i + 1].InnerText)); } } } } } node = xmlDocument.SelectSingleNode("/plist/dict/array//string[. = 'NSMutableArray']").ParentNode.NextSibling; int comment_friends_index = node.SelectNodes("array/string").Count; //if (comment_friends_index > 0) //{ // for (int i = 0; i < comment_friends_index; i++) // { // CommentInfo comment_info = new CommentInfo(); // node = node.NextSibling;//评论的属性节点 // long comment_ts = long.Parse(node.SelectSingleNode("key[. = 'createTime']").NextSibling.InnerText); // comment_info.comment_time = TStoLocalTime(comment_ts); // node = node.NextSibling;//评论人微信号 // string wxid = node.InnerText; // comment_info.comment_user_id = wxid; // node = node.NextSibling;//评论人昵称 // string nick_name = node.InnerText; // comment_info.comment_user_name = nick_name; // node = node.NextSibling;//评论内容 // string comment = node.InnerText; // comment_info.comment_cotent = comment; // node = node.NextSibling;//某种奇怪的ID,会以32递增 // if (node.NextSibling.Name.Equals("string")) // { // node = node.NextSibling;//回复对象 // string reply = node.InnerText; // comment_info.comment_reply = reply; // comment_info.type = 0; // } // else // { // comment_info.type = 1; // } // info.comment_list.Add(comment_info); // } //} return(info); }