/// <summary> /// 点击发送 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { if (textBox1.Text != null && _friendUser != null && _meUser != null) { WXMsg msg = new WXMsg(); msg.From = _meUser.UserName; msg.Msg = textBox1.Text; msg.Readed = false; msg.To = _friendUser.UserName; msg.Type = 1; msg.Time = DateTime.Now; _friendUser.SendMsg(msg, false); } }
/// <summary> /// 点击发送 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void SendContent_Click(object sender, EventArgs e) { try //if (rSendContent.Text != null && _friendUser != null && _meUser != null) { if (rSendContent.Text.Trim() == "") //Trim()是去除空格 { MessageBox.Show("(*^__^*) 嘻嘻……\n不能发空消息", "提 示"); } else { WXMsg msg = new WXMsg(); msg.Uin = _meUser.uin; msg.Sid = LoginCore.GetPassTicket(_meUser.uin).WxSid; msg.From = _meUser.UserName; msg.Msg = rSendContent.Text; msg.Readed = false; msg.To = _friendUser.UserName; msg.Type = 1; msg.Time = DateTime.Now; _friendUser.SendMsg(msg, false); rSendContent.Clear(); rSendContent.Focus(); } } catch { return; } }
private void SendText(WXMesssage msg, int count) { //发消息 if (null != msg) { if ((count % 100) == 0) { ExecEven("休息一下等待下一轮发送.........", null); Thread.Sleep(60 * 1000); } _me.SendMsg(msg); Thread.Sleep(900); var semdLog = string.Format("{0}\t已发【文本】信息给{1}", DateTime.Now.ToString(), msg.ToNickName); ExecEven(semdLog, null); } }
/// <summary> /// 指定某人发送指定消息 /// </summary> /// <param name="FromUserName">自己ID</param> /// <param name="ToUserName">好友ID</param> /// <param name="Msg">消息内容</param> public bool SpecifiedReply(string ToUserName, string Msg) { try { WXMsg assignMsg = new WXMsg(); WXUser assignUser = new WXUser(); assignMsg.From = MessageSync.userInfo.UserName; assignMsg.Msg = Msg; assignMsg.Readed = false; assignMsg.To = ToUserName; assignMsg.Type = 1; assignMsg.Time = DateTime.Now; assignUser.SendMsg(assignMsg, false); return(true); } catch (Exception) { return(false); } }
public void sendContent(string content_json) { LogUtil.log_call(this, "获取到发送信息,即将开始发送。。。"); try { ArrayList img_list = new ArrayList(); //LogUtil.log_call(this, "content_json:" + content_json); JObject sync_resul = JsonConvert.DeserializeObject(content_json) as JObject; string content = sync_resul["content"].ToString(); if (sync_resul["imgs"]["count"].ToString() != "0") { foreach (JObject key in sync_resul["imgs"]["items"]) { img_list.Add(key["url"].ToString()); } } for (int i = 0; i < this.dataGridView_weixin_qun_list.Rows.Count; i++) { if (this.dataGridView_weixin_qun_list[0, i].Value != null) { bool checked_ = (bool)this.dataGridView_weixin_qun_list[0, i].Value; if (checked_) { WXUser user = (WXUser)this.dataGridView_weixin_qun_list[1, i].Tag; if (user != null) { //LogUtil.log_call(this, "user.UserName:" + user.UserName); WXUser _friendUser = new WXUser(); WXMsg msg = new WXMsg(); msg.From = _me.UserName; msg.Msg = content; msg.Readed = false; msg.To = user.UserName; msg.Type = 1; msg.Time = DateTime.Now; foreach (string img in img_list) { string img_str = img; if (img_str.Contains("file:///")) { img_str = img_str.Replace("file:///", ""); } string MediaId = WXService.upload(this, "", _me.UserName, user.UserName, img_str); if (!string.IsNullOrEmpty(MediaId)) { WXService wxs = new WXService(); string send_result = wxs.SendMsg_img(msg.Msg, msg.From, msg.To, 3, MediaId); //LogUtil.log_call(this, "send_result:" + send_result); } } if (img_list.Count > 0) { Thread.Sleep(1000); } _friendUser.SendMsg(msg, false); //WXService wxs = new WXService(); //wxs.up.SendMsg(msg.Msg, msg.From, msg.To, msg.Type); } } } } LogUtil.log_call(this, "发送成功!"); } catch (Exception exception) { LogUtil.log_call(this, string.Concat("[buttonFwSndDelAll_Click]出错:", exception.ToString())); } }
/// <summary> /// /// </summary> private void DoMainLogic() { _lblWait.BringToFront(); ((Action)(delegate() { WXService wxs = new WXService(); JObject init_result = wxs.WxInit(); //初始化 List <object> contact_all = new List <object>(); if (init_result != null) { _me = new WXUser(); _me.UserName = init_result["User"]["UserName"].ToString(); _me.City = ""; _me.HeadImgUrl = init_result["User"]["HeadImgUrl"].ToString(); _me.NickName = init_result["User"]["NickName"].ToString(); _me.Province = ""; _me.PYQuanPin = init_result["User"]["PYQuanPin"].ToString(); _me.RemarkName = init_result["User"]["RemarkName"].ToString(); _me.RemarkPYQuanPin = init_result["User"]["RemarkPYQuanPin"].ToString(); _me.Sex = init_result["User"]["Sex"].ToString(); _me.Signature = init_result["User"]["Signature"].ToString(); foreach (JObject contact in init_result["ContactList"]) //部分好友名单 { WXUser user = new WXUser(); user.UserName = contact["UserName"].ToString(); user.City = contact["City"].ToString(); user.HeadImgUrl = contact["HeadImgUrl"].ToString(); user.NickName = contact["NickName"].ToString(); user.Province = contact["Province"].ToString(); user.PYQuanPin = contact["PYQuanPin"].ToString(); user.RemarkName = contact["RemarkName"].ToString(); user.RemarkPYQuanPin = contact["RemarkPYQuanPin"].ToString(); user.Sex = contact["Sex"].ToString(); user.Signature = contact["Signature"].ToString(); _contact_latest.Add(user); } } JObject contact_result = wxs.GetContact(); //通讯录 if (contact_result != null) { foreach (JObject contact in contact_result["MemberList"]) //完整好友名单 { WXUser user = new WXUser(); user.UserName = contact["UserName"].ToString(); user.City = contact["City"].ToString(); user.HeadImgUrl = contact["HeadImgUrl"].ToString(); user.NickName = contact["NickName"].ToString(); user.Province = contact["Province"].ToString(); user.PYQuanPin = contact["PYQuanPin"].ToString(); user.RemarkName = contact["RemarkName"].ToString(); user.RemarkPYQuanPin = contact["RemarkPYQuanPin"].ToString(); user.Sex = contact["Sex"].ToString(); user.Signature = contact["Signature"].ToString(); contact_all.Add(user); } } IOrderedEnumerable <object> list_all = contact_all.OrderBy(e => (e as WXUser).ShowPinYin); WXUser wx; string start_char; foreach (object o in list_all) { wx = o as WXUser; start_char = wx.ShowPinYin == "" ? "" : wx.ShowPinYin.Substring(0, 1); if (!_contact_all.Contains(start_char.ToUpper())) { _contact_all.Add(start_char.ToUpper()); } _contact_all.Add(o); } this.BeginInvoke((Action)(delegate() //等待结束 { _lblWait.Visible = false; wChatList1.Items.AddRange(_contact_latest.ToArray()); //近期联系人 wFriendsList1.Items.AddRange(_contact_all.ToArray()); //通讯录 wpersonalinfo.FriendUser = _me; })); string sync_flag = ""; JObject sync_result; while (true) { sync_flag = wxs.WxSyncCheck(); //同步检查 if (sync_flag == null) { continue; } //这里应该判断 sync_flag中selector的值 else //有消息 { sync_result = wxs.WxSync(); //进行同步 if (sync_result != null) { if (sync_result["AddMsgCount"] != null && sync_result["AddMsgCount"].ToString() != "0") { foreach (JObject m in sync_result["AddMsgList"]) { string from = m["FromUserName"].ToString(); string to = m["ToUserName"].ToString(); string content = m["Content"].ToString(); string type = m["MsgType"].ToString(); WXMsg msg = new WXMsg(); msg.From = from; msg.Msg = type == "1" ? content : "请在其他设备上查看消息1111"; //只接受文本消息 msg.Readed = false; msg.Time = DateTime.Now; msg.To = to; msg.Type = int.Parse(type); if (msg.Type == 51) //屏蔽一些系统数据 { continue; } //消息处理 if ((msg.To == "@@ab5c137f16c29a0140eacfa2034c287da5f33961fee17e3a2ac54c0eb7a30d14") || (msg.From == "@@ab5c137f16c29a0140eacfa2034c287da5f33961fee17e3a2ac54c0eb7a30d14")) { setLabel(msg.Msg); } this.BeginInvoke((Action) delegate() { WXUser user; bool exist_latest_contact = false; foreach (Object u in wChatList1.Items) { user = u as WXUser; if (user != null) { if (user.UserName == msg.From && msg.To == _me.UserName) //接收别人消息 { //label1.Text = msg.; wChatList1.Items.Remove(user); wChatList1.Items.Insert(0, user); exist_latest_contact = true; user.ReceiveMsg(msg); break; } else if (user.UserName == msg.To && msg.From == _me.UserName) //同步自己在其他设备上发送的消息 { wChatList1.Items.Remove(user); wChatList1.Items.Insert(0, user); exist_latest_contact = true; user.SendMsg(msg, true); break; } } } if (!exist_latest_contact) { foreach (object o in wFriendsList1.Items) { WXUser friend = o as WXUser; if (friend != null && friend.UserName == msg.From && msg.To == _me.UserName) { wChatList1.Items.Insert(0, friend); friend.ReceiveMsg(msg); break; } if (friend != null && friend.UserName == msg.To && msg.From == _me.UserName) { wChatList1.Items.Insert(0, friend); friend.SendMsg(msg, true); break; } } } wChatList1.Invalidate(); }); } } } } System.Threading.Thread.Sleep(10); } })).BeginInvoke(null, null); }
/// <summary> /// /// </summary> private void DoMainLogic() { _lblWait.BringToFront(); ((Action)(delegate() { Dictionary <string, string> ss = new Dictionary <string, string>(); //先判断下键值是否存在要不卡死头像只能显示一个用户的 //if (!ss.ContainsKey("1")) //{ // ss.Add("1", "1"); //} string sid = LoginCore.GetPassTicket(Uin).WxSid; WXService wxs = new WXService(); wxs.Uin = Uin; wxs.Sid = sid; wxs.robotID = robotID; JObject init_result = wxs.WxInit(); //初始化 List <object> contact_all = new List <object>(); if (init_result != null) { _me = new WXUser(); _me.uin = wxs.Uin; _me.UserName = init_result["User"]["UserName"].ToString(); _me.City = ""; _me.HeadImgUrl = init_result["User"]["HeadImgUrl"].ToString(); _me.NickName = init_result["User"]["NickName"].ToString(); _me.Province = ""; _me.PYQuanPin = init_result["User"]["PYQuanPin"].ToString(); _me.RemarkName = init_result["User"]["RemarkName"].ToString(); _me.RemarkPYQuanPin = init_result["User"]["RemarkPYQuanPin"].ToString(); _me.Sex = init_result["User"]["Sex"].ToString(); _me.Signature = init_result["User"]["Signature"].ToString(); foreach (JObject contact in init_result["ContactList"]) //部分好友名单 { WXUser user = new WXUser(); user.uin = wxs.Uin; user.UserName = contact["UserName"].ToString(); user.City = contact["City"].ToString(); user.HeadImgUrl = contact["HeadImgUrl"].ToString(); user.NickName = contact["NickName"].ToString(); user.Province = contact["Province"].ToString(); user.PYQuanPin = contact["PYQuanPin"].ToString(); user.RemarkName = contact["RemarkName"].ToString(); user.RemarkPYQuanPin = contact["RemarkPYQuanPin"].ToString(); user.Sex = contact["Sex"].ToString(); user.Signature = contact["Signature"].ToString(); _contact_latest.Add(user); } } JObject contact_result = wxs.GetContact(); //通讯录 if (contact_result != null) { foreach (JObject contact in contact_result["MemberList"]) //完整好友名单 { WXUser user = new WXUser(); user.uin = wxs.Uin; user.UserName = contact["UserName"].ToString(); user.City = contact["City"].ToString(); user.HeadImgUrl = contact["HeadImgUrl"].ToString(); user.NickName = contact["NickName"].ToString(); user.Province = contact["Province"].ToString(); user.PYQuanPin = contact["PYQuanPin"].ToString(); user.RemarkName = contact["RemarkName"].ToString(); user.RemarkPYQuanPin = contact["RemarkPYQuanPin"].ToString(); user.Sex = contact["Sex"].ToString(); user.Signature = contact["Signature"].ToString(); contact_all.Add(user); //((Action)delegate() //{ // //写入所有好友信息 // var b = WxOperateLogDal.AddchartLog(wxs.Uin, contact["UserName"].ToString(), contact["City"].ToString(), contact["HeadImgUrl"].ToString(), contact["NickName"].ToString(), contact["Province"].ToString(), contact["PYQuanPin"].ToString(), contact["RemarkName"].ToString(), contact["RemarkPYQuanPin"].ToString(), contact["Sex"].ToString(), contact["Signature"].ToString()); //}).BeginInvoke(null, null); wChatList1.Invalidate(); } } IOrderedEnumerable <object> list_all = contact_all.OrderBy(e => (e as WXUser).ShowPinYin); WXUser wx; string start_char; foreach (object o in list_all) { wx = o as WXUser; start_char = wx.ShowPinYin == "" ? "" : wx.ShowPinYin.Substring(0, 1); if (!_contact_all.Contains(start_char.ToUpper())) { _contact_all.Add(start_char.ToUpper()); } _contact_all.Add(o); } this.BeginInvoke((Action)(delegate() //等待结束 { _lblWait.Visible = false; wChatList1.Items.AddRange(_contact_latest.ToArray()); //近期联系人 wFriendsList1.Items.AddRange(_contact_all.ToArray()); //通讯录 wpersonalinfo.FriendUser = _me; })); string sync_flag = ""; JObject sync_result; while (true) { sync_flag = wxs.WxSyncCheck(); //同步检查 if (sync_flag == null) { continue; } //这里应该判断 sync_flag中selector的值 else //有消息 { sync_result = wxs.WxSync(); //进行同步 if (sync_result != null) { if (sync_result["AddMsgCount"] != null && sync_result["AddMsgCount"].ToString() != "0") { foreach (JObject m in sync_result["AddMsgList"]) { string from = m["FromUserName"].ToString(); string to = m["ToUserName"].ToString(); string content = m["Content"].ToString(); string MsgId = m["MsgId"].ToString(); string type = m["MsgType"].ToString();//语音视频标识 WXMsg msg = new WXMsg(); msg.From = from; wxs.Uin = Uin; wxs.Sid = sid; msg.Sid = wxs.Sid; msg.Uin = wxs.Uin; msg.Msg = type == "1" ? content : "收到一个系统数据"; //只接受文本消息 if (msg.Type == 1) //屏蔽一些系统数据 { msg.Msg = content; } msg.Readed = false; msg.Time = DateTime.Now; msg.To = to; msg.Type = int.Parse(type); //if (msg.Type == 51) //屏蔽一些系统数据 //{ // msg.Msg = "收到一个系统数据"; //} if (msg.Type == 10000)//进群退群消息 { string s = sync_result.ToString(); } if (msg.Type == 3)//图片 { msg.Msg = content + "收到一个图片"; string sFilePath = Environment.CurrentDirectory + "\\IMG"; string sFileName = MsgId + ".jpg"; sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径 HttpService.HttpDownloadFile(Constant._getmsgimg_url + MsgId, msg.Uin, sFileName); } if (msg.Type == 34)//语音 { msg.Msg = "收到语音点击查看"; //Button newButton = new Button();//创建一个名为newButton的新按钮 //newButton.Width = 150; //newButton.Text = "NewButton"; //newButton.BackColor = Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); //newButton.Click += new EventHandler(textBox1_Click); string sFilePath = Environment.CurrentDirectory + "\\MP3"; string sFileName = MsgId + ".wav"; sFileName = sFilePath + "\\" + sFileName; //文件的绝对路径 HttpService.HttpDownloadFile(Constant._getmsgmp3_url + MsgId, msg.Uin, sFileName); } if (msg.Type == 43)//小视频 { msg.Msg = "收到小视频" + "点击查看"; string sFilePath = Environment.CurrentDirectory + "\\MP4"; string sFileName = MsgId + ".MP4"; sFileName = sFilePath + "\\" + sFileName; HttpService.HttpDownloadFile(Constant._getmsgvideo_url + MsgId, msg.Uin, sFileName); } if (msg.Type == 62)//视频 { msg.Msg = content + "收到一个视频"; } if (msg.Type == 10002)//消息撤回 { msg.Msg = content + "对方撤回了消息"; } if (msg.Type == 42)//好友名片 { msg.Msg = content + "收到一个好友名片"; } if (msg.Type == 47)//动态表情 { msg.Msg = content + "收到一个动态表情"; } if (msg.Type == 48)//位置消息 { msg.Msg = content + "收到一个位置消息"; } if (msg.Type == 49)//分享链接 { msg.Msg = content + "收到一个分享链接"; } BeginInvoke((Action) delegate() { WXUser user; bool exist_latest_contact = false; foreach (object u in wChatList1.Items) { user = u as WXUser; if (user != null) { if (user.UserName == msg.From && msg.To == _me.UserName) //接收别人消息 { wChatList1.Items.Remove(user); wChatList1.Items.Insert(0, user); exist_latest_contact = true; user.ReceiveMsg(msg); break; } else if (user.UserName == msg.To && msg.From == _me.UserName) //同步自己在其他设备上发送的消息 { wChatList1.Items.Remove(user); wChatList1.Items.Insert(0, user); exist_latest_contact = true; user.SendMsg(msg, true); break; } } } if (!exist_latest_contact) { foreach (object o in wFriendsList1.Items) { WXUser friend = o as WXUser; if (friend != null && friend.UserName == msg.From && msg.To == _me.UserName) { wChatList1.Items.Insert(0, friend); friend.ReceiveMsg(msg); break; } if (friend != null && friend.UserName == msg.To && msg.From == _me.UserName) { wChatList1.Items.Insert(0, friend); friend.SendMsg(msg, true); break; } } } Wx_AlertForm.ShowWay showWay = Wx_AlertForm.ShowWay.UpDown; string aftitle = _me.NickName + "收到来自" + _me.ShowName + "一条消息"; string afContent = msg.Msg; int afShowInTime, afShowTime, afShowOutTime; int afWidth, afHeigth; int.TryParse("100", out afShowInTime); int.TryParse("8000", out afShowTime); int.TryParse("800", out afShowOutTime); int.TryParse("250", out afWidth); int.TryParse("120", out afHeigth); af = new Wx_AlertForm(); af.Show(afContent, aftitle, showWay, afWidth, afHeigth, afShowInTime, afShowTime, afShowOutTime); }); } } } } //System.Threading.Thread.Sleep(800); //#region 开始任务 ////var robotID = table.Rows[0]["RobotId"].ToString(); //WxTaskCore wt = new WxTaskCore(sid, Uin, robotID); //wt.user = _me; ////接收消息事件 ////wt.OnRevice += new WxTaskCore.Revice(wt_OnRevice); ////接收修改联系人消息 //wt.OnModifyContact += new WxTaskCore.ModifyContact(wt_OnModifyContact); ////通知发送信息 //wt.OnNotifySend += new WxTaskCore.NotifySend(wt_OnNotifySend); //////每一个微信号,开启一个线程 ////ThreadStart start = new ThreadStart(wt.ReviceMsg); ////new Thread(start).Start(); ////启动发送线程 //new Thread(new ThreadStart(wt.AutoSendMsg)).Start(); //#endregion } })).BeginInvoke(null, null); }
private void skinButton1_Click(object sender, EventArgs e) { this.skinButton1.Enabled = false; List <MessageType> message = new List <MessageType>(); int count = DataGridMessage.Rows.Count; for (int i = 0; i < count; i++) { DataGridViewCheckBoxCell checkCell = (DataGridViewCheckBoxCell)DataGridMessage.Rows[i].Cells[0]; Boolean flag = Convert.ToBoolean(checkCell.Value); if (flag == true) { MessageType msgType = new MessageType() { SendType = this.DataGridMessage.Rows[i].Cells[1].Value.ToString(), TxtContent = this.DataGridMessage.Rows[i].Cells[2].Value.ToString() }; message.Add(msgType); } } if (message.Count <= 0) { MessageBox.Show("请选择好你要发送的消息!"); return; } WXMesssage msg = new WXMesssage(); //发消息 var sendMsg = message.Where(a => a.SendType == "文本").FirstOrDefault(); if (null != sendMsg) { foreach (var item in contact_all) { msg.From = _me.UserName; msg.Readed = false; msg.To = item.UserName; msg.Time = DateTime.Now; msg.Type = 1; msg.Msg = sendMsg.TxtContent; _me.SendMsg(msg); outPost(item.NickName, sendMsg.SendType); } } //发图片 var sendImage = message.Where(a => a.SendType == "图片").FirstOrDefault(); if (null != sendImage) { if (!File.Exists(sendImage.TxtContent)) { MessageBox.Show("文件不存在,请选择好文件!"); return; } //先上传 WXServices wxServices = new WXServices(); var resultJson = wxServices.UploadImage(sendImage.TxtContent); if (!string.IsNullOrEmpty(resultJson)) { JObject obj = JsonConvert.DeserializeObject(resultJson) as JObject; string mediaId = obj["MediaId"].ToString(); if (!string.IsNullOrEmpty(mediaId)) { foreach (var item in contact_all) { msg.From = _me.UserName; msg.Readed = false; msg.To = item.UserName; msg.Time = DateTime.Now; msg.MediaId = mediaId; _me.SendImage(msg); outPost(item.NickName, sendImage.SendType); } } } } //发视频 var sendVideo = message.Where(a => a.SendType == "视频").FirstOrDefault(); if (null != sendVideo) { if (!File.Exists(sendVideo.TxtContent)) { MessageBox.Show("文件不存在,请选择好文件!"); return; } WXServices wxServices = new WXServices(); var resultJson = wxServices.UploadVideo(sendVideo.TxtContent, _me.UserName, contact_all[0].UserName); if (!string.IsNullOrEmpty(resultJson)) { JObject obj = JsonConvert.DeserializeObject(resultJson) as JObject; string mediaId = obj["MediaId"].ToString(); if (!string.IsNullOrEmpty(mediaId)) { foreach (var item in contact_all) { msg.From = _me.UserName; msg.Readed = false; msg.To = item.UserName; msg.Time = DateTime.Now; msg.MediaId = mediaId; _me.SendVideo(msg); outPost(item.NickName, sendVideo.SendType); } } } } this.skinButton1.Enabled = true; }