private void LsvWxLoggedin_Click(object sender, EventArgs e) { currentWxInfoEntity = (WX_Info_Entity)lsvWxLoggedin.SelectedItems[0].Tag; SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_FRIEND_INFO, "0"); SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_GROUP_INFO, "0"); }
/// <summary> /// 通过进程判断微信是否闪退 /// </summary> /// <param name="wxList"></param> /// <returns></returns> private bool CheckWxOnline(WX_Info_Entity wx) { int pID = CommonUtil.TranNull <int>(wx.WxProcessID); Process p = Process.GetProcessById(pID); if (p == null) { return(false); } return(true); }
private void SendWeDllCmd(WX_Info_Entity wx, int type, string msg) { byte[] buff = new byte[1004]; byte[] b1 = BitConverter.GetBytes(type); byte[] b2 = Encoding.UTF8.GetBytes(msg); Array.Copy(b1, buff, 4); Array.Copy(b2, 0, buff, 4, b2.Length); socketClient.SendTo(buff, wx.Addr); }
private void HandMessagecb(int type, string msg, EndPoint clientOfReceiveFrom) { LogHelper.LogUtil.WXHOOKUI.InfoFormat("HandMessagecb ClientOfReceiveFrom: [{2}], type: [{0}], msg: [{1}]", type, msg, clientOfReceiveFrom); ListViewItem lvi = new ListViewItem(); lvi.Text = "0"; lvi.SubItems.Add(type.ToString()); lvi.SubItems.Add(msg); this.lv_recv_msg.Items.Add(lvi); if (type == 2) { string[] wxinfoDetail = msg.Split('|'); WX_Info_Entity wxInfoEntity = new WX_Info_Entity() { WxID = wxinfoDetail[wxinfoDetail.Length - 3], WxNickName = wxinfoDetail[wxinfoDetail.Length - 2], WxProcessID = wxinfoDetail[wxinfoDetail.Length - 1], LoginTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), Addr = clientOfReceiveFrom }; if (wxLoggedinList.Count == 0 && currentWxInfoEntity == null) { currentWxInfoEntity = wxInfoEntity; } wxLoggedinList.Add(wxInfoEntity); ListViewItem lviWxLoggedin = new ListViewItem(); lviWxLoggedin.Text = wxInfoEntity.WxID; lviWxLoggedin.Tag = wxInfoEntity; lviWxLoggedin.SubItems.Add(wxInfoEntity.WxNickName); lviWxLoggedin.SubItems.Add(wxInfoEntity.WxProcessID); lsvWxLoggedin.BeginUpdate(); lsvWxLoggedin.Items.Add(lviWxLoggedin); lsvWxLoggedin.EndUpdate(); lb_online.Text = "当前在线微信:" + wxLoggedinList.Count; SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_MSG_READ, ""); } if (type == (int)WX_CMD.WX_CMD_TYPE_E_MSG_READ_ACK) { if (msg == "END") { MyThread tmp = new MyThread(new ParameterizedThreadStart(get_msg_rcv)); tmp.Start(0); } else { SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_MSG_READ, ""); } } //好友列表 if (type == (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_FRIEND_INFO_ACK) { if (msg.Equals("END", StringComparison.OrdinalIgnoreCase)) { LogHelper.LogUtil.WXHOOKUI.InfoFormat("FriendList count: [{0}]", currentWxInfoEntity.FriendList.Count); lsvFriend.Items.Clear(); lsvFriend.BeginUpdate(); foreach (FriendInfo_Entity friend_Info in currentWxInfoEntity.FriendList) { ListViewItem lviFriend = new ListViewItem(); lviFriend.Text = friend_Info.Nick; lviFriend.SubItems.Add(friend_Info.Friend_Orig_ID); lsvFriend.Items.Add(lviFriend); } lsvFriend.EndUpdate(); } else { var friendList = msg.Split('|'); int friendIndex = CommonUtil.TranNull <int>(friendList[0]); friendIndex = friendIndex + 1; FriendInfo_Entity friendInfo = new FriendInfo_Entity() { Friend_Orig_ID = friendList[1], Friend_ID = friendList[2], V_ID = friendList[3], Nick = friendList[4], Remark = friendList[5], Sex = friendList[6] }; currentWxInfoEntity.FriendList.Add(friendInfo); SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_FRIEND_INFO, friendIndex.ToString()); } } //群列表 if (type == (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_GROUP_INFO_ACK) { if (msg.Equals("END", StringComparison.OrdinalIgnoreCase)) { LogHelper.LogUtil.WXHOOKUI.InfoFormat("GroupList count: [{0}]", currentWxInfoEntity.GroupList.Count); lsvGroup.Items.Clear(); lsvGroup.BeginUpdate(); foreach (GroupInfo_Entity groupInfo in currentWxInfoEntity.GroupList) { ListViewItem lviGroup = new ListViewItem(); lviGroup.Text = string.Format("{0} ({1})", groupInfo.Nick, groupInfo.MemberNumber); lviGroup.SubItems.Add(groupInfo.Group_Orig_ID); lsvGroup.Items.Add(lviGroup); } lsvGroup.EndUpdate(); } else { var groupList = msg.Split('|'); int groupIndex = CommonUtil.TranNull <int>(groupList[0]); groupIndex = groupIndex + 1; GroupInfo_Entity groupInfo = new GroupInfo_Entity() { Group_Orig_ID = groupList[1], Group_ID = groupList[2], V_ID = groupList[3], Nick = groupList[4], MemberNumber = groupList[5] }; currentWxInfoEntity.GroupList.Add(groupInfo); SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_GROUP_INFO, groupIndex.ToString()); } } //群好友 if (type == (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_GROUP_MEMBER_INFO_ACK) { if (msg.Equals("END", StringComparison.OrdinalIgnoreCase)) { List <GroupInfo_Entity> selectedGroupList = currentWxInfoEntity.GroupList.FindAll(x => x.Selected == true); LogHelper.LogUtil.WXHOOKUI.InfoFormat("GroupList selected count: [{0}]", selectedGroupList.Count); GroupInfo_Entity currentGroup = selectedGroupList[0]; LogHelper.LogUtil.WXHOOKUI.InfoFormat("Group ID: [{0}], member count: [{1}]", currentGroup.Group_Orig_ID, currentGroup.MemberList.Count); lsvGroupMember.Items.Clear(); lsvGroupMember.BeginUpdate(); foreach (FriendInfo_Entity friend_Info in currentGroup.MemberList) { ListViewItem lviFriend = new ListViewItem(); lviFriend.Text = friend_Info.Nick; ListViewItem.ListViewSubItem lsvs = new ListViewItem.ListViewSubItem() { Text = friend_Info.Friend_Orig_ID, Tag = friend_Info.Group_Orig_ID }; LogHelper.LogUtil.WXHOOKUI.InfoFormat("lsvs.Tag of friend_Info.Group_Orig_ID: {0}", friend_Info.Group_Orig_ID); LogHelper.LogUtil.WXHOOKUI.InfoFormat("lsvs.Tag: {0}", lsvs.Tag); lviFriend.SubItems.Add(lsvs); lsvGroupMember.Items.Add(lviFriend); } lsvGroupMember.EndUpdate(); } else { var groupmemberList = msg.Split('|'); int groupmemberIndex = CommonUtil.TranNull <int>(groupmemberList[0]); groupmemberIndex = groupmemberIndex + 1; string groupID = groupmemberList[1]; string groupMemberMsg = string.Format("{0}|{1}", groupmemberIndex, groupID); FriendInfo_Entity friendInfo = new FriendInfo_Entity() { Group_Orig_ID = groupID, Friend_Orig_ID = groupmemberList[2], Friend_ID = groupmemberList[2], V_ID = groupmemberList[4], Nick = groupmemberList[5], Remark = groupmemberList[6], Sex = groupmemberList[7] }; currentWxInfoEntity.GroupList.ForEach(x => x.Selected = false); GroupInfo_Entity currentGroup = currentWxInfoEntity.GroupList.Find(x => x.Group_Orig_ID.Equals(groupID, StringComparison.OrdinalIgnoreCase)); if (currentGroup != null) { currentGroup.Selected = true; currentGroup.MemberList.Add(friendInfo); } SendWeDllCmd(currentWxInfoEntity, (int)WX_CMD.WX_CMD_TYPE_E_GET_WX_GROUP_MEMBER_INFO, groupMemberMsg); } } }