private void TestFunc() { var url = "https://pan.baidu.com/api/report/user"; var query_param = new Parameters(); query_param.Add("channel", "chunlei"); query_param.Add("web", 1); query_param.Add("app_id", BaiduPCS.APPID); query_param.Add("bdstoken", _bdstoken); query_param.Add("logid", BaiduPCS.GetLogid()); query_param.Add("clienttype", 0); var post_param = new Parameters(); post_param.Add("timestamp", (long)util.ToUnixTimestamp(DateTime.Now)); post_param.Add("action", "fm_self"); var ns = new NetStream(); ns.CookieKey = _cookie_identifier; var header = new Parameters(); header.Add("X-Requested-With", "XMLHttpRequest"); header.Add("Origin", "http://pan.baidu.com"); header.Add("Referer", BaiduPCS.BAIDU_NETDISK_URL); ns.HttpPost(url, post_param, headerParam: header, urlParam: query_param); var rep = ns.ReadResponseString(); ns.Close(); }
private bool submit_course_data(string course_id) { var url = get_session_url() + "/xf_xsqxxxk.aspx?xh=" + username.Text + "&gnmkdm=N121103"; debug_output("发送选课请求"); string course_time = "", course_name = ""; Invoke(new ThreadStart(delegate { course_time = courseTime.Text; course_name = courseName.Text; })); var post_param = new Parameters(); post_param.Add("__EVENTTARGET", ""); post_param.Add("__EVENTARGUMENT", ""); post_param.Add("__VIEWSTATE", __VIEWSTATE); post_param.Add("ddl_kcxz", ""); post_param.Add("ddl_ywyl", ""); post_param.Add("ddl_kcgs", ""); post_param.Add("ddl_xqbs", 2); post_param.Add("ddl_sksj", ""); post_param.Add("TextBox1", ""); post_param.Add("dpkcmcGrid:txtChoosePage", 1); post_param.Add("dpkcmcGrid:txtPageSize", 200); post_param.Add(course_id, "on"); post_param.Add("Button1", "++提交++"); var post_data = Encoding.UTF8.GetBytes(post_param.BuildQueryString()); //response_sr.Close(); var ns = new NetStream(); var header = new Parameters(); header.Add("Origin", get_origin_url()); header.Add("Referer", url); try { ns.HttpPost(url, post_data, NetStream.DEFAULT_CONTENT_TYPE_PARAM, header); if (ns.HTTP_Response.StatusCode != System.Net.HttpStatusCode.OK) { debug_output("HTTP错误:服务器返回" + (int)ns.HTTP_Response.StatusCode + "(" + ns.HTTP_Response.StatusDescription + ")"); return(false); //status check } var response_str = ns.ReadResponseString(Encoding.Default); return(check_course_selected(response_str.Replace("\r", "").Replace("\n", ""))); } catch (Exception) { return(false); } finally { ns.Close(); } }
//获取rsa的加密密钥 private static void _fetch_encrypt_key(out string hash, out string public_key) { var ns = new NetStream(); var param = new Parameters(); param.Add("appkey", APPKEY); param.Add("build", "513000"); param.Add("mobi_app", "android"); param.Add("platform", "android"); param.Add("ts", (long)util.ToUnixTimestamp(DateTime.Now)); param.Add("sign", CalculateSign(param)); ns.UserAgent = ANDROID_USER_AGENT; try { ns.HttpPost(_URL_AUTH_GET_KEY, param); ns.HttpPostClose(); var response = ns.ReadResponseString(); var json = JsonConvert.DeserializeObject(response) as JObject; int code = json.Value <int>("code"); if (code != 0) { hash = null; public_key = null; _last_error_code = code; _last_error_message = json.Value <string>("message"); } else { hash = json["data"].Value <string>("hash"); public_key = json["data"].Value <string>("key"); } } catch (Exception ex) { Tracer.GlobalTracer.TraceError(ex.ToString()); throw ex; } finally { ns.Close(); } }
public static bool Login(string username, string password) { string hash, public_key; _fetch_encrypt_key(out hash, out public_key); var ns = new NetStream(); var param = new Parameters(); param.Add("appkey", APPKEY); param.Add("build", "513000"); param.Add("mobi_app", "android"); param.Add("password", _encrypt_password(hash, public_key, password)); param.Add("platform", "android"); param.Add("ts", (long)util.ToUnixTimestamp(DateTime.Now)); param.Add("username", username); param.Add("sign", CalculateSign(param)); ns.UserAgent = ANDROID_USER_AGENT; try { ns.HttpPost(_URL_AUTH_LOGIN, param); ns.HttpPostClose(); var response = ns.ReadResponseString(); var json = JsonConvert.DeserializeObject(response) as JObject; int code = json.Value <int>("code"); if (code != 0) { _last_error_code = code; _last_error_message = json.Value <string>("message"); return(false); } else { _access_token = json["data"].Value <string>("access_token"); var ts = util.FromUnixTimestamp(json.Value <long>("ts")); _expire_time = ts.AddSeconds(json["data"].Value <long>("expires_in")); _mid = json["data"].Value <uint>("mid"); _refresh_token = json["data"].Value <string>("refresh_token"); //initialize other param try { _fetch_auth_info(); } catch { } while (!_sso_auth()) { Thread.Sleep(3000); } //NetStream.SaveCookie(); _save_token(); return(true); } } catch (Exception ex) { Tracer.GlobalTracer.TraceError(ex.ToString()); throw ex; } finally { ns.Close(); } }
private _login_result _v2_api__login(string token, string codestring, string gid, string username, string password, string rsakey, string rsa_publickey, string verify_code) { var ns = new NetStream(); ns.CookieKey = _cookie_identifier; try { Tracer.GlobalTracer.TraceInfo("Posting: login"); // 对明文密码进行RSA,并转换为base64的字符串 var rsa_param = Crypto.RSA_ImportPEMPublicKey(rsa_publickey); //导入public key var encrypted_password = Crypto.RSA_StringEncrypt(password, rsa_param); //加密 password = Convert.ToBase64String(encrypted_password); //to base64 // 登陆要POST的数据 var body = new Parameters(); body.Add("staticpage", "https://pan.baidu.com/res/static/thirdparty/pass_v3_jump.html"); body.Add("charset", "UTF-8"); body.Add("token", token); body.Add("tpl", "netdisk"); body.Add("subpro", "netdisk_web"); body.Add("apiver", "v3"); body.Add("tt", (long)(util.ToUnixTimestamp(DateTime.Now) * 1000)); body.Add("codestring", codestring == null ? "" : codestring); body.Add("safeflg", "0"); body.Add("u", "https://pan.baidu.com/disk/home"); body.Add("isPhone", ""); body.Add("detect", "1"); body.Add("gid", gid); body.Add("quick_user", "0"); body.Add("logintype", "basicLogin"); body.Add("logLoginType", "pc_loginBasic"); body.Add("idc", ""); body.Add("loginmerge", "true"); body.Add("foreignusername", ""); body.Add("username", username); body.Add("password", password); if (verify_code != null) { body.Add("verifycode", verify_code); } body.Add("mem_pass", "on"); body.Add("rsakey", rsakey); body.Add("crypttype", "12"); body.Add("ppui_logintime", new Random().Next(5000, 15000)); // random range [5000, 15000) body.Add("countrycode", ""); body.Add("fp_uid", ""); body.Add("fp_info", ""); body.Add("login_version", "v4"); body.Add("dv", "i_do_not_know_this_parameter"); body.Add("traceid", ""); body.Add("callback", "parent.bd__pcbs__fuckbd"); var header = new Parameters(); header.Add("Origin", "https://pan.baidu.com"); header.Add("Referer", "https://pan.baidu.com/"); ns.HttpPost("https://passport.baidu.com/v2/api/?login", body, headerParam: header); var response = ns.ReadResponseString(); var ret = new _login_result(); // parsing login result var match = Regex.Match(response, "href\\s\\+=\\s\"([^\"]+)\""); if (!match.Success) { throw new LoginFailedException("could not get login status code from HTML response"); } var response_param = match.Result("$1"); match = Regex.Match(response_param, @"&?([^=]+)=([^&]*)"); var response_key_values = new Dictionary <string, string>(); while (match.Success) { response_key_values.Add(match.Result("$1"), match.Result("$2")); match = match.NextMatch(); } if (!response_key_values.TryGetValue("err_no", out ret.errno)) { throw new LoginFailedException("could not get errno from HTML response"); } if (!response_key_values.TryGetValue("codeString", out ret.codestring)) { throw new LoginFailedException("could not get codestring from HTML response"); } if (!response_key_values.TryGetValue("vcodetype", out ret.vcodetype)) { throw new LoginFailedException("could not get vcodetype from HTML response"); } _captcha_generated = false; return(ret); } catch (LoginFailedException ex) { throw ex; } catch (Exception ex) { throw new LoginFailedException("post login failed", ex); } finally { ns.Close(); } }