예제 #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        public static JObject Load()
        {
            try
            {
                // await Task.Factory.StartNew(() =>
                // {
                if (sid != null && uin != null)
                {
                    string  init_json   = string.Format("{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"{2}\",\"DeviceID\":\"e1615250492\"}}}}", uin.Value, sid.Value, LoginService.sKey);
                    byte[]  bytes       = RequstService.SendPostRequest(InterFaceURL._init_url + "&pass_ticket=" + LoginService.pass_Ticket, init_json);
                    string  init_str    = Encoding.UTF8.GetString(bytes);
                    JObject init_result = JsonConvert.DeserializeObject(init_str) as JObject;
                    _syncKey = new Dictionary <string, string>();
                    foreach (JObject synckey in init_result["SyncKey"]["List"])  //同步键值
                    {
                        if (!_syncKey.ContainsKey(synckey["Key"].ToString()))
                        {
                            _syncKey.Add(synckey["Key"].ToString(), synckey["Val"].ToString());
                        }
                    }
                    userInfo = jsonSerialize.Deserialize <UserInfo>(init_result["User"].ToString());

                    return(init_result);
                }
                return(null);
                //  });
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
예제 #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 = "";

            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 = RequstService.GetCookie("wxsid");
            Cookie uin = RequstService.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);
                byte[] bytes = null;
                switch (type)
                {
                case 1:
                    bytes = RequstService.SendPostRequest(InterFaceURL._sendmsg_url + sid.Value + "&lang=zh_CN&pass_ticket=" + LoginService.pass_Ticket, msg_json);
                    break;

                case 3:
                    bytes = RequstService.SendPostRequest(InterFaceURL._send_image_url + sid.Value + "&lang=zh_CN&pass_ticket=" + LoginService.pass_Ticket, msg_json);
                    break;
                }

                string send_result = Encoding.UTF8.GetString(bytes);
            }
        }
예제 #3
0
 /// <summary>
 /// 获取二维码
 /// </summary>
 /// <returns></returns>
 public Image GetQRCode()
 {
     try
     {
         string datetime = GetTimeStamp();
         //获取UUID的URL
         string _appid_url = "https://login.weixin.qq.com/jslogin?appid=wx782c26e4c19acffb&fun=new&lang=zh_CN&_=" + datetime + "";
         //获取二维码的URL
         string _qrcode_url = "https://login.weixin.qq.com/qrcode/"; //后面增加UUID
         byte[] bytes       = RequstService.SendGetRequest(_appid_url);
         _uuid = Encoding.UTF8.GetString(bytes).Split(new string[] { "\"" }, StringSplitOptions.None)[1];
         bytes = RequstService.SendPostRequest(_qrcode_url + _uuid, "t=webwx&_=" + datetime + "");
         Image qrCode = Image.FromStream(new MemoryStream(bytes));
         return(qrCode);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
예제 #4
0
        /// <summary>
        /// 微信同步(获取最新消息)
        /// </summary>
        /// <returns></returns>
        public static JObject WxSync()
        {
            string sync_json = "{{\"BaseRequest\" : {{\"DeviceID\":\"e1615250492\",\"Sid\":\"{1}\", \"Skey\":\"{5}\", \"Uin\":\"{0}\"}},\"SyncKey\" : {{\"Count\":{2},\"List\":[{3}]}},\"rr\" :{4}}}";
            Cookie sid       = RequstService.GetCookie("wxsid");
            Cookie uin       = RequstService.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    = RequstService.SendPostRequest(InterFaceURL._sync_url + sid.Value + "&lang=zh_CN&skey=" + LoginService.sKey + "&pass_ticket=" + LoginService.pass_Ticket, sync_json);
                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"])
                    {
                        if (!_syncKey.ContainsKey(key["Key"].ToString()))
                        {
                            _syncKey.Add(key["Key"].ToString(), key["Val"].ToString());
                        }
                    }
                }
                return(sync_resul);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        /// <summary>
        /// 获取好友列表数据
        /// </summary>
        public static JObject Friends()
        {
            try
            {
                if (sid != null && uin != null)
                {
                    string init_json = string.Format("{{\"BaseRequest\":{{\"Uin\":\"{0}\",\"Sid\":\"{1}\",\"Skey\":\"{2}\",\"DeviceID\":\"e1615250492\"}}}}", uin.Value, sid.Value, LoginService.sKey);

                    byte[] bytesFriends = RequstService.SendPostRequest(InterFaceURL._friends_url + "&pass_ticket=" + LoginService.pass_Ticket, init_json);
                    if (bytesFriends == null)
                    {
                        return(null);
                    }
                    string friends_str = Encoding.UTF8.GetString(bytesFriends);
                    friends_result = JsonConvert.DeserializeObject(friends_str) as JObject;
                    return(friends_result);
                }
                return(null);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }