Exemplo n.º 1
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account">账号实例</param>
        public static void DoLogin(ref Account account)
        {
            /* 旧版参数
             * string parm = "appkey=" + Config.Instance.Appkey + "&build=" + Config.Instance.Build + "&mobi_app=android&password="******"&platform=android&ts=" + TimeStamp + "&username="******"appkey={Config.Instance.Appkey}&bili_local_id={account.DeviceId}&build={Config.Instance.Build}&buvid={account.Buvid}&channel=bili&device=phone&device_id={account.DeviceId}&device_name=BiliAccount{account.DeviceGuid}&device_platform=BiliAccount{Assembly.GetExecutingAssembly().GetName().Version}&from_pv=main.my-information.my-login.0.click&from_url=bilibili%3A%2F%2Fuser_center%2Fmine&local_id={account.Buvid}&mobi_app=android&password={account.EncryptedPassword}&platform=android&statistics=%7B%22appId%22%3A1%2C%22platform%22%3A3%2C%22version%22%3A%22{Config.Instance.Version}%22%2C%22abtest%22%3A%22%22%7D&ts={TimeStamp}&username={account.UserName}";

            parm += "&sign=" + GetSign(parm);
            //string str = Http.PostBodyOutCookies("http://passport.bilibili.com/api/v3/oauth2/login", out account.Cookies, parm, null, "application/x-www-form-urlencoded;charset=utf-8", "", Config.Instance.User_Agent);
            string str = Http.PostBodyOutCookies("https://passport.bilibili.com/x/passport-login/oauth2/login ", out account.Cookies, parm, null, "application/x-www-form-urlencoded;charset=utf-8", "", $"BiliAccount/{Config.Dll_Version}");

            if (!string.IsNullOrEmpty(str))
            {
                DoLogin_DataTemplete obj = JsonConvert.DeserializeObject <DoLogin_DataTemplete>(str);
                switch (obj.code)
                {
                case 0:    //初步登录成功
                    LoginSuccess(obj, ref account);
                    break;

                case -105:    //需要验证码
                    account.Url         = obj.data.url;
                    account.LoginStatus = Account.LoginStatusEnum.NeedCaptcha;
                    break;

                case -629:    //密码错误
                    account.LoginStatus = Account.LoginStatusEnum.WrongPassword;
                    break;

                default:
                    account.LoginStatus = Account.LoginStatusEnum.None;
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public static void DoLoginWithCatpcha(string captcha, ref Account account)
        {
            string parm = "actionKey=" + Config.Instance.Appkey + "&appkey=" + Config.Instance.Appkey + "&build=" + Config.Instance.Build + "&captcha=" + captcha + "&mobi_app=android&password="******"&device=android&platform=android&ts=" + TimeStamp + "&username="******"&sign=" + GetSign(parm);
            //string str = Http.PostBodyOutCookies("http://passport.bilibili.com/api/v3/oauth2/login", out account.Cookies, parm, account.Cookies, "application/x-www-form-urlencoded;charset=utf-8", "", Config.Instance.User_Agent);
            string str = Http.PostBodyOutCookies("https://passport.bilibili.com/x/passport-login/oauth2/login", out account.Cookies, parm, account.Cookies, "application/x-www-form-urlencoded;charset=utf-8", "", $"BiliAccount/{Config.Dll_Version}");

            if (!string.IsNullOrEmpty(str))
            {
                DoLogin_DataTemplete obj = JsonConvert.DeserializeObject <DoLogin_DataTemplete>(str);
                switch (obj.code)
                {
                case 0:    //登录成功
                    LoginSuccess(obj, ref account);
                    break;

                case -105:    //验证码错误
                    account.Url         = obj.data.url;
                    account.LoginStatus = Account.LoginStatusEnum.NeedCaptcha;
                    break;

                case -629:    //密码错误
                    account.LoginStatus = Account.LoginStatusEnum.WrongPassword;
                    break;

                default:
                    account.LoginStatus = Account.LoginStatusEnum.None;
                    break;
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 初步登录成功判断
        /// </summary>
        /// <param name="obj">登录返回数据体</param>
        /// <param name="account">Account实例</param>
        private static void LoginSuccess(DoLogin_DataTemplete obj, ref Account account)
        {
            switch (obj.data.status)
            {
            case 0:    //登陆成功
                account.Uid                 = obj.data.token_info.mid;
                account.AccessToken         = obj.data.token_info.access_token;
                account.RefreshToken        = obj.data.token_info.refresh_token;
                account.Expires_AccessToken = DateTime.Now.AddSeconds(obj.data.token_info.expires_in);

                account.Cookies = new CookieCollection();
                foreach (DoLogin_DataTemplete.Data_Templete.Cookie_Info_Templete.Cookie_Templete i in obj.data.cookie_info.cookies)
                {
                    account.strCookies += i.name + "=" + i.value + "; ";
                    account.Cookies.Add(new Cookie(i.name, i.value)
                    {
                        Domain = ".bilibili.com"
                    });
                    account.Expires_Cookies = DateTime.Parse("1970-01-01 08:00:00").AddSeconds(i.expires);

                    if (i.name == "bili_jct")
                    {
                        account.CsrfToken = i.value;
                    }
                }
                account.strCookies  = account.strCookies.Substring(0, account.strCookies.Length - 2);
                account.LoginStatus = Account.LoginStatusEnum.ByPassword;
                break;

            case 1:    //手机验证
                Regex reg   = new Regex("&tel=.*?&");
                Match match = reg.Match(obj.data.url);
                account.Tel         = match.Value.Substring(5, match.Value.Length - 6);
                account.Url         = obj.data.url;
                account.LoginStatus = Account.LoginStatusEnum.NeedTelVerify;
                break;

            case 3:    //设备登录验证
                account.Url         = obj.data.url;
                account.LoginStatus = Account.LoginStatusEnum.NeedSafeVerify;
                break;

            default:
                break;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account">账号实例</param>
        public static void DoLogin(ref Account account)
        {
            if (!IsInited)
            {
                Init();
            }
            string parm = "appkey=" + Appkey + "&build=" + Build + "&mobi_app=android&password="******"&platform=android&ts=" + TimeStamp + "&username="******"&sign=" + GetSign(parm);
            string str = Http.PostBodyOutCookies("http://passport.bilibili.com/api/v3/oauth2/login", out account.Cookies, parm, null, "application/x-www-form-urlencoded;charset=utf-8", "", User_Agent);

            if (!string.IsNullOrEmpty(str))
            {
#if NETSTANDARD2_0 || NETCORE3_0
                DoLogin_DataTemplete obj = JsonConvert.DeserializeObject <DoLogin_DataTemplete>(str);
#else
                DoLogin_DataTemplete obj = (new JavaScriptSerializer()).Deserialize <DoLogin_DataTemplete>(str);
#endif

                switch (obj.code)
                {
                case 0:    //初步登录成功
                    LoginSuccess(obj, ref account);
                    break;

                case -105:    //需要验证码
                    account.Url         = obj.data.url;
                    account.LoginStatus = Account.LoginStatusEnum.NeedCaptcha;
                    break;

                case -629:    //密码错误
                    account.LoginStatus = Account.LoginStatusEnum.WrongPassword;
                    break;

                default:
                    account.LoginStatus = Account.LoginStatusEnum.None;
                    break;
                }
            }
        }