Beispiel #1
0
        //这里需要添加问题答案的部分!!!!!!!!!!!!
        public string GetOrderPostData(string orderPage, bool modifyQuantity, int quantity, bool modifyTransport, string transport, bool modifyMemo, string memo, bool modifyPromotion, bool modifyShopPromotion, bool modifyAnnoy, bool applyPriceBorder, int priceBorder, out bool lessPriceBorder, CookieContainer cc, string questionAnswer)
        {
            lessPriceBorder = true;

            if (string.IsNullOrEmpty(orderPage))
            {
                auctionLog.Log("警告:传递的订单页面源代码为空");
                return(string.Empty);
            }

            GetOrderFormContent(orderPage);

            string orderInformationDomain = GetOrderInformationDomain(orderPage);

            if (string.IsNullOrEmpty(orderInformationDomain))
            {
                return(string.Empty);
            }

            GetOrderTransports(orderInformationDomain);
            GetOrderPromotion(orderInformationDomain);
            GetOrderShopPromotion(orderInformationDomain);

            if (inputControls.Count < 1)
            {
                auctionLog.Log("警告:未发现订单页面中的input控件");
                return(string.Empty);
            }

            string postData = String.Empty;
            bool   transportArranged = false, addressArranged = false, codArranged = false;
            string selectedTansport = string.Empty, bestTransport = string.Empty;

            if (string.IsNullOrEmpty(promotion.Price))
            {
                auctionLog.Log("警告:未从促销选项中获得价格信息,尝试从整个订单表单数据域中获取");
                Match priceMatch = Regex.Match(orderInformationDomain, "price\\s*\"\\s*:\\s*\"(?<price>\\d+)\\s*\"", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (priceMatch.Success)
                {
                    actualFee = int.Parse(priceMatch.Groups["price"].ToString());
                }
                else
                {
                    auctionLog.Log("警告:未发现任何价格信息,价格边界条件失效");
                }
            }
            else
            {
                actualFee = int.Parse(promotion.Price);
            }

            //获取运输方式信息,避免重复计算运费使用
            if (postage.Transports.Count > 0)
            {
                if (modifyTransport && !string.IsNullOrEmpty(transport))
                {
                    selectedTansport = GetSelectedTransport(transport);
                }
                else
                {
                    bestTransport = GetBestTransport();
                }
            }

            //生成post数据
            foreach (InputControl inputControl in inputControls)
            {
                if (inputControl.Control.ToLower() == "input")
                {
                    if (inputControl.Type.ToLower() == "text")
                    {
                        //修改购买数量
                        if (inputControl.Name.ToLower() == "_fm.g._0.q")
                        {
                            if (modifyQuantity)
                            {
                                postData += inputControl.Name + "=" + quantity.ToString() + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                            continue;
                        }

                        //填写其他地址邮政编码
                        if (inputControl.Name.ToLower() == "_fm.g._0.p")
                        {
                            postData += inputControl.Name + "=" + addressInformation.Postcode + "&";
                            continue;
                        }

                        //填写其他地址的收货人
                        if (inputControl.Name.ToLower() == "_fm.g._0.de")
                        {
                            postData += inputControl.Name + "=" + addressInformation.Addressee + "&";
                            continue;
                        }

                        //填写其他地址的手机
                        if (inputControl.Name.ToLower() == "_fm.g._0.deli")
                        {
                            postData += inputControl.Name + "=" + addressInformation.Mobile + "&";
                            continue;
                        }

                        //填写验证码,这里需要添加验证码识别的部分!!!!!!!!!!!!!!!!!!!!
                        if (inputControl.Name.ToLower() == "_fm.g._0.c")
                        {
                            if (isCheckCode)
                            {
                                auctionLog.Log("通知:可能需要输入验证码");
                                DateTime dt1 = new DateTime(1970, 1, 1);
                                DateTime dt2 = DateTime.Now;
                                TimeSpan ts  = new TimeSpan(dt2.Ticks - dt1.Ticks);

                                CookieCollection ccReturned;
                                Bitmap           image = new Bitmap(auctionOperations.GetCheckCodeImageStream("http://checkcode.taobao.com/auction/checkcode?sessionID=" + encryptString + "&t=" + (ts.Ticks / 10000).ToString(), cc, out ccReturned));
                                cc.Add(ccReturned);

                                checkCodeForm.checkCodePic.Image = image;
                                checkCodeForm.ShowDialog();
                                postData += inputControl.Name + "=" + checkCodeForm.txtCheckCode.Text.Trim() + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                            continue;
                        }

                        //填写问题答案
                        if (inputControl.Name.ToLower() == "_fm.g._0.s" && !string.IsNullOrEmpty(questionAnswer))
                        {
                            postData += inputControl.Name + "=" + questionAnswer + "&";
                            continue;
                        }

                        postData += inputControl.Name + "=" + inputControl.Value + "&";
                        continue;
                    }

                    if (inputControl.Type.ToLower() == "radio")
                    {
                        //默认选择第一个收货地址
                        if (inputControl.Name.ToLower() == "address" && !addressArranged)
                        {
                            postData       += inputControl.Name + "=" + inputControl.Value + "&";
                            addressArranged = true;
                            continue;
                        }

                        //修改运输方式
                        if (inputControl.Name.ToLower() == "_shipping_option" && !transportArranged && postage.Transports.Count > 0)
                        {
                            if (modifyTransport && !string.IsNullOrEmpty(transport))
                            {
                                postData += inputControl.Name + "=" + selectedTansport + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + bestTransport + "&";
                            }
                            transportArranged = true;
                            continue;
                        }

                        //修改包含货到付款的运输方式
                        if (inputControl.Name.ToLower() == "consignment" && !codArranged)
                        {
                            postData   += inputControl.Name + "=" + inputControl.Value + "&";
                            codArranged = true;
                            continue;
                        }
                        continue;
                    }

                    if (inputControl.Type.ToLower() == "hidden")
                    {
                        //修改运输方式
                        if (inputControl.Name.ToLower() == "_fm.g._0.sh")
                        {
                            if (postage.Transports.Count > 0)
                            {
                                if (modifyTransport && !string.IsNullOrEmpty(transport))
                                {
                                    postData += inputControl.Name + "=" + selectedTansport + "&";
                                }
                                else
                                {
                                    postData += inputControl.Name + "=" + bestTransport + "&";
                                }
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                            continue;
                        }

                        //修改购买数量
                        if (inputControl.Name.ToLower() == "quantity")
                        {
                            if (modifyQuantity)
                            {
                                postData += inputControl.Name + "=" + quantity.ToString() + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                            continue;
                        }

                        //填写地区码
                        if (inputControl.Name.ToLower() == "_fm.g._0.di")
                        {
                            postData += inputControl.Name + "=" + addressInformation.AreaCode + "&";
                            continue;
                        }

                        postData += inputControl.Name + "=" + inputControl.Value + "&";
                        continue;
                    }

                    //修改是否匿名
                    if (inputControl.Type.ToLower().Trim() == "checkbox" && inputControl.Name.ToLower().Contains("anony"))
                    {
                        //修改留言
                        if (modifyMemo)
                        {
                            postData += "_fm.g._0.w" + "=" + memo + "&";
                        }
                        else
                        {
                            postData += "_fm.g._0.w" + "=" + "&";
                        }

                        //修改促销方式
                        string promotionString = modifyPromotion ? GetPromotionString(true) : GetPromotionString(false);
                        if (!string.IsNullOrEmpty(promotionString))
                        {
                            postData += promotionString + "&";
                        }

                        //修改店铺促销方式
                        string shopPromotionString = modifyShopPromotion ? GetShopPromotionString(true) : GetShopPromotionString(false);
                        if (!string.IsNullOrEmpty(shopPromotionString))
                        {
                            postData += shopPromotionString + "&";
                        }

                        //修改是否匿名
                        if (modifyAnnoy)
                        {
                            postData += inputControl.Name + "=" + inputControl.Value + "&";
                        }

                        continue;
                    }
                    continue;
                }

                //填写其他地址信息
                if (inputControl.Control.ToLower() == "select")
                {
                    if (inputControl.Name.ToLower() == "n_prov")
                    {
                        postData += inputControl.Name + "=" + addressInformation.AreaCode.Substring(0, 2) + "0000" + "&";
                        continue;
                    }

                    if (inputControl.Name.ToLower() == "n_city")
                    {
                        postData += inputControl.Name + "=" + addressInformation.AreaCode.Substring(0, 4) + "00" + "&";
                        continue;
                    }

                    if (inputControl.Name.ToLower() == "n_area")
                    {
                        postData += inputControl.Name + "=" + addressInformation.AreaCode + "&";
                        continue;
                    }
                    continue;
                }

                //填写街道地址信息
                if (inputControl.Control.ToLower() == "textarea")
                {
                    if (inputControl.Name.ToLower() == "_fm.g._0.d")
                    {
                        postData += inputControl.Name + "=" + addressInformation.Address + "&";
                        continue;
                    }
                    continue;
                }
            }

            if (postData.EndsWith("&"))
            {
                postData = postData.Substring(0, postData.Length - 1);
            }

            //更正应付费信息
            postData = Regex.Replace(postData, "actualPaidFee\\s*=.*?&", "actualPaidFee=" + actualFee.ToString() + "&");

            //是否满足价格边界条件
            if (applyPriceBorder && actualFee > 0 && actualFee > priceBorder)
            {
                lessPriceBorder = false;
            }

            return(postData);
        }
        //这里需要添加问题答案的部分!!!!!!!!!!!!
        public string GetOrderPostData(string orderPage, bool modifyQuantity, int quantity, bool modifyTransport, string transport, bool modifyMemo, string memo, bool modifyPromotion, bool modifyShopPromotion, bool modifyAnnoy, bool applyPriceBorder, int priceBorder, out bool lessPriceBorder, CookieContainer cc)
        {
            lessPriceBorder = true;
            if (string.IsNullOrEmpty(orderPage))
            {
                auctionLog.Log("警告:传递的订单页面源代码为空");
                return(string.Empty);
            }

            GetOrderFormContent(orderPage);

            string orderInformationDomain = GetOrderInformationDomain(orderPage);

            if (string.IsNullOrEmpty(orderInformationDomain))
            {
                return(string.Empty);
            }

            GetOrderTransports(orderInformationDomain);
            GetOrderPromotion(orderInformationDomain);
            GetOrderShopPromotion(orderInformationDomain);

            if (inputControls.Count < 1)
            {
                auctionLog.Log("警告:未发现订单页面中的input控件");
                return(string.Empty);
            }

            string postData = String.Empty;
            string selectedTansport = string.Empty, defaultTransport = string.Empty;

            if (string.IsNullOrEmpty(promotion.Price))
            {
                auctionLog.Log("警告:未从促销选项中获得价格信息,尝试从整个订单表单数据域中获取");
                Match priceMatch = Regex.Match(orderInformationDomain, "price\\s*\"\\s*:\\s*\"(?<price>\\d+)\\s*\"", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline);
                if (priceMatch.Success)
                {
                    actualFee = int.Parse(priceMatch.Groups["price"].ToString());
                }
                else
                {
                    auctionLog.Log("警告:未发现任何价格信息,价格边界条件失效");
                }
            }
            else
            {
                actualFee = int.Parse(promotion.Price);
            }

            //获取运输方式信息,避免重复计算运费使用
            if (modifyTransport)
            {
                selectedTansport = GetSelectedTransport(transport);
            }
            else
            {
                defaultTransport = GetDefaultTransport();
            }


            //生成post数据
            foreach (InputControl inputControl in inputControls)
            {
                if (inputControl.Control.ToLower() == "input")
                {
                    if (inputControl.Type.ToLower() == "text")
                    {
                        //是否修改数量
                        if (inputControl.Name.ToLower().Contains("quantity"))
                        {
                            if (modifyQuantity)
                            {
                                postData += inputControl.Name + "=" + quantity.ToString() + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                            continue;
                        }

                        //填写验证码
                        if (inputControl.Name.ToLower() == "checkcode")
                        {
                            if (checkCode.isCheckCode == "true")
                            {
                                postData = inputControl.Name + "=" + checkCode.checkCode + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                            continue;
                        }

                        postData += inputControl.Name + "=" + inputControl.Value + "&";
                    }
                    if (inputControl.Type.ToLower() == "hidden")
                    {
                        //设置运输方式input(codServiceType),注意,如果以后淘宝升级免运费状态下不用列表选择,注意将该控件value设置为0
                        if (inputControl.Name.ToLower().Contains("codservicetype") && modifyTransport)
                        {
                            if (modifyTransport)
                            {
                                postData += inputControl.Name + "=" + selectedTansport + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + defaultTransport + "&";
                            }
                        }
                        else
                        {
                            //获取验证码并填充newCheckCode表单字段,注意,这里需要添加验证码识别的部分!!!!!!!!!!!!!!!!!!!!
                            if (inputControl.Name.ToLower() == "newCheckCode" && checkCode.isCheckCode == "true")
                            {
                                auctionLog.Log("通知:可能需要输入验证码");

                                CookieCollection ccReturned;
                                Bitmap           image = new Bitmap(auctionOperations.GetCheckCodeImageStream("http://checkcode.taobao.com/auction/checkcode?sessionID=" + checkCode.encrypterString, cc, out ccReturned));
                                cc.Add(ccReturned);
                                checkCodeForm.checkCodePic.Image = image;
                                checkCodeForm.ShowDialog();
                                checkCode.checkCode = checkCodeForm.txtCheckCode.Text.Trim();

                                if (string.IsNullOrEmpty(checkCode.checkCode))
                                {
                                    auctionLog.Log("警告:并未输入验证码");
                                    return(string.Empty);
                                }

                                string newCheckCode = auctionOperations.GetNewCheckCode(checkCode, cc, out ccReturned);
                                cc.Add(ccReturned);
                                if (string.IsNullOrEmpty(newCheckCode))
                                {
                                    auctionLog.Log("警告:未能成功获取newCheckCode数据");
                                    return(string.Empty);
                                }

                                postData += inputControl.Name + "=" + newCheckCode + "&";
                            }
                            else
                            {
                                postData += inputControl.Name + "=" + inputControl.Value + "&";
                            }
                        }
                    }

                    //修改是否匿名
                    if (inputControl.Type.ToLower().Trim() == "checkbox" && inputControl.Name.ToLower().Contains("anony") && modifyAnnoy)
                    {
                        postData += inputControl.Name + "=" + inputControl.Value + "&";
                    }
                }

                if (inputControl.Control.ToLower() == "textarea")
                {
                    //修改促销方式
                    string promotionString = modifyPromotion ? GetPromotionString(true) : GetPromotionString(false);
                    if (!string.IsNullOrEmpty(promotionString))
                    {
                        postData += promotionString + "&";
                    }

                    //修改留言
                    if (modifyMemo && !string.IsNullOrEmpty(memo))
                    {
                        postData += inputControl.Name + "=" + memo + "&";
                    }
                    else
                    {
                        postData += inputControl.Name + "=" + inputControl.Value + "&";
                    }

                    //修改店铺促销方式
                    string shopPromotionString = modifyShopPromotion ? GetShopPromotionString(true) : GetShopPromotionString(false);
                    if (!string.IsNullOrEmpty(shopPromotionString))
                    {
                        postData += shopPromotionString + "&";
                    }
                }
                if (inputControl.Control.ToLower() == "select")
                {
                    //修改运输方式Select
                    if (inputControl.Name.ToLower().Contains("post"))
                    {
                        if (modifyTransport)
                        {
                            postData += inputControl.Name + "=" + selectedTansport + "&";
                        }
                        else
                        {
                            postData += inputControl.Name + "=" + defaultTransport + "&";
                        }
                    }
                }
            }

            if (postData.EndsWith("&"))
            {
                postData = postData.Substring(0, postData.Length - 1);
            }

            if (applyPriceBorder && actualFee > 0 && actualFee > priceBorder)
            {
                lessPriceBorder = false;
            }

            return(postData);
        }