private string QRCodeLogin(QRCodeClass qrcodeclass) { try { string skey = qrcodeclass.skey; this.Headers.Set("Referer", @"https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); this.redirect = false; byte[] tmp2 = this.DownloadData("https://tw.newlogin.beanfun.com/login/qr_step2.aspx?skey=" + skey); this.redirect = true; string response2 = Encoding.UTF8.GetString(tmp2); Debug.Write(response2); Regex regex2 = new Regex("akey=(.*)&authkey"); if (!regex2.IsMatch(response2)) { this.errmsg = "AKeyParseFailed"; return(null); } string akey = regex2.Match(response2).Groups[1].Value; regex2 = new Regex("authkey=(.*)&"); if (!regex2.IsMatch(response2)) { this.errmsg = "authkeyParseFailed"; return(null); } string authkey = regex2.Match(response2).Groups[1].Value; Debug.WriteLine(authkey); string test = this.DownloadString("https://tw.newlogin.beanfun.com/login/final_step.aspx?akey=" + akey + "&authkey=" + authkey + "&bfapp=1"); return(akey); } catch (Exception e) { this.errmsg = "LoginUnknown\n\n" + e.Message + "\n" + e.StackTrace; return(null); } }
public QRCodeClass GetQRCodeValue(string skey) { string response = this.DownloadString("https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); Regex regex = new Regex("id=\"__VIEWSTATE\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoViewstate"; return(null); } string viewstate = regex.Match(response).Groups[1].Value; regex = new Regex("id=\"__EVENTVALIDATION\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoEventvalidation"; return(null); } string eventvalidation = regex.Match(response).Groups[1].Value; //Thread.Sleep(3000); regex = new Regex("\\$\\(\"#theQrCodeImg\"\\).attr\\(\"src\", \"../(.*)\" \\+ obj.strEncryptData\\);"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoHash"; return(null); } string value = regex.Match(response).Groups[1].Value; response = this.DownloadString("https://tw.newlogin.beanfun.com/generic_handlers/get_qrcodeData.ashx?skey=" + skey); regex = new Regex("\"strEncryptData\": \"(.*)\"}"); if (!regex.IsMatch(response)) { this.errmsg = "LoginIntResultError"; return(null); } string strEncryptData = regex.Match(response).Groups[1].Value; value += strEncryptData; Stream stream = this.OpenRead("https://tw.newlogin.beanfun.com/" + value); QRCodeClass res = new QRCodeClass(); res.skey = skey; res.viewstate = viewstate; res.eventvalidation = eventvalidation; res.value = strEncryptData; res.bitmap = new Bitmap(stream); return(res); }
public int QRCodeCheckLoginStatus(QRCodeClass qrcodeclass) { try { string skey = qrcodeclass.skey; int errorCount = 0; string result; this.Headers.Set("Referer", @"https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); NameValueCollection payload = new NameValueCollection(); payload.Add("data", qrcodeclass.value); //Debug.WriteLine(qrcodeclass.value); string response = Encoding.UTF8.GetString(this.UploadValues("https://tw.bfapp.beanfun.com/api/Check/CheckLoginStatus", payload)); Regex regex = new Regex("\"ResultMessage\":\"(.*)\",\"ResultDat"); if (!regex.IsMatch(response)) { this.errmsg = "LoginJsonParseFailed"; return(-1); } result = regex.Match(response).Groups[1].Value; Debug.WriteLine(result); if (result == "Failed") { return(0); } else if (result == "Token Expired") { //this.errmsg = "登入逾時,請重新取得QRCode"; return(-2); } else if (result == "Success") { return(1); } else { this.errmsg = response; return(-1); } } catch (Exception e) { this.errmsg = "Network Error on QRCode checking login status\n\n" + e.Message + "\n" + e.StackTrace; } return(-1); }
public int QRCodeCheckLoginStatus(QRCodeClass qrcodeclass) { try { string skey = qrcodeclass.skey; //int errorCount = 0; string result; this.Headers.Set("Referer", @"https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); NameValueCollection payload = new NameValueCollection(); payload.Add(qrcodeclass.oldAppQRCode ? "data" : "status", qrcodeclass.value); //Debug.WriteLine(qrcodeclass.value); string response = this.UploadString(qrcodeclass.oldAppQRCode ? "https://tw.bfapp.beanfun.com/api/Check/CheckLoginStatus" : "https://tw.newlogin.beanfun.com/generic_handlers/CheckLoginStatus.ashx", payload); JObject jsonData; try { jsonData = JObject.Parse(response); } catch { this.errmsg = "LoginJsonParseFailed"; return(-1); } result = (string)jsonData["ResultMessage"]; Console.WriteLine(result); if (result == "Failed") { return(0); } else if (result == "Token Expired") { //this.errmsg = "登入逾時,請重新取得QRCode"; return(-2); } else if (result == "Success") { return(1); } else { this.errmsg = response; return(-1); } } catch (Exception e) { this.errmsg = "Network Error on QRCode checking login status\n\n" + e.Message + "\n" + e.StackTrace; } return(-1); }
public BitmapImage getQRCodeImage(QRCodeClass qrcodeclass) { BitmapImage result; try { byte[] buffer = this.DownloadData(qrcodeclass.bitmapUrl + (qrcodeclass.oldAppQRCode ? "" : qrcodeclass.value)); result = new BitmapImage(); result.BeginInit(); result.StreamSource = new MemoryStream(buffer); result.EndInit(); } catch (Exception) { result = null; } return(result); }
public QRCodeClass GetQRCodeValue(string skey) { string resp = this.DownloadString("https://tw.newlogin.beanfun.com/login/id-pass_form.aspx?skey=" + skey); string response = this.DownloadString("https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); Regex regex = new Regex("id=\"__VIEWSTATE\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoViewstate"; return(null); } string viewstate = regex.Match(response).Groups[1].Value; regex = new Regex("id=\"__EVENTVALIDATION\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoEventvalidation"; return(null); } string eventvalidation = regex.Match(response).Groups[1].Value; //Thread.Sleep(3000); regex = new Regex("u=(.*)\" style"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoHash"; return(null); } string value = regex.Match(response).Groups[1].Value; Stream stream = this.OpenRead("http://tw.newlogin.beanfun.com/qrhandler.ashx?u=" + value); QRCodeClass res = new QRCodeClass(); res.skey = skey; res.viewstate = viewstate; res.eventvalidation = eventvalidation; res.value = Uri.UnescapeDataString(value); res.bitmap = new Bitmap(stream); return(res); }
public void Login(string id, string pass, int loginMethod, QRCodeClass qrcodeClass = null, string service_code = "610074", string service_region = "T9") { try { string response = null; Regex regex; string skey = null; string akey = null; string cardid = null; if (loginMethod == (int)LoginMethod.QRCode) { skey = qrcodeClass.skey; } else { skey = GetSessionkey(); } switch (loginMethod) { case (int)LoginMethod.Regular: akey = RegularLogin(id, pass, skey); break; case (int)LoginMethod.Keypasco: akey = KeypascoLogin(id, pass, skey); break; case (int)LoginMethod.PlaySafe: string r = playsafeLogin(id, pass, skey); if (r == null) { return; } string[] temp = r.Split(' '); if (temp.Count() != 2) { this.errmsg = "LoginPlaySafeResultError"; return; } cardid = temp[0]; akey = temp[1]; break; case (int)LoginMethod.QRCode: akey = QRCodeLogin(qrcodeClass); break; default: this.errmsg = "LoginNoMethod"; return; } if (akey == null) { return; } NameValueCollection payload = new NameValueCollection(); payload.Add("SessionKey", skey); payload.Add("AuthKey", akey); Debug.WriteLine(skey); Debug.WriteLine(akey); response = Encoding.UTF8.GetString(this.UploadValues("https://tw.beanfun.com/beanfun_block/bflogin/return.aspx", payload)); Debug.WriteLine(response); response = this.DownloadString("https://tw.beanfun.com/" + this.ResponseHeaders["Location"]); Debug.WriteLine(response); Debug.WriteLine(this.ResponseHeaders); this.webtoken = this.GetCookie("bfWebToken"); if (this.webtoken == "") { this.errmsg = "LoginNoWebtoken"; return; } if (loginMethod == (int)LoginMethod.PlaySafe) { response = this.DownloadString("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=" + webtoken + "&cardid=" + cardid, Encoding.UTF8); } else { response = this.DownloadString("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=" + webtoken, Encoding.UTF8); } if (loginMethod == (int)LoginMethod.PlaySafe) { regex = new Regex("id=\"__VIEWSTATE\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoViewstate"; return; } string viewstate = regex.Match(response).Groups[1].Value; regex = new Regex("id=\"__EVENTVALIDATION\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoEventvalidation"; return; } string eventvalidation = regex.Match(response).Groups[1].Value; payload = new NameValueCollection(); payload.Add("__VIEWSTATE", viewstate); payload.Add("__EVENTVALIDATION", eventvalidation); payload.Add("btnCheckPLASYSAFE", "Hidden+Button"); response = Encoding.UTF8.GetString(this.UploadValues("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=" + webtoken + "&cardid=" + cardid, payload)); } // Add account list to ListView. regex = new Regex("<div id=\"(\\w+)\" sn=\"(\\d+)\" name=\"([^\"]+)\""); this.accountList.Clear(); foreach (Match match in regex.Matches(response)) { if (match.Groups[1].Value == "" || match.Groups[2].Value == "" || match.Groups[3].Value == "") { continue; } accountList.Add(new AccountList(match.Groups[1].Value, match.Groups[2].Value, match.Groups[3].Value)); } if (accountList.Count == 0) { this.errmsg = "LoginNoAccount"; return; } this.errmsg = null; } catch (Exception e) { if (e is WebException) { this.errmsg = "網路連線錯誤,請檢查官方網站連線是否正常。" + e.Message; } else { this.errmsg = "LoginUnknown\n\n" + e.Message + "\n" + e.StackTrace; } return; } }
public void Login(string id, string pass, int loginMethod, QRCodeClass qrcodeClass = null, string service_code = "610074", string service_region = "T9") { this.cardid = null; this.webtoken = null; try { string response = null; string skey = null; string akey = null; string cardid = null; if (loginMethod == (int)LoginMethod.QRCode) { skey = qrcodeClass.skey; } else { skey = GetSessionkey(); } switch (loginMethod) { case (int)LoginMethod.Regular: akey = RegularLogin(id, pass, skey); break; case (int)LoginMethod.Keypasco: akey = KeypascoLogin(id, pass, skey); break; case (int)LoginMethod.PlaySafe: string r = playsafeLogin(id, pass, skey); if (r == null) { return; } string[] temp = r.Split(' '); if (temp.Count() != 2) { this.errmsg = "LoginPlaySafeResultError"; return; } cardid = temp[0]; akey = temp[1]; this.cardid = cardid; break; case (int)LoginMethod.QRCode: akey = QRCodeLogin(qrcodeClass); break; default: this.errmsg = "LoginNoMethod"; return; } if (akey == null) { return; } NameValueCollection payload = new NameValueCollection(); payload.Add("SessionKey", skey); payload.Add("AuthKey", akey); Debug.WriteLine(skey); Debug.WriteLine(akey); response = Encoding.UTF8.GetString(this.UploadValues("https://tw.beanfun.com/beanfun_block/bflogin/return.aspx", payload)); Debug.WriteLine(response); response = this.DownloadString("https://tw.beanfun.com/" + this.ResponseHeaders["Location"]); Debug.WriteLine(response); Debug.WriteLine(this.ResponseHeaders); this.webtoken = this.GetCookie("bfWebToken"); if (this.webtoken == "") { this.errmsg = "LoginNoWebtoken"; return; } GetAccounts(service_code, service_region, false); } catch (Exception e) { if (e is WebException) { this.errmsg = "網路連線錯誤,請檢查官方網站連線是否正常。" + e.Message; } else { this.errmsg = "LoginUnknown\n\n" + e.Message + "\n" + e.StackTrace; } return; } }
public void Login(string id, string pass, int loginMethod, QRCodeClass qrcodeClass = null, string service_code = "610074", string service_region = "T9") { this.webtoken = null; this.SessionKey = null; try { string akey = null; if (loginMethod == (int)LoginMethod.QRCode) { SessionKey = qrcodeClass.skey; } else { if (App.LoginRegion == "HK") { if (this.bfServ == null) { try { bfServ = new BFServiceX(); } catch { this.errmsg = "BFServiceXNotFound"; return; } } bfServ.Initialize2(); } SessionKey = GetSessionkey(); } switch (loginMethod) { case (int)LoginMethod.Regular: if (App.LoginRegion == "TW") { akey = RegularLogin(id, pass, SessionKey); } else { akey = RegularLogin_HK(id, pass, SessionKey); } break; case (int)LoginMethod.QRCode: akey = QRCodeLogin(qrcodeClass); break; default: this.errmsg = "LoginNoMethod"; return; } LoginCompleted(akey, service_code, service_region); } catch (Exception e) { if (e is WebException) { this.errmsg = "網路連線錯誤,請檢查官方網站連線是否正常。" + e.Message; } else { this.errmsg = "LoginUnknown\n\n" + e.Message + "\n" + e.StackTrace; } return; } }
public QRCodeClass GetQRCodeValue(string skey, bool oldAppQRCode) { string response = this.DownloadString("https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); Regex regex = new Regex("id=\"__VIEWSTATE\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoViewstate"; return(null); } string viewstate = regex.Match(response).Groups[1].Value; regex = new Regex("id=\"__EVENTVALIDATION\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoEventvalidation"; return(null); } string eventvalidation = regex.Match(response).Groups[1].Value; //Thread.Sleep(3000); string value; string strEncryptData; if (oldAppQRCode) { string qrdata = this.DownloadString("https://tw.newlogin.beanfun.com/generic_handlers/get_qrcodeData.ashx?skey=" + skey + "&startGame="); regex = new Regex("\"strEncryptData\": \"(.*)\"}"); if (!regex.IsMatch(qrdata)) { this.errmsg = "LoginNoQrcodedata"; return(null); } value = regex.Match(qrdata).Groups[1].Value; strEncryptData = Uri.UnescapeDataString(value); } else { regex = new Regex("\\$\\(\"#theQrCodeImg\"\\).attr\\(\"src\", \"../(.*)\" \\+ obj.strEncryptData\\);"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoHash"; return(null); } value = regex.Match(response).Groups[1].Value; strEncryptData = this.getQRCodeStrEncryptData(skey); if (strEncryptData == null || strEncryptData == "") { this.errmsg = "LoginIntResultError"; return(null); } } QRCodeClass res = new QRCodeClass(); res.skey = skey; res.viewstate = viewstate; res.eventvalidation = eventvalidation; res.value = strEncryptData; res.bitmapUrl = oldAppQRCode ? ("http://tw.newlogin.beanfun.com/qrhandler.ashx?u=" + value) : ("https://tw.newlogin.beanfun.com/" + value); res.oldAppQRCode = oldAppQRCode; return(res); }
public void Login(string id, string pass, int loginMethod, QRCodeClass qrcodeClass = null, string service_code = "610074", string service_region = "T9") { this.webtoken = null; try { string response = null; string skey = null; string akey = null; if (loginMethod == (int)LoginMethod.QRCode) { skey = qrcodeClass.skey; } else { skey = GetSessionkey(); } switch (loginMethod) { case (int)LoginMethod.Regular: akey = RegularLogin(id, pass, skey); break; case (int)LoginMethod.QRCode: akey = QRCodeLogin(qrcodeClass); break; default: this.errmsg = "LoginNoMethod"; return; } if (akey == null) { return; } //key允许重复的MAP NameValueCollection payload = new NameValueCollection(); payload.Add("SessionKey", skey); payload.Add("AuthKey", akey); Debug.WriteLine(skey); //2020037c850ec1ce3248 Debug.WriteLine(akey); //202003c0a458cbec574a response = Encoding.UTF8.GetString(this.UploadValues("https://tw.beanfun.com/beanfun_block/bflogin/return.aspx", payload)); Debug.WriteLine(response); response = this.DownloadString("https://tw.beanfun.com/" + this.ResponseHeaders["Location"]); Debug.WriteLine(response); Debug.WriteLine(this.ResponseHeaders); this.webtoken = this.GetCookie("bfWebToken"); if (this.webtoken == "") { this.errmsg = "LoginNoWebtoken"; return; } GetAccounts(service_code, service_region, false); } catch (Exception e) { if (e is WebException) { this.errmsg = "網路連線錯誤,請檢查官方網站連線是否正常。" + e.Message; } else { this.errmsg = "LoginUnknown\n\n" + e.Message + "\n" + e.StackTrace; } return; } }
public QRCodeClass GetQRCodeValue(string skey, bool oldAppQRCode) { string response = this.DownloadString("https://tw.newlogin.beanfun.com/login/qr_form.aspx?skey=" + skey); Regex regex = new Regex("id=\"__VIEWSTATE\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoViewstate"; return(null); } string viewstate = regex.Match(response).Groups[1].Value; regex = new Regex("id=\"__EVENTVALIDATION\" value=\"(.*)\" />"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoEventvalidation"; return(null); } string eventvalidation = regex.Match(response).Groups[1].Value; //Thread.Sleep(3000); string value; string strEncryptData; Stream stream; if (oldAppQRCode) { string qrdata = this.DownloadString($"https://tw.newlogin.beanfun.com/generic_handlers/get_qrcodeData.ashx?skey={skey}&startGame="); regex = new Regex("\"strEncryptData\": \"(.*)\"}"); if (!regex.IsMatch(qrdata)) { this.errmsg = "LoginNoQrcodedata"; return(null); } value = regex.Match(qrdata).Groups[1].Value; strEncryptData = Uri.UnescapeDataString(value); stream = this.OpenRead($"http://tw.newlogin.beanfun.com/qrhandler.ashx?u={value}"); } else { regex = new Regex("\\$\\(\"#theQrCodeImg\"\\).attr\\(\"src\", \"../(.*)\" \\+ obj.strEncryptData\\);"); if (!regex.IsMatch(response)) { this.errmsg = "LoginNoHash"; return(null); } value = regex.Match(response).Groups[1].Value; response = this.DownloadString($"https://tw.newlogin.beanfun.com/generic_handlers/get_qrcodeData.ashx?skey={skey}"); //regex = new Regex("\"strEncryptData\": \"(.*)\"}"); //if (!regex.IsMatch(response)) //{ this.errmsg = "LoginIntResultError"; return null; } //strEncryptData = regex.Match(response).Groups[1].Value; var definitions = new { intResult = "", strResult = "", strEncryptData = "", strEncryptBCDOData = "" }; var json = JsonConvert.DeserializeAnonymousType(response, definitions); strEncryptData = json.strEncryptData; stream = this.OpenRead($"https://tw.newlogin.beanfun.com/{value}{strEncryptData}"); } QRCodeClass res = new QRCodeClass(); res.skey = skey; res.viewstate = viewstate; res.eventvalidation = eventvalidation; res.value = strEncryptData; res.bitmap = new Bitmap(stream); res.oldAppQRCode = oldAppQRCode; return(res); }