Example #1
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       = BaseService2.GetCookie("wxsid");
            Cookie uin       = BaseService2.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                init_json = string.Format(init_json, uin.Value, sid.Value, LoginService2.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 = BaseService2.SendPostRequest(url + "r=" + r + "&lang=zh_CN&pass_ticket=" + LoginService2.Pass_Ticket, init_json);
                    if (bytes != null)
                    {
                        init_str = Encoding.UTF8.GetString(bytes);
                        if (init_str.Contains("1100"))
                        {
                            continue;
                        }
                        break;
                    }
                }
                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 #2
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)
        {
            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 = BaseService2.GetCookie("wxsid");
            Cookie uin = BaseService2.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                msg_json = string.Format(msg_json, sid.Value, uin.Value, msg, from, to, type, LoginService2.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 = BaseService2.SendPostRequest(url + sid.Value + "&lang=zh_CN&pass_ticket=" + LoginService2.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 = BaseService2.GetCookie("wxsid");
            Cookie uin = BaseService2.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                msg_json = "{\"BaseRequest\":{ \"Uin\":" + uin.Value + ",\"Sid\":\"" + sid.Value + "\",\"Skey\":\"" + LoginService2.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 = BaseService2.SendPostRequest(url + "&r=" + DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString().Split(new char[] { '.' })[0] + "&pass_ticket=" + LoginService2.Pass_Ticket, msg_json);
                    string send_result = Encoding.UTF8.GetString(bytes);

                    if (!send_result.Contains("\"Ret\": 0"))
                    {
                        continue;
                    }
                    else
                    {
                        return(send_result);
                    }
                }
            }
            return("");
        }
Example #4
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       = BaseService2.GetCookie("wxsid");
            Cookie uin       = BaseService2.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, LoginService2.SKey);

            if (sid != null && uin != null)
            {
                byte[] bytes = BaseService2.SendPostRequest(_sync_url + sid.Value + "&lang=zh_CN&skey=" + LoginService2.SKey + "&pass_ticket=" + LoginService2.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);
            }
        }