Example #1
0
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="type"></param>
        public void SendMsg(string msg, string from, string to, int type)
        {
            StringBuilder s  = new StringBuilder();//s数组中存放着需要的数字
            Random        ra = new Random();

            for (int i = 0; i < 15; i++)//遍历数组显示结果
            {
                s.Append(ra.Next(1, 10));
            }

            string msg_json = "{{" +
                              "\"BaseRequest\":{{" +
                              "\"DeviceID\" : \"e" + s.ToString() + "\"," +
                              "\"Sid\" : \"{0}\"," +
                              "\"Skey\" : \"{6}\"," +
                              "\"Uin\" : \"{1}\"" +
                              "}}," +
                              "\"Msg\" : {{" +
                              "\"ClientMsgId\" : {8}," +
                              "\"Content\" : \"{2}\"," +
                              "\"FromUserName\" : \"{3}\"," +
                              "\"LocalID\" : {9}," +
                              "\"ToUserName\" : \"{4}\"," +
                              "\"Type\" : {5}" +
                              "}}," +
                              "\"rr\" : {7}" +
                              "}}";

            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                msg_json = string.Format(msg_json, sid.Value, uin.Value, msg, from, to, type, LoginService.SKey, DateTime.Now.Millisecond, DateTime.Now.Millisecond, DateTime.Now.Millisecond);

                List <string> listCheckUrl = new List <string>();
                listCheckUrl.Add("wx.qq.com");
                listCheckUrl.Add("wx2.qq.com");
                byte[] bytes = null;
                foreach (string item in listCheckUrl)
                {
                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxsendmsg?sid=";
                    bytes = BaseService.SendPostRequest(url + sid.Value + "&lang=zh_CN&pass_ticket=" + LoginService.Pass_Ticket, msg_json);
                    if (bytes == null)
                    {
                        continue;
                    }
                    string send_result = Encoding.UTF8.GetString(bytes);

                    if (!send_result.Contains("\"Ret\": 0"))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Example #2
0
        ///// <summary>
        ///// 微信同步
        ///// </summary>
        ///// <returns></returns>
        //public JObject WxSync()
        //{
        //    string sync_json = "{{\"BaseRequest\" : {{\"DeviceID\":\"e1615250492\",\"Sid\":\"{1}\", \"Skey\":\"{5}\", \"Uin\":\"{0}\"}},\"SyncKey\" : {{\"Count\":{2},\"List\":[{3}]}},\"rr\" :{4}}}";
        //    Cookie sid = BaseService.GetCookie("wxsid");
        //    Cookie uin = BaseService.GetCookie("wxuin");

        //    string sync_keys = "";
        //    foreach (KeyValuePair<string, string> p in _syncKey)
        //    {
        //        sync_keys += "{\"Key\":" + p.Key + ",\"Val\":" + p.Value + "},";
        //    }
        //    sync_keys = sync_keys.TrimEnd(',');
        //    sync_json = string.Format(sync_json, uin.Value, sid.Value, _syncKey.Count, sync_keys, (long)(DateTime.Now.ToUniversalTime() - new System.DateTime(1970, 1, 1)).TotalMilliseconds, LoginService.SKey);

        //    if (sid != null && uin != null)
        //    {
        //        byte[] bytes = BaseService.SendPostRequest(_sync_url + sid.Value + "&lang=zh_CN&skey=" + LoginService.SKey + "&pass_ticket=" + LoginService.Pass_Ticket, sync_json);

        //        if (bytes == null || bytes.Length == 0)
        //        {
        //            return null;
        //        }
        //        string sync_str = Encoding.UTF8.GetString(bytes);

        //        JObject sync_resul = JsonConvert.DeserializeObject(sync_str) as JObject;

        //        if (sync_resul["SyncKey"]["Count"].ToString() != "0")
        //        {
        //            _syncKey.Clear();
        //            foreach (JObject key in sync_resul["SyncKey"]["List"])
        //            {
        //                _syncKey.Add(key["Key"].ToString(), key["Val"].ToString());
        //            }
        //        }
        //        return sync_resul;
        //    }
        //    else
        //    {
        //        return null;
        //    }
        //}
        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="type"></param>
        public void SendMsg(string msg, string from, string to, int type, List <Cookie> cookList, string SKey, string Pass_Ticket)
        {
            string msg_json = "{{" +
                              "\"BaseRequest\":{{" +
                              "\"DeviceID\" : \"e441551176\"," +
                              "\"Sid\" : \"{0}\"," +
                              "\"Skey\" : \"{6}\"," +
                              "\"Uin\" : \"{1}\"" +
                              "}}," +
                              "\"Msg\" : {{" +
                              "\"ClientMsgId\" : {8}," +
                              "\"Content\" : \"{2}\"," +
                              "\"FromUserName\" : \"{3}\"," +
                              "\"LocalID\" : {9}," +
                              "\"ToUserName\" : \"{4}\"," +
                              "\"Type\" : {5}" +
                              "}}," +
                              "\"rr\" : {7}" +
                              "}}";

            Cookie sid = cookList.Find(p => p.Name == "wxsid");
            Cookie uin = cookList.Find(p => p.Name == "wxuin");

            if (sid != null && uin != null)
            {
                msg_json = string.Format(msg_json, sid.Value, uin.Value, msg, from, to, type, SKey, DateTime.Now.Millisecond, DateTime.Now.Millisecond, DateTime.Now.Millisecond);

                List <string> listCheckUrl = new List <string>();
                listCheckUrl.Add("wx.qq.com");
                listCheckUrl.Add("wx2.qq.com");
                byte[] bytes = null;
                foreach (string item in listCheckUrl)
                {
                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxsendmsg?sid=";
                    bytes = BaseService.SendPostRequest(url + sid.Value + "&lang=zh_CN&pass_ticket=" + Pass_Ticket, msg_json);
                    if (bytes == null)
                    {
                        continue;
                    }
                    string send_result = Encoding.UTF8.GetString(bytes);

                    if (!send_result.Contains("\"Ret\": 0"))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Example #3
0
        public string GetQun(string qunUserName)
        {
            string msg_json = "";

            StringBuilder s  = new StringBuilder();//s数组中存放着需要的数字
            Random        ra = new Random();

            for (int i = 0; i < 15; i++)//遍历数组显示结果
            {
                s.Append(ra.Next(1, 10));
            }

            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                msg_json = "{\"BaseRequest\":{ \"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"DeviceID\":\"e" + s.ToString() + "\"},\"Count\":1,\"List\":[{\"UserName\":\"" + qunUserName + "\",\"EncryChatRoomId\":\"\"}]}";


                List <string> listCheckUrl = new List <string>();
                listCheckUrl.Add("wx.qq.com");
                listCheckUrl.Add("wx2.qq.com");
                byte[] bytes = null;
                foreach (string item in listCheckUrl)
                {
                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxbatchgetcontact?type=ex";
                    bytes = BaseService.SendPostRequest(url + "&r=" + DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString().Split(new char[] { '.' })[0] + "&pass_ticket=" + LoginService.Pass_Ticket, msg_json);

                    if (bytes == null)
                    {
                        continue;
                    }
                    string send_result = Encoding.UTF8.GetString(bytes);

                    if (!send_result.Contains("\"Ret\": 0"))
                    {
                        continue;
                    }
                    else
                    {
                        return(send_result);
                    }
                }
            }
            return("");
        }
Example #4
0
        public string DeleteUser(string gUserName, string cUserName)
        {
            string msg_json = "";

            StringBuilder s  = new StringBuilder();//s数组中存放着需要的数字
            Random        ra = new Random();

            for (int i = 0; i < 15; i++)//遍历数组显示结果
            {
                s.Append(ra.Next(1, 10));
            }

            Cookie sid = BaseService.GetCookie("wxsid");
            Cookie uin = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                msg_json = "{\"BaseRequest\":{ \"DeviceID\":\"e" + s.ToString() + "\",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"Uin\":" + uin.Value + "},\"DelMemberList\":\"" + cUserName + "\",\"ChatRoomName\":\"" + gUserName + "\"}";
                List <string> listCheckUrl = new List <string>();
                listCheckUrl.Add("wx.qq.com");
                listCheckUrl.Add("wx2.qq.com");
                byte[] bytes = null;
                foreach (string item in listCheckUrl)
                {
                    ///cgi-bin/mmwebwx-bin/webwxupdatechatroom?fun=delmember&lang=zh_CN&pass_ticket=
                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxupdatechatroom?fun=delmember&lang=zh_CN";
                    bytes = BaseService.SendPostRequest(url + "&pass_ticket=" + LoginService.Pass_Ticket, msg_json);
                    if (bytes == null)
                    {
                        continue;
                    }

                    string send_result = Encoding.UTF8.GetString(bytes);

                    if (!send_result.Contains("\"Ret\": 0"))
                    {
                        continue;
                    }
                    else
                    {
                        return(send_result);
                    }
                }
            }
            return("");
        }
Example #5
0
        /// <summary>
        /// 微信初始化
        /// </summary>
        /// <returns></returns>
        public JObject WxInit()
        {
            StringBuilder s  = new StringBuilder();//s数组中存放着需要的数字
            Random        ra = new Random();

            for (int i = 0; i < 15; i++)//遍历数组显示结果
            {
                s.Append(ra.Next(1, 10));
            }

            string init_json = "{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"{2}\",\"DeviceID\":\"e{3}\"}}}}";
            Cookie sid       = BaseService.GetCookie("wxsid");
            Cookie uin       = BaseService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                init_json = string.Format(init_json, uin.Value, sid.Value, LoginService.SKey, s.ToString());

                string r = DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString().Split(new char[] { '.' })[0];

                List <string> listCheckUrl = new List <string>();
                listCheckUrl.Add("wx.qq.com");
                listCheckUrl.Add("wx2.qq.com");
                byte[] bytes    = null;
                string init_str = "";
                foreach (string item in listCheckUrl)
                {
                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxinit?";
                    bytes = BaseService.SendPostRequest(url + "r=" + r + "&lang=zh_CN&pass_ticket=" + LoginService.Pass_Ticket, init_json);
                    if (bytes != null)
                    {
                        init_str = Encoding.UTF8.GetString(bytes);
                        //if (init_str.Contains("1100"))
                        //{
                        //    continue;
                        //}
                        //break;
                        if (init_str.Contains("\"Ret\": 0"))
                        {
                            break;
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                JObject init_result = JsonConvert.DeserializeObject(init_str) as JObject;

                foreach (JObject synckey in init_result["SyncKey"]["List"])  //同步键值
                {
                    if (_syncKey.ContainsKey(synckey["Key"].ToString()))
                    {
                        continue;
                    }
                    _syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString());
                }
                return(init_result);
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        public string SendImage(string fileName, string filePath, string fileSize, string fromUser, string toUser, string fileMD5)
        {
            string ret         = "";
            string send_result = "";

            try
            {
                List <string> listCheckUrl = new List <string>();
                listCheckUrl.Add("file.wx.qq.com");
                listCheckUrl.Add("file2.wx.qq.com");
                foreach (string item in listCheckUrl)
                {
                    StringBuilder s  = new StringBuilder(); //s数组中存放着需要的数字
                    Random        ra = new Random();
                    for (int i = 0; i < 15; i++)            //遍历数组显示结果
                    {
                        s.Append(ra.Next(1, 10));
                    }

                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxuploadmedia?f=json";

                    string date = DateTime.Now.ToString("yyyy-MM-dd");
                    date = date.Replace("-", "/");
                    string time = DateTime.Now.ToString("ttH:mm:ss");

                    NameValueCollection nav = new NameValueCollection();
                    nav.Add("id", "WU_FILE_" + frmMainForm.Count);
                    nav.Add("name", fileName);
                    nav.Add("type", "image/png");
                    //nav.Add("type", "application/octet-stream");
                    nav.Add("lastModifiedDate", date + " " + time);
                    //nav.Add("chunks", "2");
                    //nav.Add("chunk", "1");
                    nav.Add("size", fileSize);
                    nav.Add("mediatype", "pic");

                    Cookie sid = BaseService.GetCookie("wxsid");
                    Cookie uin = BaseService.GetCookie("wxuin");

                    if (sid == null)
                    {
                        Log.WriteLogByDate("sid为空了");
                    }
                    if (uin == null)
                    {
                        Log.WriteLogByDate("uin为空了");
                    }

                    string baseRequest = "{ \"UploadType\":2,\"BaseRequest\":{ \"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"DeviceID\":\"e" + s.ToString() + "\"},\"ClientMediaId\":" + DateTime.Now.DateTimeToUnixTimestamp() + ",\"TotalLen\":" + fileSize + ",\"StartPos\":0,\"DataLen\":" + fileSize + ",\"MediaType\":4,\"FromUserName\":\"" + fromUser + "\",\"ToUserName\":\"" + toUser + "\",\"FileMd5\":\"" + fileMD5 + "\"}";

                    nav.Add("uploadmediarequest", baseRequest);
                    //string webwx_data_ticket = BaseService.GetCookie("webwx_data_ticket").Value;
                    Cookie webwx_data_ticket = BaseService.GetCookie("webwx_data_ticket");

                    if (webwx_data_ticket != null)
                    {
                        LoginService.webwx_data_ticket = webwx_data_ticket.Value;
                    }
                    else
                    {
                        Log.WriteLogByDate("webwx_data_ticket为空了");
                    }

                    nav.Add("webwx_data_ticket", LoginService.webwx_data_ticket);
                    nav.Add("pass_ticket", LoginService.Pass_Ticket);

                    ret = BaseService.HttpUploadFile(url, fileName, fileName, "image/png", nav);
                    //ret = BaseService.HttpUploadFile(url, fileName, fileName, "application/octet-stream", nav);
                    Log.WriteLogByDate("发送图片ret=" + ret);
                    if (string.IsNullOrEmpty(ret))
                    {
                        continue;
                    }

                    if (!ret.Contains("\"Ret\": 0"))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }



                //发送图片
                JObject jobject = JsonConvert.DeserializeObject(ret) as JObject;
                string  mediaId = jobject["MediaId"].ToString();

                List <string> listCheckUrl2 = new List <string>();
                listCheckUrl2.Add("wx.qq.com");
                listCheckUrl2.Add("wx2.qq.com");

                foreach (string item in listCheckUrl2)
                {
                    StringBuilder s  = new StringBuilder(); //s数组中存放着需要的数字
                    Random        ra = new Random();
                    for (int i = 0; i < 15; i++)            //遍历数组显示结果
                    {
                        s.Append(ra.Next(1, 10));
                    }

                    string url = "https://" + item + "/cgi-bin/mmwebwx-bin/webwxsendmsgimg?fun=async&f=json&pass_ticket=" + LoginService.Pass_Ticket;

                    Cookie sid         = BaseService.GetCookie("wxsid");
                    Cookie uin         = BaseService.GetCookie("wxuin");
                    string baseRequest = "{\"BaseRequest\":{ \"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService.SKey + "\",\"DeviceID\":\"e" + s.ToString() + "\"},\"Msg\":{\"Type\":3,\"MediaId\":\"" + mediaId + "\",\"FromUserName\":\"" + fromUser + "\",\"ToUserName\":\"" + toUser + "\",\"LocalID\":" + DateTime.Now.DateTimeToUnixTimestamp() + ",\"ClientMsgId\":" + DateTime.Now.DateTimeToUnixTimestamp() + "}}";

                    byte[] bytes = null;
                    bytes = BaseService.SendPostRequest(url, baseRequest);
                    if (bytes == null)
                    {
                        continue;
                    }
                    send_result = Encoding.UTF8.GetString(bytes);
                    if (!send_result.Contains("\"Ret\":0"))
                    {
                        continue;
                    }
                }
            }
            catch (Exception ex)
            {
                //发生图片
                Log.WriteLogByDate("发送图片失败");
                Log.WriteLog(ex);
            }

            frmMainForm.Count++;
            Log.WriteLogByDate("发送图片返回结果:" + send_result);
            return(send_result);
        }