public void Send(object sender, MouseButtonEventArgs e) { long time = Time.Now(); string url = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg" + "?sid=" + Data.wxsid + "&skey=" + Data.skey + "&pass_ticket=" + Data.pass_ticket + "&r=" + time; WebRequest request = WebRequest.Create(url); request.Method = "POST"; JObject jsonObj = new JObject(); jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest)); SendMsg msg = new SendMsg(); msg.FromUserName = Data.me.UserName; msg.ToUserName = user.UserName; msg.Type = 1; msg.Content = SendBox.Text.Replace("\r", ""); msg.ClientMsgId = time; msg.LocalID = time; SendBox.Clear(); jsonObj.Add("Msg", JObject.FromObject(msg)); byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", "")); request.ContentType = "application/json; charset=UTF-8"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string ret = reader.ReadToEnd(); webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject <webwxsendmsg>(ret); reader.Close(); dataStream.Close(); response.Close(); Msg recvmsg = new Msg(); recvmsg.MsgId = wxsendmsg.MsgID; recvmsg.FromUserName = msg.FromUserName; recvmsg.ToUserName = msg.ToUserName; recvmsg.MsgType = msg.Type; recvmsg.Content = msg.Content; recvmsg.CreateTime = msg.LocalID; Trace.WriteLine("发送消息"); Trace.WriteLine(recvmsg.Content); Data.main.记录消息(recvmsg); }
public void Send(object sender, MouseButtonEventArgs e) { long time = Time.Now(); string url = "http://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg" + "?sid=" + Data.wxsid + "&skey=" + Data.skey + "&pass_ticket=" + Data.pass_ticket + "&r=" + time; WebRequest request = WebRequest.Create(url); request.Method = "POST"; JObject jsonObj = new JObject(); jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest)); SendMsg msg = new SendMsg(); msg.FromUserName = Data.me.UserName; msg.ToUserName = user.UserName; msg.Type = 1; msg.Content = SendBox.Text.Replace("\r", ""); msg.ClientMsgId = time; msg.LocalID = time; SendBox.Clear(); jsonObj.Add("Msg", JObject.FromObject(msg)); byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", "")); request.ContentType = "application/json; charset=UTF-8"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); WebResponse response = request.GetResponse(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string ret = reader.ReadToEnd(); webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject<webwxsendmsg>(ret); reader.Close(); dataStream.Close(); response.Close(); Msg recvmsg = new Msg(); recvmsg.MsgId = wxsendmsg.MsgID; recvmsg.FromUserName = msg.FromUserName; recvmsg.ToUserName = msg.ToUserName; recvmsg.MsgType = msg.Type; recvmsg.Content = msg.Content; recvmsg.CreateTime = msg.LocalID; Trace.WriteLine("发送消息"); Trace.WriteLine(recvmsg.Content); Data.main.记录消息(recvmsg); }
public async void SendMessage(string contact, string message) { var u = from c in Data.Contactlist where (c.Value.NickName == contact || c.Value.DisplayName == contact || c.Value.Alias == contact) select c.Value; if (u.Count() == 0) { Trace.WriteLine(string.Format("发送消息失败!未找到群:{0}, 消息:{1}。", contact, message)); return; } string userKey = u.First().UserName; long time = Time.Now(); string url = string.Format(WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/webwxsendmsg?r={0}&pass_ticket={1}&sid={2}&skey={3}", time, Data.pass_ticket, Data.wxsid, Data.skey); WebRequest request = WebRequest.Create(url); //HttpWebRequest request = HttpWebRequest.CreateHttp(url); request.Method = "POST"; JObject jsonObj = new JObject(); jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest)); SendMsg msg = new SendMsg(); msg.FromUserName = Data.me.UserName; msg.ToUserName = userKey; msg.Type = 1; msg.Content = message.Replace("\r", ""); msg.ClientMsgId = time; msg.LocalID = time; jsonObj.Add("Msg", JObject.FromObject(msg)); byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", "")); request.ContentType = "application/json; charset=UTF-8"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); Trace.WriteLine("发送消息..."); Trace.WriteLine(jsonObj.ToString().Replace("\r\n", "")); WebResponse response = await request.GetResponseAsync(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string ret = reader.ReadToEnd(); webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject<webwxsendmsg>(ret); reader.Close(); dataStream.Close(); response.Close(); //如果发送失败,调用同步消息获取最新synckey, 再重发一次? if (wxsendmsg.MsgID == null) { this.同步消息(); response = request.GetResponse(); dataStream = response.GetResponseStream(); reader = new StreamReader(dataStream); ret = reader.ReadToEnd(); wxsendmsg = JsonConvert.DeserializeObject<webwxsendmsg>(ret); reader.Close(); dataStream.Close(); response.Close(); } Trace.WriteLine(string.Format("发送消息成功!发送到:{0}, 消息:{1}。", contact, message)); }
public async void SendMessage(string contact, string message) { var u = from c in Data.Contactlist where (c.Value.NickName == contact || c.Value.DisplayName == contact || c.Value.Alias == contact) select c.Value; if (u.Count() == 0) { Trace.WriteLine(string.Format("发送消息失败!未找到群:{0}, 消息:{1}。", contact, message)); return; } string userKey = u.First().UserName; long time = Time.Now(); string url = string.Format(WeGlobal.WechatHost + "cgi-bin/mmwebwx-bin/webwxsendmsg?r={0}&pass_ticket={1}&sid={2}&skey={3}", time, Data.pass_ticket, Data.wxsid, Data.skey); WebRequest request = WebRequest.Create(url); //HttpWebRequest request = HttpWebRequest.CreateHttp(url); request.Method = "POST"; JObject jsonObj = new JObject(); jsonObj.Add("BaseRequest", JObject.FromObject(Data.baseRequest)); SendMsg msg = new SendMsg(); msg.FromUserName = Data.me.UserName; msg.ToUserName = userKey; msg.Type = 1; msg.Content = message.Replace("\r", ""); msg.ClientMsgId = time; msg.LocalID = time; jsonObj.Add("Msg", JObject.FromObject(msg)); byte[] byteArray = Encoding.UTF8.GetBytes(jsonObj.ToString().Replace("\r\n", "")); request.ContentType = "application/json; charset=UTF-8"; request.ContentLength = byteArray.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); Trace.WriteLine("发送消息..."); Trace.WriteLine(jsonObj.ToString().Replace("\r\n", "")); WebResponse response = await request.GetResponseAsync(); dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string ret = reader.ReadToEnd(); webwxsendmsg wxsendmsg = JsonConvert.DeserializeObject <webwxsendmsg>(ret); reader.Close(); dataStream.Close(); response.Close(); //如果发送失败,调用同步消息获取最新synckey, 再重发一次? if (wxsendmsg.MsgID == null) { this.步消息(); response = request.GetResponse(); dataStream = response.GetResponseStream(); reader = new StreamReader(dataStream); ret = reader.ReadToEnd(); wxsendmsg = JsonConvert.DeserializeObject <webwxsendmsg>(ret); reader.Close(); dataStream.Close(); response.Close(); } Trace.WriteLine(string.Format("发送消息成功!发送到:{0}, 消息:{1}。", contact, message)); }
private async void Send_Message(object sender, RoutedEventArgs e) { if (friend != null) { String uri = "http://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxsendmsg" + "?sid=" + cookie.wxsid + "&skey=" + cookie.skey + "&pass_ticket=" + cookie.pass_ticket + "&r=" + Time.Now(); BaseRequest baseRequest = new BaseRequest(cookie.wxuin, cookie.wxsid, cookie.skey); JObject jsonObj = new JObject(); jsonObj.Add("BaseRequest", JObject.FromObject(baseRequest)); SendMsg msg = new SendMsg(); msg.FromUserName = wxInit.User.UserName; msg.ToUserName = friend.UserName; msg.Type = 1; msg.Content = send.Text; msg.ClientMsgId = Time.Now(); msg.LocalID = Time.Now(); jsonObj.Add("Msg", JObject.FromObject(msg)); String json = jsonObj.ToString().Replace("\r\n", ""); string result = await Post.Get_Response_Str(uri, json); for (int i = 0; i < ContactView.AllItems.Count; i++) { if (friend.UserName == ContactView.AllItems[i].UserName) { bubble m = new bubble(); m.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left; m.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top; m.Text = send.Text; uri = "http://wx2.qq.com" + wxInit.User.HeadImgUrl; var response = await Get.Get_Response_Str(uri, cookie_str); var r = await response.Content.ReadAsByteArrayAsync(); var bit = await ByteArrayToBitmapImage(r); m.setImg(bit); m.setNickName(wxInit.User.NickName); Tile.TileManger.Tile(wxInit.User.NickName, ContactView.AllItems[i].NickName); ContactView.AllItems[i].dialog.Add(m); if (i != 0) { var u = ContactView.AllItems[i]; ContactView.AllItems.RemoveAt(i); ContactView.AllItems.Insert(0, u); } sp1.Children.Add(m); send.Text = ""; } } } }