Exemplo n.º 1
0
        private void btnGetCart_Click(object sender, EventArgs e)
        {
            //string cartJson =  JDHelper.GetInstance().GetCartJson(_jdLoginer.cookies);

            HttpItem     item   = new HttpItem();
            SFHttpHelper helper = new SFHttpHelper();
            HttpResult   result = new HttpResult();

            item.URL = "https://cart.jd.com/cart.action";

            item.UserAgent         = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36";
            item.Method            = "get";
            item.Allowautoredirect = true;
            item.Header.Add("Accept-Encoding", "gzip, deflate, sdch, br");
            item.Header.Add("Accept-Language", "zh-CN,zh;q=0.8");
            item.Referer  = "https://www.jd.com/";
            item.Accept   = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            item.Encoding = Encoding.UTF8;
            item.Cookie   = _jdLoginer.cookies;
            result        = helper.GetHtml(item);
            //_jdLoginer.cookies = result.Cookie;
            List <Data.Wares> waresUrls = JDHelper.GetInstance().GetCartWareList(result.Html);

            foreach (Data.Wares ware in waresUrls)
            {
                ListViewItem lvItem = new ListViewItem();
                lvItem.Text = ware.id.ToString();
                lvItem.SubItems.Add(ware.title);
                lvItem.SubItems.Add(ware.price);
                lsvCart.Items.Add(lvItem);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 结算按钮点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnJieSuan_Click(object sender, EventArgs e)
        {
            if (lsvCart.SelectedItems.Count > 0)
            {
                string cartHtml = JDHelper.GetInstance().GetCartHtml(_jdLoginer.cookies);
                string strRegex = string.Format(@"<input p-type=""{0}_\d+"".*?value=""([\d_]+)""", lsvCart.SelectedItems[0].Text);

                //把选中商品需要的优惠ID匹配出来
                Match    reg      = Regex.Match(cartHtml, strRegex, RegexOptions.Singleline);
                string[] pat      = reg.Groups[1].Value.Split('_');
                string   targetId = "0";
                string   ptype    = pat[1];
                if (pat.Length >= 3)
                {
                    targetId = pat[2];
                }
                //先取消全部商品选中状态
                JDHelper.GetInstance().CancelAllCart(_jdLoginer.cookies);
                //勾选需要结算的物品
                JDHelper.GetInstance().SelectCart(lsvCart.SelectedItems[0].Text, _jdLoginer.cookies, ptype, targetId);
                //获取结算页面
                string orderHtml = JDHelper.GetInstance().GetOrderInfo(_jdLoginer.cookies);
                //提交订单
                Dictionary <string, string> valueDic = JDHelper.GetInstance().GetValueFormHtml(orderHtml, "id");
                string eid = "", fp = "", riskControl = "";
                valueDic.TryGetValue("eid", out eid);
                valueDic.TryGetValue("fp", out fp);
                valueDic.TryGetValue("riskControl", out riskControl);
                string submitHtml = JDHelper.GetInstance().SubmitOrder(_jdLoginer.cookies, eid, fp, riskControl);
                return;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 添加购物车按钮点击
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnAddCart_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtWaresId.Text))
     {
         JDHelper.GetInstance().AddCart(_jdLoginer.cookies, txtWaresId.Text);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 获取商品信息按钮点击
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnGetWaresInfo_Click(object sender, EventArgs e)
        {
            Wares wares = JDHelper.GetInstance().GetWaresInfo(txtWaresId.Text);

            if (wares != null)
            {
                lsvFindWInfo.Items.Clear();
                ListViewItem lvItem = new ListViewItem();
                lvItem.Text = wares.id;
                lvItem.SubItems.Add(wares.title);
                lvItem.SubItems.Add(wares.price);
                lsvFindWInfo.Items.Add(lvItem);
            }
        }
Exemplo n.º 5
0
 private void btnOrderList_Click(object sender, EventArgs e)
 {
     JDHelper.GetInstance().GetOrderList(_jdLoginer.cookies);
     txtMessage.AppendText("");
 }
Exemplo n.º 6
0
 /// <summary>
 /// 清空购物车按钮点击
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnEmptyCart_Click(object sender, EventArgs e)
 {
     JDHelper.GetInstance().EmptyCart(_jdLoginer.cookies);
     lsvCart.Items.Clear();
 }