예제 #1
0
        /// <summary>
        /// 登入系统
        /// </summary>
        /// <param name="account">账号名称</param>
        /// <param name="plainPassword">明文密码</param>
        public bool Login()
        {
            if (string.IsNullOrWhiteSpace(_account) || string.IsNullOrWhiteSpace(_password))
            {
                throw new ArgumentNullException($"登录失败!账号或密码不能为空.");
            }

            if (!LoginTimeout)
            {
                return(true);
            }

            // 1. 打开首页
            string content = _restHelper.Get("home/", null);

            // 2.登录
            //            account=song90273&password=c5cd3674f081bc66dc8e76dc2209a85d&pwdtext=200_daxl5306&loginSrc=0
            string md5Password = EncryptUtil.CreateMD5(_password.Trim());
            var    parameters  = new Dictionary <string, object>
            {
                ["account"]  = _account,
                ["password"] = md5Password,
                ["pwdtext"]  = _password,
                ["loginSrc"] = "0"
            };

            var result = _restHelper.Post <LoginResult>("api/login.do", parameters);

            if (result.State != 1)
            {
                Console.WriteLine("登录失败,请检查用户名或密码是否正确。");
                return(false);
            }

            LoginTimeout = false;

            // 3. 同意协议
            _restHelper.Get("game/", null);

            PrintLog($"{DateTime.UtcNow}\t用户 {result.UserName} 登录成功! 余额:¥{result.Money}");
            return(true);
        }