Пример #1
0
        /// <summary>
        /// 获取购物车json
        /// </summary>
        /// <returns></returns>
        public string CartSelectAllItem(string cookies)
        {
            //https://cart.jd.com/cart/miniCartServiceNew.action?callback=jQuery2645472&method=GetCart&_=1495720413767

            Random       rdm     = new Random();
            string       param1  = "jQuery" + Math.Floor(1e7 * rdm.NextDouble()).ToString();
            string       strTime = Tool.ConvertDateTimeToInt(DateTime.Now).ToString();
            HttpItem     item    = new HttpItem();
            SFHttpHelper helper  = new SFHttpHelper();
            HttpResult   result  = new HttpResult();

            item.URL = string.Format("https://cart.jd.com/cart/miniCartServiceNew.action?callback={0}&method=GetCart&_={1}", param1, strTime);

            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   = cookies;
            result        = helper.GetHtml(item);
            //_jdLoginer.cookies = result.Cookie;
            return(result.Html);
        }
Пример #2
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);
            }
        }
Пример #3
0
        /// <summary>
        /// 是否要验证码
        /// </summary>
        private bool CheckAuthcode()
        {
            //判断是否需要验证 返回Json({"verifycode":false})
            //https://passport.jd.com/uc/showAuthCode?r=0.7007493122946471&version=2015
            //https://authcode.jd.com/verify/image?a=1&acid=1c55bd67-241f-4b29-a56b-5c5bc6c717f7&uid=1c55bd67-241f-4b29-a56b-5c5bc6c717f7&yys=1454509280755
            HttpItem     item   = new HttpItem();
            SFHttpHelper helper = new SFHttpHelper();
            HttpResult   result = new HttpResult();
            string       r      = new Random().NextDouble().ToString();

            item.URL          = string.Format("https://passport.jd.com/uc/showAuthCode?r={0}&version=2015", r);
            item.ContentType  = "application/x-www-form-urlencoded; charset=utf-8";
            item.Postdata     = string.Format("loginName={0}", _jdLoginer.loginname);
            item.PostDataType = PostDataType.String;
            item.UserAgent    = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0";
            item.Cookie       = _jdLoginer.cookies;
            result            = helper.GetHtml(item);
            if (result.Html.ToLower().Contains("false"))
            {
                _isAuthcode = false;
                return(false);
            }
            else
            {
                _isAuthcode = true;
                return(true);
            }
        }
Пример #4
0
        /// <summary>
        /// 获取京东页面数据
        /// </summary>
        /// <param name="website"></param>
        /// <returns></returns>
        private string GetJDWebHtml(string website)
        {
            try
            {
                if (string.IsNullOrEmpty(website))
                {
                    return(null);
                }
                HttpItem     item   = new HttpItem();
                SFHttpHelper helper = new SFHttpHelper();
                HttpResult   result = new HttpResult();
                item.URL      = website;
                item.Encoding = Encoding.UTF8;
                item.Header.Add("Accept-Encoding", "gzip, deflate");
                item.ContentType = "text/html";
                item.UserAgent   = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)";
                item.Cookie      = _jdLoginer.cookies;
                result           = helper.GetHtml(item);
                if (result.Cookie != null)
                {
                    _jdLoginer.cookies = result.Cookie;
                }

                return(result.Html);
            }
            catch (Exception ex)
            {
                ImportThreads.LastMsg = "失败:未获取到网页数据";
                Debug.WriteLine(ex.Message);
                return(null);
            }
        }
Пример #5
0
        /// <summary>
        /// 退出京东
        /// </summary>
        private void Logout()
        {
            //退出登录   https://passport.jd.com/uc/login?ltype=logout
            HttpItem     item   = new HttpItem();
            SFHttpHelper helper = new SFHttpHelper();
            HttpResult   result = new HttpResult();

            item.URL    = "https://passport.jd.com/uc/login?ltype=logout";
            item.Cookie = _jdLoginer.cookies;
            result      = helper.GetHtml(item);
            if (result != null)
            {
            }
            _jdLoginer = null;
            ShowGetMessage("退出京东登录");
        }
