Exemple #1
0
        private async Task GetbfWebTokenAsync(string skey, string akey)
        {
            NameValueCollection postData = new NameValueCollection
            {
                { "SessionKey", skey },
                { "AuthKey", akey }
            };
            var request = await CreateWebRequestPostAsync("https://tw.beanfun.com/beanfun_block/bflogin/return.aspx", postData);

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
            {
                var cc      = request.CookieContainer;
                var beanfun = cc.GetCookies(new Uri("https://tw.beanfun.com"));
                foreach (Cookie cook in beanfun)
                {
                    if (cook.Name == "bfWebToken")
                    {
                        bfWebToken = cook.Value;
                    }
                }
            }
            if (string.IsNullOrEmpty(bfWebToken))
            {
                throw new Exception("GetGameAccount Failed: No bfWebToken");
            }
        }
Exemple #2
0
        private async Task <string> GeneralLoginAsync(string accountID, string password, string skey)
        {
            var info = await GetASPInfo("https://tw.newlogin.beanfun.com/login/id-pass_form.aspx?skey=" + skey);

            string viewstate       = info.Item1;
            string eventvalidation = info.Item2;

            // Post Id-Password
            NameValueCollection postData = new NameValueCollection
            {
                { "__VIEWSTATE", viewstate },
                { "__EVENTVALIDATION", eventvalidation },
                { "t_AccountID", accountID },
                { "t_Password", password },
                { "btn_login", "登入" }
            };

            var requestPost = await CreateWebRequestPostAsync("https://tw.newlogin.beanfun.com/login/id-pass_form.aspx?skey=" + skey, postData);

            string akey = string.Empty;

            using (var response = await WebRequestExtensions.GetResponseAsync(requestPost, MillisecondsTimeout))
                akey = ParseAkey(response.ResponseUri.ToString());
            if (string.IsNullOrEmpty(akey))
            {
                throw new Exception("GeneralLogin Failed: No Authkey");
            }
            return(akey);
        }
        private async Task <string> QRCodeCheckSuccessAsync(string skey)
        {
            var request = CreateWebRequest("https://tw.newlogin.beanfun.com/login/qr_step2.aspx?skey=" + skey);

            string akey = null;

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
                using (Stream ReceiveStream = response.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                    {
                        string text  = readStream.ReadToEnd();
                        Regex  regex = new Regex("akey=([^&]+)");
                        if (regex.IsMatch(text))
                        {
                            var match = regex.Match(text);
                            akey = regex.Match(text).Groups[1].Value;
                        }
                    }

            if (string.IsNullOrEmpty(akey))
            {
                return(null);
            }

            request = CreateWebRequest("https://tw.newlogin.beanfun.com/login/final_step.aspx?akey=" + akey + "&authkey=N&bfapp=1");

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
                return(akey);
        }
        // {"Result":0,"ResultMessage":"Failed","ResultData":null}
        private async Task <bool> QRCodeCheckAsync(string strEncryptData)
        {
            NameValueCollection postData = new NameValueCollection
            {
                { "status", strEncryptData }
            };
            var checkRequest = await CreateWebRequestPostAsync("https://tw.newlogin.beanfun.com/generic_handlers/CheckLoginStatus.ashx", postData);

            try
            {
                using (var response = await WebRequestExtensions.GetResponseAsync(checkRequest, MillisecondsTimeout, false))
                    using (Stream ReceiveStream = response.GetResponseStream())
                        using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                        {
                            string text = await readStream.ReadToEndAsync();

                            string ResultMessage = null;
                            int    Result        = 0;

                            Regex regex_ResultMessage = new Regex("\"ResultMessage\":\"([^\"]+)\"");
                            Regex regex_Result        = new Regex("\"Result\":([0-9])");
                            if (regex_ResultMessage.IsMatch(text))
                            {
                                ResultMessage = regex_ResultMessage.Match(text).Groups[1].Value;
                            }
                            if (regex_Result.IsMatch(text))
                            {
                                int.TryParse(regex_Result.Match(text).Groups[1].Value, out Result);
                            }

                            Console.WriteLine(text);

                            if (Result == 1 && ResultMessage == "Success")
                            {
                                return(true);
                            }
                            else if (Result == 0 && ResultMessage == "Token Expired")
                            {
                                MessageBox.Show("QRCode Token Expired. Please Try Again.");
                            }
                            else
                            {
                                await Task.Delay(2 * 1000);

                                if (IsQRFormOpened)
                                {
                                    return(await QRCodeCheckAsync(strEncryptData));
                                }
                            }
                        }
            }
            catch (Exception e)
            {
                MessageBox.Show("Something Wrong!\n" + e.Message);
            }

            return(false);
        }
Exemple #5
0
        private async Task <string> GetSessionkeyAsync()
        {
            var webRequest = CreateWebRequest("https://tw.beanfun.com/beanfun_block/bflogin");

            webRequest.UserAgent       = UserAgent;
            webRequest.CookieContainer = CookieContainer;

            using (var response = await WebRequestExtensions.GetResponseAsync(webRequest, MillisecondsTimeout))
            {
                var skey = ParseSkey(response.ResponseUri.ToString());
                if (string.IsNullOrEmpty(skey))
                {
                    throw new Exception("GeneralLogin Failed: No Sessionkey");
                }
                return(skey);
            }
        }
Exemple #6
0
        private async Task <Tuple <string, string> > GetASPInfo(string uri)
        {
            var request = CreateWebRequest(uri);

            string viewstate       = null;
            string eventvalidation = null;

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
                using (Stream ReceiveStream = response.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                        while (!readStream.EndOfStream)
                        {
                            string line = readStream.ReadLine();
                            if (line.Contains("VIEWSTATE"))
                            {
                                Regex regex = new Regex("id=\"__VIEWSTATE\" value=\"(.*)\" />");
                                if (regex.IsMatch(line))
                                {
                                    viewstate = regex.Match(line).Groups[1].Value;
                                }
                            }
                            else if (line.Contains("__EVENTVALIDATION"))
                            {
                                Regex regex = new Regex("id=\"__EVENTVALIDATION\" value=\"(.*)\" />");
                                if (regex.IsMatch(line))
                                {
                                    eventvalidation = regex.Match(line).Groups[1].Value;
                                }
                            }
                        }

            if (string.IsNullOrEmpty(viewstate))
            {
                throw new Exception("GeneralLogin Failed: No ViewState");
            }
            if (string.IsNullOrEmpty(eventvalidation))
            {
                throw new Exception("GeneralLogin Failed: No Eventvalidation");
            }

            //viewstate = Uri.EscapeDataString(viewstate);
            //eventvalidation = Uri.EscapeDataString(eventvalidation);
            return(new Tuple <string, string>(viewstate, eventvalidation));
        }
Exemple #7
0
        private async Task <string> QRCodeLoginAsync(string skey)
        {
            var request = CreateWebRequest("https://tw.newlogin.beanfun.com/generic_handlers/get_qrcodeData.ashx?skey=" + skey);

            string strEncryptData = null;

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
                using (Stream ReceiveStream = response.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                        while (!readStream.EndOfStream)
                        {
                            string line = readStream.ReadLine();
                            line = line.Replace(" ", "");
                            if (line.Contains("strEncryptData"))
                            {
                                Regex regex = new Regex("\"strEncryptData\":\"([^\"]+)\"");
                                if (regex.IsMatch(line))
                                {
                                    strEncryptData = regex.Match(line).Groups[1].Value;
                                    break;
                                }
                            }
                        }

            if (string.IsNullOrEmpty(strEncryptData))
            {
                throw new Exception("QRCodeLogin Failed: No strEncryptData");
            }

            bool Result = await ShowQRCode(strEncryptData);

            if (Result)
            {
                var akey = await QRCodeCheckSuccessAsync(skey);

                return(akey);
            }
            else
            {
                return(null);
                //throw new Exception("QRCodeLogin Failed: No Authkey");
            }
        }
        private async Task <bool> ShowQRCode(string strEncryptData)
        {
            CloseQRForm();

            var request = CreateWebRequest(
                "https://tw.newlogin.beanfun.com/qrhandler.ashx?u=https://beanfunstor.blob.core.windows.net/redirect/appCheck.html?url=beanfunapp://Q/gameLogin/gtw/" +
                strEncryptData);

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
                using (Stream ReceiveStream = response.GetResponseStream())
                    using (var image = System.Drawing.Image.FromStream(ReceiveStream))
                    {
                        if (QRForm == null)
                        {
                            QRForm = new Form();
                        }
                        QRForm.StartPosition = FormStartPosition.CenterScreen;
                        QRForm.AutoSize      = true;
                        QRForm.AutoSizeMode  = AutoSizeMode.GrowOnly;

                        var pb = new PictureBox
                        {
                            Dock  = DockStyle.Fill,
                            Image = image
                        };
                        pb.SizeMode = PictureBoxSizeMode.CenterImage;

                        IsQRFormOpened = true;
                        bool Result = false;
                        QRForm.Load += async(o, e) =>
                        {
                            Result = await QRCodeCheckAsync(strEncryptData);

                            CloseQRForm();
                        };
                        QRForm.FormClosed += (o, e) => IsQRFormOpened = false;
                        QRForm.Controls.Add(pb);
                        QRForm.ShowDialog();
                        return(Result);
                    }
        }
Exemple #9
0
        private async Task GetGameAccountAsync(string skey, string akey, LoginMethod method, string cardid)
        {
            await GetbfWebTokenAsync(skey, akey);

            string authUri = "https://tw.beanfun.com/beanfun_block/auth.aspx?channel=game_zone&page_and_query=game_start.aspx%3Fservice_code_and_region%3D" + service_code + "_" + service_region + "&web_token=" + bfWebToken;

            var request = CreateWebRequest(authUri);

            using (var response = await WebRequestExtensions.GetResponseAsync(request, MillisecondsTimeout))
                using (Stream ReceiveStream = response.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                        while (!readStream.EndOfStream)
                        {
                            string line = readStream.ReadLine();
                            if (line.Contains("id=\"ulServiceAccountList\" class=\"ServiceAccountList\""))
                            {
                                line = readStream.ReadLine();
                                accountList.Clear();
                                var regex = new Regex("<div id=\"(\\w+)\" sn=\"(\\d+)\" name=\"([^\"]+)\"");
                                foreach (Match match in regex.Matches(line))
                                {
                                    if (match.Groups[1].Value == "" || match.Groups[2].Value == "" || match.Groups[3].Value == "")
                                    {
                                        throw new Exception("GetGameAccount Failed: No AccountList");
                                    }
                                    accountList.Add(new GameAccount(match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value));
                                }
                                break;
                            }
                        }

            if (accountList.Count == 0)
            {
                throw new Exception("GetGameAccount Failed: No AccountList");
            }
        }
Exemple #10
0
        private async System.Threading.Tasks.Task <string> GetOTPAsync(GameAccount acc, string service_code, string service_region)
        {
            string longPollingKey = "";

            var webRequest = CreateWebRequest("https://tw.beanfun.com/beanfun_block/game_zone/game_start_step2.aspx?service_code=" + service_code + "&service_region=" + service_region + "&sotp=" + acc.sotp);

            using (var r = await WebRequestExtensions.GetResponseAsync(webRequest, MillisecondsTimeout))
                using (Stream ReceiveStream = r.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                        while (!readStream.EndOfStream)
                        {
                            var line = readStream.ReadLine();
                            if (line.Contains("GetResultByLongPolling"))
                            {
                                Regex regex = new Regex("GetResultByLongPolling&key=(.*)\"");
                                if (!regex.IsMatch(line))
                                {
                                    throw new Exception("GetGamePassword Failed: OTPNoLongPollingKey");
                                }
                                longPollingKey = regex.Match(line).Groups[1].Value;
                            }
                            else if (string.IsNullOrEmpty(acc.screatetime) && line.Contains("ServiceAccountCreateTime"))
                            {
                                Regex regex = new Regex("ServiceAccountCreateTime: \"([^\"]+)\"");
                                if (!regex.IsMatch(line))
                                {
                                    throw new Exception("GetGamePassword Failed: OTPNoCreateTime");
                                }
                                acc.screatetime = regex.Match(line).Groups[1].Value;
                            }
                        }

            string secretCode = "";

            webRequest = CreateWebRequest("https://tw.newlogin.beanfun.com/generic_handlers/get_cookies.ashx");
            using (var r = await WebRequestExtensions.GetResponseAsync(webRequest, MillisecondsTimeout))
                using (Stream ReceiveStream = r.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                        while (!readStream.EndOfStream)
                        {
                            var line = readStream.ReadLine();
                            if (line.Contains("m_strSecretCode"))
                            {
                                Regex regex = new Regex("var m_strSecretCode = '(.*)';");
                                if (!regex.IsMatch(line))
                                {
                                    throw new Exception("GetGamePassword Failed: OTPNoSecretCode");
                                }
                                secretCode = regex.Match(line).Groups[1].Value;
                                break;
                            }
                        }

            webRequest = CreateWebRequest("http://tw.beanfun.com/beanfun_block/generic_handlers/get_webstart_otp.ashx?SN=" + longPollingKey + "&WebToken=" + bfWebToken + "&SecretCode=" + secretCode + "&ppppp=1F552AEAFF976018F942B13690C990F60ED01510DDF89165F1658CCE7BC21DBA&ServiceCode=" + service_code + "&ServiceRegion=" + service_region + "&ServiceAccount=" + acc.sacc + "&CreateTime=" + acc.screatetime.Replace(" ", "%20") + "&d=" + Environment.TickCount);
            using (var r = await WebRequestExtensions.GetResponseAsync(webRequest, MillisecondsTimeout))
                using (Stream ReceiveStream = r.GetResponseStream())
                    using (StreamReader readStream = new StreamReader(ReceiveStream, Encoding.UTF8))
                    {
                        string DESValue = readStream.ReadToEnd();
                        DESValue = DESValue.Substring(2);
                        string key   = DESValue.Substring(0, 8);
                        string plain = DESValue.Substring(8);
                        string otp   = DecryptDES(plain, key);
                        if (string.IsNullOrEmpty(otp))
                        {
                            throw new Exception("GetGamePassword Failed: Decrypt OTP Failed");
                        }
                        return(otp);
                    }
        }