Exemple #1
0
        /// <summary>
        /// 登录扫描检测
        /// </summary>
        /// <returns></returns>
        public object LoginCheck()
        {
            if (session_id == null)
            {
                return(null);
            }
            //查看是否扫码登录了
            byte[] bytes = BaseService.Request(StaticUrl.Url_WaitLogin + session_id + "&tip=0&r=" + ~DateTime.Now.ToTimeStamp() + "&_=" + DateTime.Now.ToTimeStamp(), MethodEnum.GET);

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

            if (login_result.Contains("=" + StaticCode.LoginCode.code_LoginSuccess))
            {
                string login_redirect_url = login_result.Split(new string[] { "\"" }, StringSplitOptions.None)[1];
                string string_url_front   = login_redirect_url.Split(new string[] { "?" }, StringSplitOptions.None)[0];
                if (string_url_front.IndexOf("wx2.qq.com") > -1)
                {
                    StaticUrl.stringWx      = "https://wx2.qq.com";
                    StaticUrl.stringWebPush = "https://webpush2.weixin.qq.com";
                }
                if (string_url_front.IndexOf("wx.qq.com") > -1)
                {
                    StaticUrl.stringWx      = "https://wx.qq.com";
                    StaticUrl.stringWebPush = "https://webpush.weixin.qq.com";
                }
                if (string_url_front.IndexOf("web1.wechat.com") > -1)
                {
                    StaticUrl.stringWx      = "https://web.wechat.com";
                    StaticUrl.stringWebPush = "https://webpush1.wechat.com";
                }
                if (string_url_front.IndexOf("web2.wechat.com") > -1)
                {
                    StaticUrl.stringWx      = "https://web.wechat.com";
                    StaticUrl.stringWebPush = "https://webpush2.wechat.com";
                }
                if (string_url_front.IndexOf("web.wechat.com") > -1)
                {
                    StaticUrl.stringWx      = "https://web.wechat.com";
                    StaticUrl.stringWebPush = "https://webpush.wechat.com";
                }
                if (string_url_front.IndexOf("web1.wechatapp.com") > -1)
                {
                    StaticUrl.stringWx      = "https://web.wechatapp.com";
                    StaticUrl.stringWebPush = "https://webpush1.wechatapp.com";
                }
                if (string_url_front.IndexOf("web.wechatapp.com") > -1)
                {
                    StaticUrl.stringWx      = "https://web.wechatapp.com";
                    StaticUrl.stringWebPush = "https://webpush.wechatapp.com";
                }
                return(login_redirect_url);
            }
            else if (login_result.Contains("=" + StaticCode.LoginCode.code_LoginWait))
            {
                if (login_result.Contains("\'"))
                {
                    string       base64_image       = login_result.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);
                    //转成图片
                    return(ImageHelper.MemoryToImageSource(memoryStream));
                }
                else
                {
                    return(WeChatClientConst.DefaultHeadImage);
                }
            }
            //注:如果用超时的话,会有问题,后期再研究
            //else if (login_result.Contains("=" + StaticCode.LoginCode.code_LoginTimeOut))
            //{
            //    session_id = null;
            //    return 408;
            //}
            else
            {
                return(null);
            }
        }