/// <summary> /// 获取文件下载地址 /// </summary> /// <param name="FileID"></param> /// <param name="FolderID"></param> /// <returns></returns> public static string GetFileDownUrl(int FileID, int FolderID) { if (!Directory.Exists(PublicConfig.CacheDir)) { Directory.CreateDirectory(PublicConfig.CacheDir); } string CachePath = $"{PublicConfig.CacheDir}\\floder{NewC.Get_MD5(FileID.ToString(), false)}"; if (File.Exists(CachePath)) { return(File.ReadAllText(CachePath)); } for (int page = 1; page <= 11; page++) { string Data = NewC.GET_HTTP(PublicConfig.File.GetUserDownUrl.Replace("{skip}", ((page - 1) * 100).ToString()).Replace("{folderid}", FolderID.ToString()), PublicConfig.Cookie, false); if (Data == "") { return(FileID.ToString()); } Dictionary <string, object> Dic = JsonToDictionary.JSONToObject <Dictionary <string, object> >(Data); ArrayList AL = (ArrayList)Dic["aaData"]; foreach (ArrayList item in AL) { if (item[1].ToString().Contains(FileID.ToString())) { string Url = NewC.GetString(item[1].ToString(), "href=\"", "\">", false, 0); File.WriteAllText(CachePath, Url); return(Url); } } } return(FileID.ToString()); }
public Login(string Username, string Password) { PublicConfig.Username = Username; if (!Directory.Exists(PublicConfig.CacheDir)) { Directory.CreateDirectory(PublicConfig.CacheDir); } UserCachePath = $"{PublicConfig.CacheDir}\\{NewC.Get_MD5(Username, false)}"; if (File.Exists(UserCachePath)) { string Cookie = File.ReadAllText(UserCachePath, Encoding.UTF8); if (IsLogin(Cookie)) { //已经登陆过了 PublicConfig.Cookie = Cookie; Console.WriteLine("登录还未失效:" + Username); return; } } if (PublicConfig.DaMaTu.Username == string.Empty || PublicConfig.DaMaTu.Password == string.Empty) { throw new Exception("验证码识别平台账号未初始化。\r\n请先设置验证码识别平台的账号密码:PublicConfig.DaMaTu.Username与PublicConfig.DaMaTu.Password\r\n验证码识别平台:dama2.com"); } string[] VerCodeAndCookie = GetVerCode(); LoginCtFile(Username, Password, VerCodeAndCookie[0], VerCodeAndCookie[1]); }
private string[] GetVerCode() { string Cookie; byte[] imageData = NewC.Get_Vercode(PublicConfig.Login.VerCodeUrl, PublicConfig.Login.VerCodeUrl, false, new CookieContainer(), out Cookie); return(new string[] { DaMa.Dama.Get(imageData), Cookie }); }
/// <summary> /// 创建文件夹 /// </summary> /// <param name="Name">文件夹名称</param> /// <param name="Desc">文件夹描述</param> /// <param name="PrintID">父文件夹ID(根目录为0)</param> /// <param name="OpenDC">是否开启直连(需要开通VIP)</param> /// <returns></returns> public static string Create(string Name, string Desc, int PrintID = 0, bool OpenDC = false) { string Data = NewC.POST_HTTP(PublicConfig.Folder.CreateUrl, PublicConfig.Folder.CreatePostData.Replace("{name}", Name).Replace("{desc}", Desc).Replace("{printid}", PrintID.ToString()).Replace("{opendc}", OpenDC ? "on" : "off"), PublicConfig.Cookie, false); if (Data.ToLower() != "ok" && !Data.Contains("存在")) { throw new Exception($@"创建文件夹时发生错误:\r\n{Data}\r\n文件夹名称:{Name}\r\n描述:{Desc}\r\n父目录:{PrintID}\r\nCookie:{PublicConfig.Cookie}"); } return(Data); }
private bool IsLogin(string Cookie) { string Data = NewC.GET_HTTP(PublicConfig.Login.CheckUrl, Cookie, false); if (Data.Contains("注册会员后再继续使用本功能") || Data.Contains("请先 登录")) { return(false); } else { return(true); } }
void Thread_Start() { try { string UpUrl = ""; int FolderID = Folder.GetFolderID(_FolderName); string Html = NewC.GET_HTTP(PublicConfig.File.GetUpUrl.Replace("{folderid}", FolderID.ToString()), PublicConfig.Cookie, false); UpUrl = NewC.GetString(Html, "initUpload('", "',", false, 0); FileInfo Info = new FileInfo(_FilePath); string Name = (_SaveName == "" ? Info.Name : _SaveName); Name = FilterName(Name); string Data = _UpFile(UpUrl, _FilePath, Name, Info.Length); DownUrl = GetFileDownUrl(Convert.ToInt32(Data), FolderID); } catch { } IsComplete = true; }
/// <summary> /// 通过文件名在指定文件夹中寻找文件 /// </summary> /// <param name="Name"></param> /// <returns></returns> public static string SearchFile(string FolderName, string Key, long FileLength, out string FileName) { FileName = ""; double FileSizeMB = Convert.ToDouble(((double)FileLength / 1024 / 1024).ToString("0.00")); int ID = GetFolderID(FolderName); if (ID > 0) { string Data = NewC.GET_HTTP(PublicConfig.Folder.SearchUrl.Replace("{key}", Key).Replace("{folderid}", ID.ToString()), PublicConfig.Cookie, false); if (Data == "") { return(""); } Dictionary <string, object> Dic = JsonToDictionary.JSONToObject <Dictionary <string, object> >(Data); ArrayList AL = (ArrayList)Dic["aaData"]; foreach (ArrayList item in AL) { double Size = FileSizeMB; try { Size = Convert.ToDouble(item[2].ToString().Replace("MB", "").Trim()); } catch { } if (FileSizeMB > Size) { if (FileSizeMB - Size > 1) { continue; } } else if (Size - FileSizeMB > 1) { continue; } string Url = NewC.GetString(item[1].ToString(), "href=\"", "\">", false, 0); MatchCollection Match = Regex.Matches(item[1].ToString(), @"<a.*?>(.*?)</a>", RegexOptions.IgnoreCase); if (Match.Count > 0) { FileName = Match[0].Groups[1].ToString(); } return(Url); } } return(""); }
/// <summary> /// 通过文件名获取文件ID /// </summary> /// <param name="Name"></param> /// <returns></returns> public static int GetFolderID(string Name) { if (!Directory.Exists(PublicConfig.CacheDir)) { Directory.CreateDirectory(PublicConfig.CacheDir); } string CachePath = $"{PublicConfig.CacheDir}\\floder{NewC.Get_MD5(Name + PublicConfig.Username, false)}"; if (File.Exists(CachePath)) { return(Convert.ToInt32(File.ReadAllText(CachePath))); } for (int page = 1; page <= 11; page++) { string Data = NewC.GET_HTTP(PublicConfig.Folder.ListUrl.Replace("{skip}", ((page - 1) * 100).ToString()), PublicConfig.Cookie, false); if (Data == "") { return(0); } Dictionary <string, object> Dic = JsonToDictionary.JSONToObject <Dictionary <string, object> >(Data); ArrayList AL = (ArrayList)Dic["aaData"]; foreach (ArrayList item in AL) { if (item[1].ToString().Contains(Name)) { string ID = NewC.GetString(item[1].ToString(), "folder_id-", "\"", false, 0); int OutID = 0; if (!int.TryParse(ID, out OutID)) { ID = NewC.GetString(item[0].ToString(), "value=\"", "\" ", false, 0); } int.TryParse(ID, out OutID); if (OutID > 0) { File.WriteAllText(CachePath, OutID.ToString()); } return(OutID); } } } return(0); }
private void LoginCtFile(string Username, string Password, string VerCode, string Cookie) { Console.WriteLine($"开始登录网盘:{Username}, Code:{VerCode}"); int NowTime = NewC.ConvertDateTimeInt(DateTime.Now); string Data; CookieContainer RetCookie = NewC.POST_SITE_DATA_Cookie(PublicConfig.Login.Url, PublicConfig.Login.Url, "", "", false, false, NewC.CookieToCookieContainer(Cookie, PublicConfig.Host), PublicConfig.Login.PostData.Replace("{username}", Username).Replace("{password}", Password).Replace("{vercode}", VerCode), false, out Data); if (Data == "ok") { PublicConfig.Cookie = RetCookie.GetCookieHeader(new Uri(PublicConfig.Host)); File.WriteAllText(UserCachePath, PublicConfig.Cookie, Encoding.UTF8); } else { throw new Exception($"登陆失败,{Data}"); } }