Beispiel #1
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="txtObj"></param>
        public void ToUpLoadRes(TxtSetting txtObj)
        {
            DateTime dt = DateTime.Now;
            string   m, d = string.Empty;

            if (dt.Month < 10)
            {
                m = "0" + dt.Month.ToString();
            }
            else
            {
                m = dt.Month.ToString();
            }
            if (dt.Day < 10)
            {
                d = "0" + dt.Day.ToString();
            }
            else
            {
                d = dt.Day.ToString();
            }
            string        timeFolder            = dt.Year.ToString() + m + d;
            List <string> uploadPath            = new List <string>();
            string        title                 = txtObj.title;
            string        policy                = @"eyJleHBpcmF0aW9uIjoiMjAyMC0wMS0wMVQxMjowMDowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDAsMTA0ODU3NjAwMF1dfQ==";
            string        oSSAccessKeyId        = "LTAIFwHQY1lUbk1D";
            string        success_action_status = "200";
            string        signature             = @"oNFWy4ePoF8sxRRf5ylB/ihJ7+M=";

            string[] extArr         = { ".JPG", ".swf", ".zip", ".JPG" };
            string[] contentTypeArr = { "image/jpeg", "application/x-shockwave-flash", "application/x-zip-compressed", "image/jpeg" };
            string[] PathArr        = { txtObj.smallPicPath, txtObj.videoPath, txtObj.zipPath, txtObj.lognPicPath };
            string   ossUrl         = "http://antppt.oss-cn-beijing.aliyuncs.com/";
            string   outResult      = "";

            for (int i = 0; i < extArr.Length; i++)
            {
                HttpUpLoad hu = null;
                hu = new HttpUpLoad();
                string encryption = MD5(title);
                uploadPath.Add(encryption);
                hu.SetFieldValue("name", title + extArr[i]);
                hu.SetFieldValue("key", timeFolder + "/" + encryption + extArr[i]);
                hu.SetFieldValue("policy", policy);
                hu.SetFieldValue("OSSAccessKeyId", oSSAccessKeyId);
                hu.SetFieldValue("success_action_status", success_action_status);
                hu.SetFieldValue("signature", signature);
                hu.SetFieldValue("file", title + extArr[i], contentTypeArr[i], GetFileData(PathArr[i]));
                hu.Upload(ossUrl, cookie, out outResult);
            }

            HttpUpLoad hl = new HttpUpLoad();

            hl.SetFieldValue("menu_id", txtObj.menu_id);
            string[] sArr = txtObj.style_ids.Split(',');
            for (int i = 0; i < sArr.Length; i++)
            {
                if (!string.IsNullOrEmpty(sArr[i]))
                {
                    hl.SetFieldValue("style_ids[]", sArr[i]);
                }
            }

            hl.SetFieldValue("title", txtObj.title);
            hl.SetFieldValue("keyword", txtObj.keyword);
            hl.SetFieldValue("related_search", txtObj.related_search);
            hl.SetFieldValue("image", ossUrl + timeFolder + "/" + uploadPath[0] + extArr[0]);
            hl.SetFieldValue("video", ossUrl + timeFolder + "/" + uploadPath[1] + extArr[1]);
            hl.SetFieldValue("txt_file", ossUrl + timeFolder + "/" + uploadPath[2] + extArr[2]);
            hl.SetFieldValue("file_size", GetFileSize(txtObj.zipPath));
            hl.SetFieldValue("price", txtObj.price);
            hl.SetFieldValue("software", txtObj.soft);
            hl.SetFieldValue("page", txtObj.page);
            hl.SetFieldValue("proportion", txtObj.proportion);
            hl.SetFieldValue("score", txtObj.score);
            hl.SetFieldValue("free_status", txtObj.free_status);
            hl.SetFieldValue("is_tuijian", txtObj.is_tuijian);
            hl.SetFieldValue("notes", txtObj.notes);
            hl.SetFieldValue("complete", txtObj.complete);
            hl.SetFieldValue("sort", txtObj.sort);
            hl.SetFieldValue("image_list", "");
            hl.SetFieldValue("pictureurls[]", ossUrl + timeFolder + "/" + uploadPath[3] + extArr[3]);
            hl.SetFieldValue("describe", txtObj.describe);
            hl.SetFieldValue("source_describe", txtObj.source_describe);

            bool   res          = hl.PostData("http://www.antppt.com/fireman/content/add.html", cookie);
            string parentFolder = resPath + @"\" + txtObj.title;

            if (res)
            {
                if (Directory.Exists(parentFolder))
                {
                    DirectoryInfo pfDir = new DirectoryInfo(parentFolder);
                    foreach (FileSystemInfo fsi in pfDir.GetFileSystemInfos())
                    {
                        if (fsi is FileInfo)
                        {
                            if (!Directory.Exists(sucessPath + @"\" + txtObj.title))
                            {
                                Directory.CreateDirectory(sucessPath + @"\" + txtObj.title);
                            }
                            File.Move(fsi.FullName, sucessPath + @"\" + txtObj.title + @"\" + fsi.Name);
                        }
                    }
                    pfDir.Delete();
                }
            }
            else
            {
                if (Directory.Exists(parentFolder))
                {
                    DirectoryInfo pfDir = new DirectoryInfo(parentFolder);
                    foreach (FileSystemInfo fsi in pfDir.GetFileSystemInfos())
                    {
                        if (fsi is FileInfo)
                        {
                            if (!Directory.Exists(failPath + @"\" + txtObj.title))
                            {
                                Directory.CreateDirectory(failPath + @"\" + txtObj.title);
                            }
                            File.Move(fsi.FullName, failPath + @"\" + txtObj.title + @"\" + fsi.Name);
                        }
                    }
                    pfDir.Delete();
                }
            }
        }