예제 #1
0
        /// <summary>
        /// 微信同步检测(检查是否有新消息)
        /// </summary>
        /// <returns></returns>
        public static string WxSyncCheck()
        {
            string datetime = LoginService.GetTimeStamp();
            string sync_key = "";

            foreach (KeyValuePair <string, string> p in _syncKey)
            {
                sync_key += p.Key + "_" + p.Value + "%7C";
            }
            sync_key = sync_key.TrimEnd('%', '7', 'C');

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

            if (sid != null && uin != null)
            {
                //同步检查url
                string _synccheckUrl = InterFaceURL._synccheck_url + string.Format("&sid={0}&uin={1}&synckey={2}&skey={3}&deviceid={4}", sid.Value, uin.Value, sync_key, LoginService.sKey, "e1615250492");

                byte[] bytes = RequstService.SendGetRequest(_synccheckUrl + "&pass_ticket=" + LoginService.pass_Ticket + "&_=" + datetime);
                if (bytes != null)
                {
                    return(Encoding.UTF8.GetString(bytes));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// 获取sid、uin
        /// </summary>
        public void GetSidUin(string loginRedirect)
        {
            byte[] bytes       = RequstService.SendGetRequest(loginRedirect + "&fun=new");
            string pass_ticket = Encoding.UTF8.GetString(bytes);

            pass_Ticket = pass_ticket.Split(new string[] { "pass_ticket" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
            sKey        = pass_ticket.Split(new string[] { "skey" }, StringSplitOptions.None)[1].TrimStart('>').TrimEnd('<', '/');
        }
예제 #3
0
        /// <summary>
        /// 接收聊天图片base64
        /// </summary>
        /// <param name="MsgId"></param>
        /// <returns></returns>
        public static string Image(string MsgId)
        {
            Cookie sid = RequstService.GetCookie("wxsid");
            Cookie uin = RequstService.GetCookie("wxuin");

            if (sid != null && uin != null)
            {
                byte[] bytes = RequstService.SendGetRequest(InterFaceURL._image_url + sid.Value + "&lang=zh_CN&skey=" + LoginService.sKey + "&pass_ticket=" + LoginService.pass_Ticket + "&username="******"&type=slave&MsgID=" + MsgId);
                return(Convert.ToBase64String(bytes));
            }
            else
            {
                return(null);
            }
        }
예제 #4
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;
     }
 }
예제 #5
0
 /// <summary>
 /// 登录扫描检测
 /// </summary>
 /// <returns></returns>
 public object LoginScanDetection()
 {
     try
     {
         if (_uuid == null)
         {
             return(null);
         }
         string datetime = GetTimeStamp();
         //等待登录 判断二维码扫描情况  408 登陆超时 201 扫描成功 200 确认登录
         string _loginScanDetection_url = "https://login.weixin.qq.com/cgi-bin/mmwebwx-bin/login?loginicon=true&_=" + datetime + "&tip=" + tip + "&uuid="; //后面增加UUID
         byte[] bytes = RequstService.SendGetRequest(_loginScanDetection_url + _uuid);
         if (bytes == null)
         {
             return(null);
         }
         string loginResult = Encoding.UTF8.GetString(bytes);
         if (loginResult.Contains("=201")) // 已扫描二维码但未登录
         {
             string       base64_image       = loginResult.Split(new string[] { "\'" }, StringSplitOptions.None)[1].Split(',')[1];
             byte[]       base64_image_bytes = Convert.FromBase64String(base64_image);
             MemoryStream memoryStream       = new MemoryStream(base64_image_bytes, 0, base64_image_bytes.Length);
             memoryStream.Write(base64_image_bytes, 0, base64_image_bytes.Length);
             return(Image.FromStream(memoryStream));
         }
         else if (loginResult.Contains("=200"))  //已扫描二维码并完成登录
         {
             string login_redirect_url = loginResult.Split(new string[] { "\"" }, StringSplitOptions.None)[1];
             return(login_redirect_url);
         }
         else
         {
             return(null);
         }
     }
     catch (Exception ex)
     {
         throw;
     }
 }
예제 #6
0
        /// <summary>
        /// 获取微信讨论组头像
        /// </summary>
        /// <param name="usename"></param>
        /// <returns></returns>
        public Image GetHeadImg(string usename)
        {
            byte[] bytes = RequstService.SendGetRequest(InterFaceURL._getheadimg_url + usename);

            return(Image.FromStream(new MemoryStream(bytes)));
        }
예제 #7
0
        /// <summary>
        /// 获取好友头像
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public Image GetIcon(string username)
        {
            byte[] bytes = RequstService.SendGetRequest(InterFaceURL._geticon_url + username);

            return(Image.FromStream(new MemoryStream(bytes)));
        }