Esempio n. 1
0
        private void GetDriveInfo()
        {
            if (!IsLogin)
            {
                DriveInfo = new DriveInfo();
            }
            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("app_id", SkyDrive_app_id.ToString());
            data.Add("checkexpire", "1");
            data.Add("checkfree", "1");
            data.Add("channel", "chunlei");
            data.Add("clienttype", "0");
            data.Add("web", "1");
            string    url  = "http://pan.baidu.com/api/quota?";
            UrolsPage page = new UrolsPage();

            foreach (KeyValuePair <string, string> item in data)
            {
                url += item.Key + "=" + item.Value + "&";
            }
            page.Url           = url;
            page.RequestCookie = requestCookie;
            page.GET();
            string html = page.Html;

            DriveInfo = JsonConvert.DeserializeObject <DriveInfo>(html);
        }
Esempio n. 2
0
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="filePath"></param>
        public FileOper UpLoadFile(string remotePath, string localPath)
        {
            try
            {
                //上传文件url
                string url = "http://c.pcs.baidu.com/rest/2.0/pcs/file?";
                Dictionary <string, string> data = new Dictionary <string, string>();
                data.Add("method", "upload");   //方法
                data.Add("path", remotePath);   //上传到网盘的路径
                data.Add("ondup", "overwrite"); //模式,覆盖
                data.Add("app_id", SkyDrive_app_id.ToString());
                StringBuilder sb = new StringBuilder();
                foreach (KeyValuePair <string, string> kv in data)
                {
                    sb.Append(HttpUtility.UrlEncode(kv.Key));
                    sb.Append("=");
                    sb.Append(HttpUtility.UrlEncode(kv.Value));
                    sb.Append("&");
                }
                string uploadUrl = url + sb.ToString();

                string    boundary = GetBoundary();
                UrolsPage page     = new UrolsPage();
                page.RequestCookie = requestCookie;
                FileInfo fileInfo = new FileInfo(localPath);
                if (fileInfo.Exists)
                {
                    using (FileStream fileStream = fileInfo.Open(FileMode.Open, FileAccess.Read))
                    {
                        string contenttype = GetContextType(fileInfo);

                        StringBuilder sbHeader = new StringBuilder();
                        sbHeader.Append("--");
                        sbHeader.Append(boundary);
                        sbHeader.Append("\r\n");
                        sbHeader.Append("Content-Disposition: form-data;filename=\"" + Path.GetFileName(localPath) + "\"");
                        sbHeader.Append("\r\n");
                        sbHeader.Append("Content-Type: ");
                        sbHeader.Append(contenttype);
                        sbHeader.Append("\r\n");
                        sbHeader.Append("\r\n");

                        string postHeader      = sbHeader.ToString();
                        byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);

                        string result = page.POST(uploadUrl, boundary, postHeaderBytes, fileStream);
                    }
                }
                else
                {
                    return(FileOper.载文件不存在);
                }
                return(FileOper.文件成功);
            }
            catch (Exception ex)
            {
                return(FileOper.文件失败);
            }
            return(FileOper.文件成功);
        }
Esempio n. 3
0
        /// <summary>
        /// 获取BAIDUID和Token值
        /// </summary>
        private void GetPara()
        {
            //获取BAIDUID
            UrolsPage page = new UrolsPage("http://www.baidu.com", Encoding.UTF8);

            requestCookie = page.RequestCookie;
            GetAllCookies(requestCookie);
            //获取Token,CodeString
            GetTokenAndCodeString();//获取 Token, CodeString
        }
Esempio n. 4
0
        /// <summary>
        /// 登陆
        /// </summary>
        private void Login()
        {
            GetPara();//获取登陆所需的参数
            string    loginUrl = "https://passport.baidu.com/v2/api/?login";
            UrolsPage page     = new UrolsPage();

            page.Url           = loginUrl;
            page.RequestCookie = requestCookie;
            Dictionary <string, string> Data = new Dictionary <string, string>();

            Data.Add("staticpage", "http://zhidao.baidu.com/static/html/v3Jump_bf2a8d6e.html");
            Data.Add("charset", "GBK");
            Data.Add("token", Token);
            Data.Add("tpl", "ik");
            Data.Add("apiver", "v3");
            Data.Add("tt", Utility.GetCurrentTimeStamp().ToString());
            Data.Add("codestring", "");
            Data.Add("isPhone", "false");
            Data.Add("safeflg", "0");
            Data.Add("u", "http://www.baidu.com/");
            Data.Add("username", userName);
            Data.Add("password", pwd);
            Data.Add("verifycode", "");
            Data.Add("mem_pass", "on");
            Data.Add("ppui_logintime", "22429");
            Data.Add("callback", "parent.bd__pcbs__7doo5q");

            StringBuilder sb = new StringBuilder();

            foreach (KeyValuePair <string, string> kv in Data)
            {
                sb.Append(HttpUtility.UrlEncode(kv.Key));
                sb.Append("=");
                sb.Append(HttpUtility.UrlEncode(kv.Value));
                sb.Append("&");
            }

            byte[] data   = Encoding.UTF8.GetBytes(sb.ToString().TrimEnd('&'));
            Stream stream = new MemoryStream(data);

            page.POST(loginUrl, "", null, stream);

            requestCookie = page.RequestCookie;
            List <Cookie> listCookie = GetAllCookies(requestCookie);

            if (!listCookie.Any(o => o.Name == "BDUSS"))
            {
                isLogin = false;
                return;
            }
            GetDriveInfo();
            //Bduss = Convert.ToString(page.ResponseCookie["BDUSS"].Value);
        }
