Exemple #1
0
        /// <summary>
        /// 登录异常时登录操作
        /// </summary>
        /// <param name="type"></param>
        /// <param name="lstr"></param>
        /// <param name="ltoken"></param>
        /// <param name="vcode"></param>
        /// <returns></returns>
        public dynamic Login2(string type, string lstr, string ltoken, string vcode)
        {
            if (string.IsNullOrEmpty(type))
            {
                return new { code = -1, msg = "type不能为空" }
            }
            ;
            if (string.IsNullOrEmpty(lstr))
            {
                return new { code = -1, msg = "lstr不能为空" }
            }
            ;
            if (string.IsNullOrEmpty(ltoken))
            {
                return new { code = -1, msg = "ltoken不能为空" }
            }
            ;
            if (string.IsNullOrEmpty(vcode))
            {
                return new { code = -1, msg = "vcode不能为空" }
            }
            ;

            string  url      = "https://wappass.baidu.com/wp/login/sec?type=2&v=" + Common.GetTimeStamp() + "0000";
            string  postData = "vcode=" + vcode + "&clientfrom=native&tpl=tb&login_share_strategy=choice&client=android&adapter=3&t=" + Common.GetTimeStamp() + "0000&act=bind_mobile&loginLink=0&smsLoginLink=1&lPFastRegLink=0&fastRegLink=1&lPlayout=0&loginInitType=0&lang=zh-cn&regLink=1&action=login&loginmerge=1&isphone=0&dialogVerifyCode=&dialogVcodestr=&dialogVcodesign=&gid=660BDF6-30E5-4A83-8EAC-F0B4752E1C4B&showtype=" + type + "&lstr=" + RFC3986Encoder.UrlEncode(lstr) + "&ltoken=" + ltoken;
            string  data     = Common.HttpPost(url: url, postDataStr: postData, referer: this._referrer);
            dynamic jsonObj  = Common.JsonStr2Obj(data);

            if (Common.IsPropertyExist(jsonObj, "errInfo") && jsonObj.errInfo.no == "0")
            {
                if (!string.IsNullOrEmpty(jsonObj.data.loginProxy.ToString()))
                {
                    data    = Common.HttpGet(url: jsonObj.data.loginProxy.ToString(), referer: this._referrer);
                    jsonObj = Common.JsonStr2Obj(data);
                }
                data = jsonObj.data.xml;

                string user        = Regex.Match(data, @"<uname>(.*?)</uname>").Groups[1].Value;
                string uid         = Regex.Match(data, @"<uid>(.*?)</uid>").Groups[1].Value;
                string face        = Regex.Match(data, @"<portrait>(.*?)</portrait>").Groups[1].Value;
                string displayname = Regex.Match(data, @"<displayname>(.*?)</displayname>").Groups[1].Value;
                string bduss       = Regex.Match(data, @"<bduss>(.*?)</bduss>").Groups[1].Value;
                string ptoken      = Regex.Match(data, @"<ptoken>(.*?)</ptoken>").Groups[1].Value;
                string stoken      = Regex.Match(data, @"<stoken>(.*?)</stoken>").Groups[1].Value;
                return(new { code = 0, uid = uid, user = user, displayname = displayname, face = face, bduss = bduss, ptoken = ptoken, stoken = stoken });
            }
            else if (Common.IsPropertyExist(jsonObj, "errInfo"))
            {
                return(new { code = jsonObj.errInfo.no, msg = jsonObj.errInfo.msg });
            }
            else
            {
                return(new { code = -1, msg = "登录失败,原因未知" });
            }
        }
Exemple #2
0
        /// <summary>
        /// 登录异常时发送手机/邮件验证码
        /// </summary>
        /// <param name="type"></param>
        /// <param name="lstr"></param>
        /// <param name="ltoken"></param>
        /// <returns></returns>
        public dynamic SendCode(string type, string lstr, string ltoken)
        {
            string  url     = "https://wappass.baidu.com/wp/login/sec?ajax=1&v=" + Common.GetTimeStamp() + "0000&vcode=&clientfrom=native&tpl=tb&login_share_strategy=choice&client=android&adapter=3&t=" + Common.GetTimeStamp() + "0000&act=bind_mobile&loginLink=0&smsLoginLink=1&lPFastRegLink=0&fastRegLink=1&lPlayout=0&loginInitType=0&lang=zh-cn&regLink=1&action=login&loginmerge=1&isphone=0&dialogVerifyCode=&dialogVcodestr=&dialogVcodesign=&gid=660BDF6-30E5-4A83-8EAC-F0B4752E1C4B&showtype=" + type + "&lstr=" + RFC3986Encoder.UrlEncode(lstr) + "&ltoken=" + ltoken;
            string  data    = Common.HttpGet(url: url, referer: this._referrer);
            dynamic jsonObj = Common.JsonStr2Obj(data);

            if (Common.IsPropertyExist(jsonObj, "errInfo") && jsonObj.errInfo.no == "0")
            {
                return(new { code = 0 });
            }
            else if (Common.IsPropertyExist(jsonObj, "errInfo"))
            {
                return(new { code = jsonObj.errInfo.no, msg = jsonObj.errInfo.msg });
            }
            else
            {
                return(new { code = -1, msg = "发生验证码失败,原因未知" });
            }
        }