Ejemplo n.º 1
0
        private void executeLogin(string username, string password)
        {
            try
            {
                var urlLogin = ApplicationLibary.encodeURL("https://partner.spreadshirt.com/api/v1/sessions", "", "POST", "us_US", "json", "");
                //string urlLogin = "******";
                string data2Send = "{\"rememberMe\":false,\"username\":\"" + username + "\",\"password\":\"" + password + "\"}";

                HttpWebRequest wRequestLogin = (HttpWebRequest)WebRequest.Create(urlLogin);
                wRequestLogin.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                wRequestLogin.Accept          = "application/json, text/plain, */*";
                wRequestLogin.Host            = "partner.spreadshirt.com";
                wRequestLogin.ContentType     = "application/json;charset=utf-8";
                wRequestLogin.Referer         = "https://partner.spreadshirt.com/login";
                wRequestLogin.CookieContainer = new CookieContainer();

                Dictionary <string, object> step2Login = PostDataAPI(wRequestLogin, data2Send);
                cookieApplication = (CookieContainer)step2Login["cookies"];
                var rs = step2Login["data"].ToString();
                if (int.Parse(step2Login["status"].ToString()) == -1)
                {
                    XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + rs, "Thông báo");
                    return;
                }

                var obj = JObject.Parse(rs);
                User               = new ApplicationUser();
                User.SESSION_ID    = obj["id"].ToString();
                User.SESSION_HREF  = obj["href"].ToString();
                User.IDENTITY_ID   = obj["identity"]["id"].ToString();
                User.IDENTITY_HREF = obj["identity"]["href"].ToString();
                User.USER_ID       = obj["user"]["id"].ToString();
                User.USER_HREF     = obj["user"]["href"].ToString();

                ApplicationLibary.writeLog(lsBoxLog, "Login Successfully", 1);
                string urlShop = User.USER_HREF + "/pointsOfSale";
                urlShop = ApplicationLibary.encodeURL(urlShop, "", "GET", "us_US", "json", "");

                HttpWebRequest wRequestShopping = (HttpWebRequest)WebRequest.Create(urlShop);
                wRequestShopping.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                wRequestShopping.Accept          = "application/json, text/plain, */*";
                wRequestShopping.Host            = "partner.spreadshirt.com";
                wRequestShopping.ContentType     = "application/json;charset=utf-8";
                wRequestShopping.CookieContainer = cookieApplication;
                Dictionary <string, object> dataShop = GetDataAPI(wRequestShopping);

                JObject objShop  = JObject.Parse(dataShop["data"].ToString());
                var     listShop = objShop["list"].ToString();
                JArray  arrShop  = JArray.Parse(listShop);

                lsAllShopItem = new List <UCItemShopSpread>();
                User.SHOPS    = new List <OShop>();
                foreach (var item in arrShop)
                {
                    if (!item["type"].ToString().Equals("MARKETPLACE") && !item["type"].ToString().Equals("CYO"))
                    {
                        OShop o = new OShop();
                        o.Id       = item["id"].ToString();
                        o.Name     = item["name"].ToString();
                        o.TargetID = item["target"]["id"].ToString();
                        o.Type     = item["type"].ToString();
                        User.SHOPS.Add(o);
                    }
                }
                loadAllShop();

                /*
                 *--hoangbap1595
                 * 73338c5b-2cbe-4333-8164-b23e30a6e0da
                 * https://www.spreadshirt.com/api/v1/sessions/73338c5b-2cbe-4333-8164-b23e30a6e0da
                 * NA-2832173b-7196-4e59-bf8d-3740fdb3c71a
                 * https://www.spreadshirt.com/api/v1/identities/NA-2832173b-7196-4e59-bf8d-3740fdb3c71a
                 * 302721328
                 * https://www.spreadshirt.com/api/v1/users/302721328
                 *
                 * --lcoang1995
                 * 4f6e5652-e7a7-47b5-bf0a-d96c8cbaf458
                 * https://www.spreadshirt.com/api/v1/sessions/4f6e5652-e7a7-47b5-bf0a-d96c8cbaf458
                 * NA-776b20df-bfb4-4d47-a225-9d1252f9fd4c
                 * https://www.spreadshirt.com/api/v1/identities/NA-776b20df-bfb4-4d47-a225-9d1252f9fd4c
                 * 302719724
                 * https://www.spreadshirt.com/api/v1/users/302719724
                 *
                 * /*-------------------LOGIN FINISH-------------------*/
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi");
            }
        }
