示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            API.Message msg = new API.Message()
            {
                IsSend      = false,
                MsgType     = 34,
                VoiceLength = 152000
            };
            adapter.Add(msg);



            //List<Image> imageList = weTextBox1.GetImages();
            //if (imageList != null && imageList.Count > 0)
            //{
            //    //int i = 0;
            //    //foreach (Image item in imageList)
            //    //{
            //    //    item.Save("image" + i + ".bmp");
            //    //    i++;
            //    //}
            //}

            //string rtf = weTextBox1.Rtf;
            //File.WriteAllText("D:\\rtf2.rtf",rtf);


            //MessageBox.Show("11");
        }
示例#2
0
 /// <summary>
 /// 聊天记录点击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void fListView1_ItemClick(object sender, WinForm.UI.Events.ItemClickEventArgs e)
 {
     API.Message msg = e.ViewHolder.UserData as API.Message;
     if (msg.MsgType == 3)//图片消息
     {
         string path = string.Empty;
         if (!msg.IsSend)
         {
             string fileName = msg.MsgId + ".bmp";
             path = Path.Combine(App.PATH_CACHE, fileName);
         }
         else
         {
             path = msg.fileName;
         }
         ImageForm form = new ImageForm();
         form.Show(path);
     }
     else if (msg.MsgType == 34) //语音消息
     {
         string path = msg.fileName;
         musicForm.Player(path);
         adapter.Play();
         AsyncTask.StartNew(() =>
         {
             Thread.Sleep((int)msg.VoiceLength / 1000);
             adapter.Stop();
         });
     }
 }
示例#3
0
        /// <summary>
        /// 发送文本消息
        /// </summary>
        /// <param name="ToUserName"></param>
        /// <param name="Content"></param>
        public void SendMsg(string ToUserName, string Content)
        {
            Contact ToUser = WechatAPIService.GetContact(ToUserName);

            API.Message msg = new API.Message()
            {
                MsgType = 1,
                Content = Content,
                IsSend  = true,
                Remote  = ToUser,
                Mime    = WechatAPIService.Self,
            };
            Task <SendMsgResponse> task = api.SendMsgAsync(ToUserName, Content);

            task.ContinueWith((obj) =>
            {
                SendMsgResponse res = obj.Result;
                if (res != null && !string.IsNullOrEmpty(res.MsgID))
                {
                    MessageDao MsgDao = DaoMaster.GetSession().GetMessageDao();
                    msg.MsgId         = res.MsgID;
                    MsgDao.InsertMessage(msg, openContact.Seq);
                }
            });
        }
示例#4
0
        /// <summary>
        /// 下载图片
        /// </summary>
        private void DownloadImage(API.Message msg)
        {
            string url      = string.Format("/cgi-bin/mmwebwx-bin/webwxgetmsgimg?MsgID={0}", msg.MsgId);
            Image  image    = api.GetMsgImage(url);
            string fileName = msg.MsgId + ".bmp";
            string path     = Path.Combine(App.PATH_CACHE, fileName);

            image.Save(path);
        }
示例#5
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            string message = txtMessage.Text;
            string rtf     = txtMessage.Rtf;

            if (string.IsNullOrWhiteSpace(message) && string.IsNullOrEmpty(rtf))
            {
                return;
            }
            this.btnSend.Enabled = false;
            if (!string.IsNullOrEmpty(message))
            {
                SendMsg(this.openContact.ID, message);
                API.Message msg = new API.Message()
                {
                    MsgType = 1,
                    Content = message,
                    IsSend  = true,
                    Remote  = openContact,
                    Mime    = WechatAPIService.Self
                };
                adapter.Add(msg);
            }
            List <Image> imageList = txtMessage.GetImages();

            if (imageList != null && imageList.Count > 0)
            {
                List <API.Message> messageList = new List <API.Message>();
                foreach (Image item in imageList)
                {
                    string filePath = Path.Combine(App.PATH_CACHE, Path.GetRandomFileName() + ".bmp");
                    item.Save(filePath);
                    SendImg(this.openContact.ID, filePath);
                    messageList.Add(new API.Message()
                    {
                        MsgType  = 3,
                        fileName = filePath,
                        IsSend   = true,
                        Remote   = openContact,
                        Mime     = WechatAPIService.Self
                    });
                }
                adapter.AddItems(messageList);
            }

            txtMessage.Clear();
            this.fListView1.ScrollBottom();
            this.btnSend.Enabled = true;
        }
示例#6
0
 private void Api_OnAddMessage(WechatAPIService sender, AddMessageEvent e)
 {
     API.Message msg = e.Msg;
     if (msg.MsgType == 51)
     {
         return;
     }
     //判断发送消息人是否为当前聊天用户
     if (this.openContact != null && openContact.ID == msg.Remote.ID)
     {
         m_SyncContext.Post(UpdateMessageList, msg);
     }
     if (msg.MsgType == 3)
     {
         AsyncTask.StartNew(() => DownloadImage(msg));
     }
 }