public override void OnHttpStatusOK(QQHttpResponse response) { JObject json = JObject.Parse(response.GetResponseString()); List <object> recents = new List <object>(); QQStore store = Context.Store; if (json["retcode"].ToString() == "0") { JArray result = json["result"].ToObject <JArray>(); for (int i = 0; i < result.Count; i++) { JObject rejson = result[i].ToObject <JObject>(); switch (rejson["type"].ToObject <int>()) { case 0: { //好友 QQBuddy buddy = store.GetBuddyByUin(rejson["uin"].ToObject <long>()); if (buddy != null) { recents.Add(buddy); } break; } case 1: { //群 QQGroup group = store.GetGroupByCode(rejson["uin"].ToObject <long>()); if (group != null) { recents.Add(group); } break; } case 2: { //讨论组 QQDiscuz discuz = store.GetDiscuzByDid(rejson["uin"].ToObject <long>()); if (discuz != null) { recents.Add(discuz); } break; } } } NotifyActionEvent(QQActionEventType.EVT_OK, recents); } else { NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.UNEXPECTED_RESPONSE)); } }
public override void OnHttpStatusOK(QQHttpResponse response) { JObject json = JObject.Parse(response.GetResponseString()); QQStore store = Context.Store; if (json["retcode"].ToString() == "0") { JArray result = json["result"].ToObject <JArray>(); for (int i = 0; i < result.Count; i++) { JObject obj = result[i].ToObject <JObject>(); long uin = obj["uin"].ToObject <long>(); string status = obj["status"].ToString(); int clientType = obj["client_type"].ToObject <int>(); QQBuddy buddy = store.GetBuddyByUin(uin); buddy.Status = QQStatus.ValueOfRaw(status); buddy.ClientType = QQClientType.ValueOfRaw(clientType); } } NotifyActionEvent(QQActionEventType.EVT_OK, store.GetOnlineBuddyList()); }
public override void OnHttpStatusOK(QQHttpResponse response) { JObject json = JObject.Parse(response.GetResponseString()); string str = JsonConvert.SerializeObject(json); int retcode = json["retcode"].ToObject <int>(); if (retcode == 0) { QQStore store = Context.Store; // 处理好友列表 JObject results = json["result"].ToObject <JObject>(); // 获取JSON列表信息 JArray jsonCategories = results["categories"].ToObject <JArray>(); // 获取JSON好友基本信息列表 flag/uin/categories JArray jsonFriends = results["friends"].ToObject <JArray>(); // face/flag/nick/uin JArray jsonInfo = results["info"].ToObject <JArray>(); // uin/markname/ JArray jsonMarknames = results["marknames"].ToObject <JArray>(); // vip_level/u/is_vip JArray jsonVipinfo = results["vipinfo"].ToObject <JArray>(); // 默认好友列表 QQCategory c = new QQCategory() { Index = 0, Name = "我的好友", Sort = 0 }; store.AddCategory(c); // 初始化好友列表 foreach (JToken t in jsonCategories) { JObject jsonCategory = t.ToObject <JObject>(); QQCategory qqc = new QQCategory(); qqc.Index = jsonCategory["index"].ToObject <int>(); qqc.Name = jsonCategory["name"].ToString(); qqc.Sort = jsonCategory["sort"].ToObject <int>(); store.AddCategory(qqc); } // 处理好友基本信息列表 flag/uin/categories foreach (JToken t in jsonFriends) { QQBuddy buddy = new QQBuddy(); JObject jsonFriend = t.ToObject <JObject>(); long uin = jsonFriend["uin"].ToObject <long>(); buddy.Uin = uin; buddy.Status = QQStatus.OFFLINE; buddy.ClientType = QQClientType.Unknown; // 添加到列表中 int category = jsonFriend["categories"].ToObject <int>(); QQCategory qqCategory = store.GetCategoryByIndex(category); buddy.Category = qqCategory; qqCategory.BuddyList.Add(buddy); // 记录引用 store.AddBuddy(buddy); } // face/flag/nick/uin foreach (JToken t in jsonInfo) { JObject info = t.ToObject <JObject>(); long uin = info["uin"].ToObject <long>(); QQBuddy buddy = store.GetBuddyByUin(uin); buddy.Nickname = info["nick"].ToString(); } // uin/markname foreach (JToken t in jsonMarknames) { JObject jsonMarkname = t.ToObject <JObject>(); long uin = jsonMarkname["uin"].ToObject <long>(); QQBuddy buddy = store.GetBuddyByUin(uin); if (buddy != null) { buddy.MarkName = jsonMarkname["markname"].ToString(); } } // vip_level/u/is_vip foreach (JToken t in jsonVipinfo) { JObject vipInfo = t.ToObject <JObject>(); long uin = vipInfo["u"].ToObject <long>(); QQBuddy buddy = store.GetBuddyByUin(uin); buddy.VipLevel = vipInfo["vip_level"].ToObject <int>(); int isVip = vipInfo["is_vip"].ToObject <int>(); if (isVip != 0) { buddy.IsVip = true; } else { buddy.IsVip = false; } } NotifyActionEvent(QQActionEventType.EVT_OK, store.GetCategoryList()); } else { // LOG.warn("unknown retcode: " + retcode); NotifyActionEvent(QQActionEventType.EVT_ERROR, new QQException(QQErrorCode.ERROR_HTTP_STATUS, "unknown retcode: " + retcode)); } }