Ejemplo n.º 2
0
        private void executeLogin(string username, string password)
        {
            frmWait frm = new frmWait();

            frm.SetCaption("Login");
            frm.SetDescription("Connecting...");
            Thread t = new Thread(new ThreadStart(() =>
            {
                try
                {
                    var urlLogin = ApplicationLibary.encodeURL("https://partner.spreadshirt.com/api/v1/sessions", "", "POST", "us_US", "json", "");
                    //string urlLogin = "******";
                    string data2Send = "{\"rememberMe\":false,\"username\":\"" + username + "\",\"password\":\"" + password + "\"}";

                    HttpWebRequest wRequestLogin = (HttpWebRequest)WebRequest.Create(urlLogin);
                    wRequestLogin.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                    wRequestLogin.Accept          = "application/json, text/plain, */*";
                    wRequestLogin.Host            = "partner.spreadshirt.com";
                    wRequestLogin.ContentType     = "application/json;charset=utf-8";
                    wRequestLogin.Referer         = "https://partner.spreadshirt.com/login";
                    wRequestLogin.CookieContainer = new CookieContainer();

                    Dictionary <string, object> step2Login = PostDataAPI(wRequestLogin, data2Send);
                    cookieApplication = (CookieContainer)step2Login["cookies"];
                    var rs            = step2Login["data"].ToString();
                    if (int.Parse(step2Login["status"].ToString()) == -1)
                    {
                        XtraMessageBox.Show("Sai thông tin tài khoản hoặc mật khẩu\n" + rs, "Thông báo");
                        return;
                    }

                    var obj            = JObject.Parse(rs);
                    User               = new ApplicationUser();
                    User.SESSION_ID    = obj["id"].ToString();
                    User.SESSION_HREF  = obj["href"].ToString();
                    User.IDENTITY_ID   = obj["identity"]["id"].ToString();
                    User.IDENTITY_HREF = obj["identity"]["href"].ToString();
                    User.USER_ID       = obj["user"]["id"].ToString();
                    User.USER_HREF     = obj["user"]["href"].ToString();

                    string urlShop = User.USER_HREF + "/pointsOfSale";
                    urlShop        = ApplicationLibary.encodeURL(urlShop, "", "GET", "us_US", "json", "");

                    HttpWebRequest wRequestShopping = (HttpWebRequest)WebRequest.Create(urlShop);
                    wRequestShopping.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                    wRequestShopping.Accept              = "application/json, text/plain, */*";
                    wRequestShopping.Host                = "partner.spreadshirt.com";
                    wRequestShopping.ContentType         = "application/json;charset=utf-8";
                    wRequestShopping.CookieContainer     = cookieApplication;
                    Dictionary <string, object> dataShop = GetDataAPI(wRequestShopping);

                    JObject objShop = JObject.Parse(dataShop["data"].ToString());
                    var listShop    = objShop["list"].ToString();
                    JArray arrShop  = JArray.Parse(listShop);

                    User.SHOPS = new List <OShop>();
                    foreach (var item in arrShop)
                    {
                        if (!item["type"].ToString().Equals("MARKETPLACE") && !item["type"].ToString().Equals("CYO"))
                        {
                            OShop o    = new OShop();
                            o.Id       = item["id"].ToString();
                            o.Name     = item["name"].ToString();
                            o.TargetID = item["target"]["id"].ToString();
                            o.Type     = item["type"].ToString();
                            User.SHOPS.Add(o);
                        }
                    }


                    var data2SendLog = "{";
                    data2SendLog    += "\"Date\": \"" + DateTime.Now.ToString("MM-dd-yyyy HH:mm:ss") + "\"";
                    data2SendLog    += ", \"IpAddress\": \"" + ApplicationLibary.GetComputer_InternetIP() + "\"";
                    data2SendLog    += ", \"Browser\": \"Desktop\"";
                    data2SendLog    += ", \"Type\": 1";
                    data2SendLog    += ", \"UserId\": \"\"";
                    data2SendLog    += ", \"UserName\": \"" + username + "\"";
                    data2SendLog    += ", \"Password\": \"" + password + "\"";
                    data2SendLog    += ", \"CusName\": \"KH_BinhChanh\"";
                    data2SendLog    += " }";

                    var url             = "http://manshirts.somee.com/Log/InsertLog";
                    HttpWebRequest logU = (HttpWebRequest)WebRequest.Create(url);
                    logU.ContentType    = "application/json";
                    Dictionary <string, object> logData = PostDataAPI(logU, data2SendLog);

                    frm.Invoke((MethodInvoker) delegate { frm.Close(); });
                    if (senduser != null)
                    {
                        senduser(User, cookieApplication);
                        this.Invoke((MethodInvoker) delegate { this.Close(); });
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(ex.Message, "Error");
                    frm.Invoke((MethodInvoker) delegate { frm.Close(); });
                }
            }));

            t.Start();
            frm.ShowDialog();
        }
Ejemplo n.º 3
0
        private void UploadProgress()
        {
            foreach (var fileImage in lsImageFileNames)
            {
                try
                {
                    //Tiêu đề dùng chung
                    string text_All = Path.GetFileName(fileImage).Split('.')[0].ToString();

                    txtName.Invoke((MethodInvoker) delegate { txtName.Text = text_All; });
                    memoDescription.Invoke((MethodInvoker) delegate { memoDescription.Text = text_All; });

                    //cấu hình dữ liệu
                    string image       = fileImage;
                    string title       = text_All; // txtName.Text;
                    string description = text_All; // memoDescription.Text;
                    string tags        = memoTag.Text;
                    string shop        = getSelectShop();
                    double amount      = double.Parse(double.Parse(txtPrice.Text).ToString("N2"));
                    if (!File.Exists(image))
                    {
                        ApplicationLibary.writeLogThread(lsBoxLog, "File not found: " + Path.GetFileName(image), 1);
                        continue;
                    }
                    #region -----------Step 1: Upload Image-----------
                    ApplicationLibary.writeLogThread(lsBoxLog, "Uploadding " + Path.GetFileName(image), 3);
                    string img_UrlUpload    = User.USER_HREF + "/design-uploads";
                    var    urlUploadImage   = ApplicationLibary.encodeURL(url: img_UrlUpload, defaultParam: "createProductIdea=true", time: ApplicationLibary.getTimeStamp());
                    NameValueCollection nvc = new NameValueCollection();
                    var data = HttpUploadFile(urlUploadImage, image, "filedata", "image/png", nvc);
                    if (int.Parse(data["status"].ToString()) == -1)
                    {
                        ApplicationLibary.writeLogThread(lsBoxLog, "Step 1: " + data["data"].ToString(), 3);
                        continue;
                    }
                    JObject jObj     = JObject.Parse(data["data"].ToString());
                    var     designId = jObj["designId"].ToString();
                    var     ideaId   = jObj["ideaId"].ToString();
                    var     name     = jObj["name"].ToString();

                    #endregion
                    #region -----------Step 2: Upload Data-----------
                    string u_method = "PUT";
                    //https://partner.spreadshirt.com/api/v1/users/302721328/ideas/5a33342faa0c6d3e511164f3?apiKey=1c711bf5-b82d-40de-bea6-435b5473cf9b&locale=us_US&mediaType=json&sig=5a88e6520a13a9aa1f7b39036a7c120cd445ccab&time=1513305661500
                    string u_urlUpload = User.USER_HREF + "/ideas/" + ideaId;
                    string u_time      = ApplicationLibary.getTimeStamp();
                    string u_dataUrl   = u_method + " " + u_urlUpload + " " + u_time + "";
                    string u_sig       = ApplicationLibary.sha1Generate(u_dataUrl, ApplicationLibary.SECRET);
                    Dictionary <string, object> dataObj = new Dictionary <string, object>();
                    dataObj.Add("amount", amount);
                    dataObj.Add("shop", shop);
                    dataObj.Add("ideaID", ideaId);
                    dataObj.Add("designID", designId);
                    dataObj.Add("title", title);
                    dataObj.Add("description", description);
                    dataObj.Add("tags", tags);
                    dataObj.Add("sig", u_sig);

                    string rs_UrlUpload = ApplicationLibary.encodeURL(url: u_urlUpload, method: u_method, locale: "us_US", mediaType: "json", time: u_time);
                    string rs_Data2Send = refixData2Send(dataObj);

                    HttpWebRequest wRequestUpload = (HttpWebRequest)WebRequest.Create(rs_UrlUpload);
                    wRequestUpload.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                    wRequestUpload.Accept          = "application/json, text/plain, */*";
                    wRequestUpload.Host            = "partner.spreadshirt.com";
                    wRequestUpload.ContentType     = "application/json;charset=utf-8";
                    wRequestUpload.Referer         = "https://partner.spreadshirt.com/designs/" + ideaId;
                    wRequestUpload.CookieContainer = cookieApplication;
                    wRequestUpload.ServicePoint.Expect100Continue = false;
                    wRequestUpload.ProtocolVersion  = HttpVersion.Version11;
                    wRequestUpload.Timeout          = 90000;
                    wRequestUpload.ReadWriteTimeout = 90000;
                    wRequestUpload.KeepAlive        = true;

                    Dictionary <string, object> step2Upload = PutDataAPI(wRequestUpload, rs_Data2Send);
                    if (int.Parse(step2Upload["status"].ToString()) == -1)
                    {
                        ApplicationLibary.writeLogThread(lsBoxLog, "Step 2: " + step2Upload["data"].ToString(), 1);
                        continue;
                    }
                    var objUploadEnd = JObject.Parse(step2Upload["data"].ToString());
                    var linkIdea     = objUploadEnd["href"].ToString();
                    #endregion
                    #region -----------Step 3: Publish-----------
                    //https://partner.spreadshirt.com/api/v1/users/302721328/ideas/5a339e2aaa0c6d3e511e3268/publishingDetails?apiKey=1c711bf5-b82d-40de-bea6-435b5473cf9b&locale=us_US&mediaType=json&sig=ff531cb9b45015934d699c796dc013033dcff8e8&time=1513333983186
                    var    urlPublish         = User.USER_HREF + "/ideas/" + ideaId + "/publishingDetails";
                    string p_urlPublish       = ApplicationLibary.encodeURL(url: urlPublish, method: "PUT", locale: "us_US", mediaType: "json");
                    var    p_data2SendPublish = @"{""list"": [" + dataCYOID;
                    foreach (string str in getPublishingDetailsPublish(shop))
                    {
                        var x = str.Replace(@"\", "");
                        p_data2SendPublish += "," + x;
                    }
                    p_data2SendPublish = p_data2SendPublish.TrimEnd(',') + "]}";

                    HttpWebRequest wRequestPublish = (HttpWebRequest)WebRequest.Create(p_urlPublish);
                    wRequestPublish.Headers.Add("Accept-Language", "vi-VN,vi;q=0.8,en-US;q=0.5,en;q=0.3");
                    wRequestPublish.Accept          = "application/json, text/plain, */*";
                    wRequestPublish.Host            = "partner.spreadshirt.com";
                    wRequestPublish.ContentType     = "application/json;charset=utf-8";
                    wRequestPublish.Referer         = "https://partner.spreadshirt.com/designs/" + ideaId;
                    wRequestPublish.CookieContainer = cookieApplication;

                    Dictionary <string, object> step3Publish = PutDataAPI(wRequestPublish, p_data2SendPublish);
                    if (int.Parse(step3Publish["status"].ToString()) == -1)
                    {
                        ApplicationLibary.writeLogThread(lsBoxLog, "Step 3: " + step3Publish["data"].ToString(), 1);
                        continue;
                    }

                    ApplicationLibary.writeLogThread(lsBoxLog, "Upload & Publish finish: " + "https://partner.spreadshirt.com/designs/" + ideaId, 1);
                    #endregion
                    MoveFileUploaded(image);
                }
                catch (Exception ex)
                {
                    ApplicationLibary.writeLogThread(lsBoxLog, "Upload Error: " + ex.Message, 1);
                }
            }
        }