private void SendImage(WXMesssage msg, int count) { if (null != msg) { if ((count % 15) == 0) { ExecEven("休息一下等待下一轮发送.........", null); Thread.Sleep(60 * 1000); } _me.SendImage(msg); Thread.Sleep(900); var semdLog = string.Format("{0}\t已发【图片】信息给{1}", DateTime.Now.ToString(), msg.ToNickName); ExecEven(semdLog, 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; }