//消息同步 private void WxSync(WebwxSyncInfo info) { if (info.AddMsgCount > 0) { foreach (var c in panUserList.Controls) { ContactItem citem = c as ContactItem; var msgs = info.AddMsgList.Where(x => x.FromUserName == citem.Name || x.ToUserName == citem.Name).ToList(); foreach (var msg in msgs) { MsgShowInfo msginfo = new MsgShowInfo { Content = msg.Content, FromUser = msg.FromUserName, ToUser = msg.ToUserName, isMe = msg.FromUserName == CurrentUser.UserName, MsgType = msg.MsgType, }; if (msginfo.isMe) { msginfo.HeadImg = pictureBox1.Image; } else if (msg.FromUserName == citem.Name) { msginfo.HeadImg = citem.Avatar; } citem.msgList.Add(msginfo); if (CurrentContact?.Name == citem.Name) { msgListShow1.Add(msginfo); if (autoReply.Checked) { SendMsg(citem.Name, "这是自动回复的消息:" + DateTime.Now.ToString()); } } break; } } } }
//开始同步检测 public void StartSyncCheck(string result) { if (!result.Contains("selector:\"0\"") || !result.Contains("retcode:\"0\"")) { WebwxSync.GetData(httpJson, DeviceID, LoginInfo, SyncKey, GetRnum(), (string json) => { WebwxSyncInfo syncInfo = JsonConvert.DeserializeObject <WebwxSyncInfo>(json); //更新同步key this.SyncKey = syncInfo.SyncKey; AjaxResult syncResult = new AjaxResult { AjaxType = AjaxTypes.WxSync, Data = syncInfo, }; OnAjaxCompleted(syncResult); WebwxSyncCheck.GetData(httpClient, DeviceID, LoginInfo, SyncKey, StartTimestamp + TimestampCount++, StartSyncCheck); }); } else { WebwxSyncCheck.GetData(httpClient, DeviceID, LoginInfo, SyncKey, StartTimestamp + TimestampCount++, StartSyncCheck); } }