Пример #6
0
        public string GetHtml(string url, string method, Encoding encoding, Dictionary <string, string> header = null)
        {
            SFHttpHelper helper = new SFHttpHelper();
            HttpResult   result = new HttpResult();

            hitem.URL               = url;
            hitem.Method            = method;
            hitem.Allowautoredirect = true;
            hitem.UserAgent         = _PC_UserAgent;
            hitem.ContentType       = _ContentType;
            hitem.Accept            = _Accept;
            hitem.Cookie            = _Cookies;

            if (_Referer != null)
            {
                hitem.Referer = _Referer;
            }

            if (header != null)
            {
                foreach (var item in header.Keys)
                {
                    hitem.Header.Add(item, header[item]);
                }
            }
            if (method == "post")
            {
                hitem.Postdata     = _Postdata;
                hitem.PostDataType = PostType;
            }

            result = helper.GetHtml(hitem);

            _Cookies = result.Cookie;

            return(result.Html);
        }
Пример #7
0
        /**********************************************************************************************************
        *   //京东模拟登录步骤
        *   //第一步:获取登录页面基础输入值;
        *   //第二步:判断是否需要验证码,如需要则取验证码图片到本地并由用户输入;
        *   //第三步:拼装所有提交信息;
        *   //第四步:提交数据到指定服务;
        *   //第五步:获取返回信息,通过正则表达式来取需要的数据。
        *   //https://passport.jd.com/new/login.aspx
        *   //post https://passport.jd.com/uc/loginService?uuid=b9155d01-fbe3-4a61-b15f-0fd99ea101a8&&r=0.8045588354580104&version=2015
        *   //如uuid、r、version
        *   //uuid ; r 随机数种子 会过期,过期后提示“authcode为空”;version 京东登录脚本的版本号
        *   //验证码图片获取地址
        *   //https://authcode.jd.com/verify/image?a=1&amp;acid=dd73def5-a635-4692-af7d-464491d99579&amp;uid=dd73def5-a635-4692-af7d-464491d99579
        *   //<div id="o-authcode" class="item item-vcode item-fore4  hide ">
        *   //https://passport.jd.com/uc/showAuthCode?r=0.7007493122946471&version=2015
        **********************************************************************************************************/

        /// <summary>
        /// 登录京东商城
        /// </summary>
        private bool Login(string authcode)
        {
            HttpItem     item   = new HttpItem();
            SFHttpHelper helper = new SFHttpHelper();
            HttpResult   result = new HttpResult();

            //如果需要验证码就需要jda,jdb,jdc,jdv这些,如果没有出验证码,可以直接post登录成功的
            //string cookies = "__jda=95931165.290243407.1371634814.1371634814.1371634814.1; __jdb=95931165.1.290243407|1.1371634814; __jdc=95931165; __jdv=95931165|direct|-|none|-;" + _jdLoginer.cookies;
            string cookies = "__jdu=1394616361; __jda=122270672.1394616361.1461636833.1461636833.1461636833.1; "
                             + "unpl=V2_ZzNtbRBWQxYiDhMAckpaBGJRE1tLB0oSIV8UB3tNWAZjChpeclRCFXIUR1FnGlsUZwIZXUZcQBRFCHZXchBYAGEHG1hyV0YdPHhGVXoYXQRmABRdcmdAFEUAdlR5EVkCZwQQWkJncxJFOJLoxM7du7KOg4nZ9HMXdABEXH0RXANXAiJcch"
                             + "wtFDgIRFx%2bHlwCZQQSbUM%3d; mt_subsite=||1111%2C1461636920; __jdb=122270672.5.1394616361|1.1461636833; __jdc=122270672; __jdv=122270672|click.union.timesdata.net"
                             + "|t_288547584_149xA1000000271|tuiguang|c012f7de8b704c078a86efcb1e525892; _tp=gvgIRVyymbK6lFmmkN3g4qGeJnHoph%2BdcBXbCOaBySY%3D; unick=%E4%B8%96%E7%BA%AA%E9%AB%98%E6%A1%A5;"
                             + " _pst=jd_7bb8087728c44; TrackID=1F5uT6zOHbmBW01TKlUyQ7GbEINQ09CbCTnXNkT2aqA8pwDg2ZR_B_Z5jWfneDJfNRQPoMXHH9sGbM7iJlmjiDX9BnAqcsEDlmDkvSQOQIH0; pinId=jc-OZwkDIvyjW1nEe9zdD7V9-x-f3wj7;"
                             + " _jrda=1; _jrdb=1461637460015; 3AB9D23F7A4B3C9B=78d97a3d1e9e4ae2832d21dbe81d6fd7394012304; alc=/Y1Y1CquLQZPWbDaIhh/8w==; _ntvsWYk=rsy+/seWbN6G+IYtHAWOUz3B8xVwiF4oDNcJUecODec=;"
                             + " mp=13908052076; _ntEhbrP=KPnWKr0GkGLYESVBeRIc7ucPudXAa+ADs6Z9GI6c5ug=; _ntevPgB=BAeWuzhoS+8o0U6OEKkSQH0hOa/4bp32f3dvImaQbzU=; _ntRblQD=vEujL7I++TMt+jeraYPTW/s56Fm8gBpoC9gN2FYO0XA="
                             + _jdLoginer.cookies;

            cookies            = cookies.Replace("HttpOnly,", null);
            _jdLoginer.cookies = cookies;

            //https://passport.jd.com/uc/loginService?uuid=c4ee6786-a737-43f2-9110-0aea68500665&ReturnUrl=http%3A%2F%2Fwww.jd.com%2F&r=0.12566684937051964&version=2015
            //https://passport.jd.com/uc/loginService?uuid=c8422a2d-e011-4783-8bca-38625607a086&ltype=logout&r=0.04991701628602441&version=2015
            item.URL               = string.Format("https://passport.jd.com/uc/loginService?uuid={0}&ltype=logout&r={1}&version=2015", _jdLoginer.uuid, _jdLoginer.r);
            item.Method            = "post";
            item.Allowautoredirect = true;
            item.ContentType       = "application/x-www-form-urlencoded; charset=UTF-8";
            item.Postdata          = string.Format("uuid={0}&machineNet=&machineCpu=&machineDisk=&eid={1}&fp={2}&_t={3}&{4}={5}"
                                                   + "&loginname={6}&nloginpwd={7}&loginpwd={7}&chkRememberMe=on&authcode={8}",
                                                   _jdLoginer.uuid, _jdLoginer.eid, _jdLoginer.fp, _jdLoginer._t, _jdLoginer.tname, _jdLoginer.tvalue,
                                                   _jdLoginer.loginname, _jdLoginer.loginpwd, authcode);
            item.Header.Add("x-requested-with", "XMLHttpRequest");
            item.Header.Add("Accept-Encoding", "gzip, deflate");
            //item.Referer = "http://passport.jd.com/new/login.aspx?ReturnUrl=http%3a%2f%2fjd2008.jd.com%2fJdHome%2fOrderList.aspx";
            item.Accept        = "*/*";
            item.Encoding      = Encoding.UTF8;
            item.Cookie        = cookies;
            result             = helper.GetHtml(item);
            _jdLoginer.cookies = result.Cookie;

            if (!result.Html.Contains("success"))
            {
                string   rtnMsg = result.Html.Remove(0, 1).TrimEnd(')');
                LoginMsg jdMsg  = JsonConvert.DeserializeObject <LoginMsg>(rtnMsg);
                //用户名错误({"username":"******"})
                if (result.Html.ToLower().Contains("username"))
                {
                    ShowGetMessage("失败:用户名错误!" + jdMsg.value);
                    ImportThreads.LastMsg = "失败:用户名错误!" + jdMsg.value;
                }
                else if (result.Html.ToLower().Contains("pwd"))
                {
                    ShowGetMessage("失败:密码验证不通过!" + jdMsg.value);
                    //密码错误 ({"pwd":"\u8d26\u6237\u540d\u4e0e\u5bc6\u7801\u4e0d\u5339\u914d\uff0c\u8bf7\u91cd\u65b0\u8f93\u5165"})
                    ImportThreads.LastMsg = "失败:密码验证不通过!" + jdMsg.value;
                }
                else if (result.Html.ToLower().Contains("emptyauthcode"))
                {
                    ShowGetMessage("失败:请输入登录验证码!" + jdMsg.value);
                    //验证码错误 ({"emptyAuthcode":"\u8bf7\u8f93\u5165\u9a8c\u8bc1\u7801"})
                    //({"_t":"_ntcKIiJ","emptyAuthcode":"\u9a8c\u8bc1\u7801\u4e0d\u6b63\u786e\u6216\u9a8c\u8bc1\u7801\u5df2\u8fc7\u671f"})
                    ImportThreads.LastMsg = "失败:请输入登录验证码!" + jdMsg.value;
                }
                else
                {
                    ImportThreads.LastMsg = jdMsg.value;
                }
                ImportThreads.WareEnd = true;
                return(false);
            }
            ShowGetMessage("登录成功!");
            ImportThreads.LastMsg = "登录成功!";
            return(true);
        }