//二维码登录 public void Qrcode_Login(BiliCookie biliCookie, login login) { Login_Success(biliCookie, login); }
//(网页接口)密码登录 public void Password_login_Web(string username, string password, string hash, Verification_Key verification_key, login login) { Coding coding = new Coding(); var rsa = new RSACryptoServiceProvider(); var public_key = @"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDjb4V7EidX/ym28t2ybo0U6t0n 6p4ej8VjqKHg100va6jkNbNTrLQqMCQCAYtXMXXp2Fwkk6WR+12N9zknLjf+C9sx /+l48mjUU8RqahiFD1XT/u2e0m2EN029OhCgkHx3Fc/KlFSIbak93EH/XlYis0w+ Xl69GV6klzgxW6d2xQIDAQAB"; rsa.FromX509PublicKey(Convert.FromBase64String(public_key)); var bytes = Convert.ToBase64String(rsa.Encrypt(Encoding.UTF8.GetBytes("mangohappy"), false)); var client = new RestClient("http://passport.bilibili.com/web/login/v2"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); request.AddParameter("captchaType", "6"); request.AddParameter("username", username); request.AddParameter("password", Convert.ToBase64String(rsa.Encrypt(Encoding.UTF8.GetBytes(hash + password), false))); request.AddParameter("keep", "true"); request.AddParameter("key", verification_key.key); request.AddParameter("goUrl", coding.UrlEncode("https://www.bilibili.com/")); request.AddParameter("challenge", verification_key.challenge); request.AddParameter("validate", verification_key.validate); request.AddParameter("seccode", verification_key.seccode); IRestResponse response = client.Execute(request); JObject recommend = (JObject)JsonConvert.DeserializeObject(response.Content); string code = recommend["code"].ToString(); if (string.Equals(code, "-2111")) { MessageBox.Show("由于您已开启二次验证,二次验证API出了点问题,请改用扫码或者验证码登录,抱歉了"); /*Verification_Key Double_verification_key = Get_Verification_Key(7); * Double_verification_key.Sms_type = 18; * Double_verification_key.tmp_code = (recommend["data"].ToString()).Substring((recommend["data"].ToString()).IndexOf("tmp_token=") + 10, 32);*/ login.Password_Login.Visibility = Visibility.Hidden; login.Sms_Code_Login.Visibility = Visibility.Visible; /*login.phone_textbox.Text = Double_verification_key.tmp_code; * login.phone_textbox.IsReadOnly = true; * login.Sms_code_Send_buttons.Content = "请验证"; * login.Sms_code_Send_buttons.IsEnabled = false; * login.Sms_Login_button.Content = "请验证"; * login.Sms_Login_button.IsEnabled = false; * login.sendKey_To_Geetest_page(Double_verification_key);*/ } else if (string.Equals(code, "0")) { BiliCookie biliCookie = Get_Cookie(response.Content); Login_Success(biliCookie, login); } else { MessageBox.Show(response.Content); } client = null; request = null; response = null; recommend = null; code = null; }
//发送手机验证码 public void Send_Sms(Verification_Key verification_key, login login) { if (verification_key.Sms_type == 18)//二次验证 { var client = new RestClient("https://api.bilibili.com/x/safecenter/sms/send"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddParameter("application/x-www-form-urlencoded", "type=18&captchaType=7" + "&captcha_key=" + verification_key.key + "&challenge=" + verification_key.challenge + "&validate=" + verification_key.validate + "&seccode=" + verification_key.seccode + "&tmp_code=" + verification_key.tmp_code , ParameterType.RequestBody); IRestResponse response = client.Execute(request); MessageBox.Show(response.Content); JObject recommend = (JObject)JsonConvert.DeserializeObject(response.Content); string code = recommend["code"].ToString(); if (!string.Equals(code, "0")) { login.Sms_code_Send_buttons.Content = "失败"; } client = null; request = null; response = null; recommend = null; code = null; } else if (verification_key.Sms_type == 21)//验证码登录 { var client = new RestClient("http://passport.bilibili.com/web/sms/general/v2/send"); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddParameter("application/x-www-form-urlencoded", "tel=" + verification_key.phone + "&cid=1&type=21&captchaType=6" + "&key=" + verification_key.key + "&challenge=" + verification_key.challenge + "&validate=" + verification_key.validate + "&seccode=" + verification_key.seccode, ParameterType.RequestBody); IRestResponse response = client.Execute(request); JObject recommend = (JObject)JsonConvert.DeserializeObject(response.Content); string code = recommend["code"].ToString(); if (!string.Equals(code, "0")) { MessageBox.Show(response.Content); login.Sms_code_Send_buttons.Content = "发送"; } else if (string.Equals(code, "0")) { login.Sms_code_Send_buttons.Content = "重发"; login.Sms_Login_button.IsEnabled = true; } client = null; request = null; response = null; recommend = null; code = null; } }