Esempio n. 5
0
        /// <summary>
        /// 获取文件目录
        /// </summary>
        /// <returns></returns>
        public List <BaiDuFile> GetFileDir()
        {
            if (!IsLogin)
            {
                return(null);
            }
            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("app_id", SkyDrive_app_id.ToString());
            string url = "http://pan.baidu.com/api/list?";

            UrolsPage page = new UrolsPage();

            foreach (KeyValuePair <string, string> item in data)
            {
                url += item.Key + "=" + item.Value + "&";
            }
            page.Url           = url;
            page.RequestCookie = requestCookie;
            page.GET();

            string html   = page.Html;
            Regex  reg    = new Regex(@",.*,");
            Match  list_m = reg.Match(html);

            reg = new Regex(@"\{.*?\}");
            MatchCollection  mc       = reg.Matches(list_m.Value);
            List <BaiDuFile> fileList = new List <BaiDuFile>();
            BaiDuFile        fileItem;

            foreach (Match item in mc)
            {
                fileItem = new BaiDuFile();
                if (GetJsonValue("isdir", item.Value) == "1")
                {
                    fileItem.Type     = 2;
                    fileItem.IsFolder = true;
                }
                else
                {
                    fileItem.Type     = 1;
                    fileItem.IsFolder = false;
                }
                fileItem.Name = GetJsonValue("server_filename", item.Value);
                fileItem.Path = GetJsonValue("path", item.Value);
                fileList.Add(fileItem);
            }
            return(fileList);
        }
Esempio n. 6
0
        /// <summary>
        /// 获取Token,用于登陆用
        /// </summary>
        private void GetTokenAndCodeString()
        {
            string    url  = string.Format("https://passport.baidu.com/v2/api/?getapi&tpl=ik&apiver=v3&tt={0}&class=login", Utility.GetCurrentTimeStamp());
            UrolsPage page = new UrolsPage();

            page.Url           = url;
            page.RequestCookie = requestCookie;
            page.GET();
            requestCookie = page.RequestCookie;
            GetAllCookies(requestCookie);
            ResultData result = JsonConvert.DeserializeObject <ResultData>(page.Html);

            if (result.ErrInfo.no == "0")
            {
                Token = result.Data.Token;
                //CodeString = result.Data.CodeString;
            }
        }
Esempio n. 7
0
        public List <Entry> List(Entry folder)
        {
            if (!IsLogin)
            {
                return(null);
            }

            Dictionary <string, string> data = new Dictionary <string, string>();

            data.Add("app_id", SkyDrive_app_id.ToString());
            if (folder != null && !String.IsNullOrEmpty(folder.path))
            {
                data.Add("dir", folder.path);
            }
            string url = "http://pan.baidu.com/api/list?";

            UrolsPage page = new UrolsPage();

            foreach (KeyValuePair <string, string> item in data)
            {
                url += HttpUtility.UrlEncode(item.Key) + "=" + HttpUtility.UrlEncode(item.Value) + "&";
            }
            page.Url           = url;
            page.RequestCookie = requestCookie;
            page.GET();

            string html = page.Html;

            Rootobject root = JsonConvert.DeserializeObject <Rootobject>(html);

            if (root.errno != 0)
            {
                return(null);
            }

            return(new List <Entry>(root.list));

            //Regex reg = new Regex(@",.*,");
            //Match list_m = reg.Match(html);
            //reg = new Regex(@"\{.*?\}");
            //MatchCollection mc = reg.Matches(list_m.Value);
            //List<BaiDuFile> fileList = new List<BaiDuFile>();
            //BaiDuFile fileItem;
            //foreach (Match item in mc)
            //{
            //    fileItem = new BaiDuFile();
            //    if (GetJsonValue("isdir", item.Value) == "1")
            //    {
            //        fileItem.Type = 2;
            //        fileItem.IsFolder = true;
            //    }
            //    else
            //    {
            //        fileItem.Type = 1;
            //        fileItem.IsFolder = false;
            //    }
            //    fileItem.Name = GetJsonValue("server_filename", item.Value);
            //    fileItem.Path = GetJsonValue("path", item.Value);
            //    fileList.Add(fileItem);
            //}
            //return fileList;
        }