Ejemplo n.º 1
0
        public void GetCityLibrary()
        {
            if (bCityLibraryFinished)
            {
                return;
            }

            while (true)
            {
                HttpParam pmCityLibrary = new HttpParam(pmLogin, false);
                DxWinHttp http          = new DxWinHttp();
                http.Open("POST", HttpParam.URL + @"address/cityLibrary.action", true);
                SetHttpRequestHeader(ref http, pmCityLibrary.GetSign());
                http.Send(pmCityLibrary.GetParam());

                WaitForResponse(ref http);
                if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                {
                    JObject joCityLibraryResult = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                    if ((string)joCityLibraryResult["code"] == @"0")
                    {
                        JArray jaCityLibrary = (JArray)joCityLibraryResult["data"]["list"];
                        foreach (JObject city in jaCityLibrary)
                        {
                            dcCityLibrary.Add((string)city["code"], (string)city["name"]);
                        }
                        bCityLibraryFinished = true;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void SendPrices(int concertId)
        {
            while (true)
            {
                HttpParam pmPrices = new HttpParam(pmLogin);
                pmPrices.joBody = new JObject(
                    new JProperty("concertId", Convert.ToString(concertId))
                    );
                JObject joPricesReturn = new JObject();
                Dictionary <string, int> dcPriceGoodId = new Dictionary <string, int>();
                while (true)
                {
                    DxWinHttp http = new DxWinHttp();
                    http.Open("POST", HttpParam.URL + @"ticket/prices.action", true);
                    SetHttpRequestHeader(ref http, pmPrices.GetSign());
                    http.Send(pmPrices.GetParam());

                    WaitForResponse(ref http);
                    if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                    {
                        //string ret = File.ReadAllText("prices_return.txt");
                        //joPricesReturn = (JObject)JsonConvert.DeserializeObject(ret);

                        joPricesReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                        if ((string)joPricesReturn["code"] == @"0")
                        {
                            JArray jaPrices = (JArray)joPricesReturn["data"]["prices"];
                            foreach (JObject joPrice in jaPrices)
                            {
                                if ((string)joPrice["restStock"] != @"0")
                                {
                                    dcPriceGoodId.Add((string)joPrice["title"], (int)joPrice["goodsId"]);
                                }
                            }
                            dc_ConcertId_dcPriceGoodId[concertId] = dcPriceGoodId;
                            dc_ConcertId_Finished[concertId]      = true;
                            return;
                        }
                    }

                    if (DateTime.Now < AllPlayers.dtStartTime)
                    {
                        if ((AllPlayers.dtStartTime - DateTime.Now).TotalMilliseconds > 60000)
                        {
                            Thread.Sleep(60000);
                        }
                        else if ((AllPlayers.dtStartTime - DateTime.Now).TotalMilliseconds > 1000)
                        {
                            Thread.Sleep(1000);
                        }
                    }
                    else
                    {
                        Thread.Sleep(50);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        void SendNotReadNum()
        {
            while (true)
            {
                while (true)
                {
                    DxWinHttp http = new DxWinHttp();
                    http.Open("POST", HttpParam.URL + @"news/notReadNum.action", true);
                    SetHttpRequestHeader(ref http, pmNotReadNum.GetSign());
                    http.Send(pmNotReadNum.GetParam());

                    WaitForResponse(ref http);
                    if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                    {
                        JObject joNotReadNumResult = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                        if ((string)joNotReadNumResult["code"] == @"0")
                        {
                            break;
                        }
                    }
                }
                Thread.Sleep(AllPlayers.nNotReadNumInterval * 1000);
            }
        }
Ejemplo n.º 4
0
        public void Run()
        {
            Program.form1.UpdateDataGridView(strTelephone, Column.Login, "false");
            Program.form1.UpdateDataGridView(strTelephone, Column.OrderInfo, @"");

            // login.action
            pmLogin = new HttpParam(joLoginParam);
            JObject joLoginReturn = new JObject();
            int     nTimes        = 0;

            while (true)
            {
                DxWinHttp http = new DxWinHttp();
                http.Open("POST", HttpParam.URL + @"account/login.action", true);
                SetHttpRequestHeader(ref http, pmLogin.GetSign());
                http.Send(pmLogin.GetParam());

                WaitForResponse(ref http);
                if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                {
                    joLoginReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                    if ((string)joLoginReturn["code"] == @"0")
                    {
                        break;
                    }
                }
                nTimes++;
                if (nTimes >= 10)
                {
                    Program.form1.UpdateDataGridView(strTelephone, Column.Login, "放弃");
                    return;
                }
            }
            pmLogin.strUserId    = (string)joLoginReturn["data"][HttpParam.USERID];
            pmLogin.strUserToken = (string)joLoginReturn["data"][HttpParam.USERTOKEN];
            Program.form1.UpdateDataGridView(strTelephone, Column.Login, "true");
            if (AllPlayers.nLoginTimes == 1)
            {
                Program.form1.UpdateDataGridView(strTelephone, Column.Name, (string)joLoginReturn["data"]["realName"]);
            }

            // addressList.action
            if (AllPlayers.nLoginTimes == 1)
            {
                // CityLibrary.action
                bool bNeedGetCityLibrary = false;
                lock (this)
                {
                    if (!bCityLibraryApply)
                    {
                        bNeedGetCityLibrary = true;
                        bCityLibraryApply   = true;
                    }
                }

                if (bNeedGetCityLibrary)
                {
                    GetCityLibrary();
                }

                HttpParam pmAddressList = new HttpParam(pmLogin);
                pmAddressList.joBody = new JObject();
                JObject joAddressListReturn = new JObject();
                while (true)
                {
                    DxWinHttp http = new DxWinHttp();
                    http.Open("POST", HttpParam.URL + @"address/addressList.action", true);
                    SetHttpRequestHeader(ref http, pmAddressList.GetSign());
                    http.Send(pmAddressList.GetParam());

                    WaitForResponse(ref http);
                    if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                    {
                        joAddressListReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                        if ((string)joAddressListReturn["code"] == @"0")
                        {
                            JArray jaAddressList = (JArray)joAddressListReturn["data"]["list"];
                            if (jaAddressList.Count <= 0)
                            {
                                Program.form1.UpdateDataGridView(strTelephone, Column.Address, @"null");
                                return;
                            }
                            joAddress = new JObject();
                            foreach (JObject addr in jaAddressList)
                            {
                                if ((int)addr["isDefault"] == 1)
                                {
                                    joAddress = addr;
                                    break;
                                }
                            }

                            while (!bCityLibraryFinished)
                            {
                                Thread.Sleep(1);
                            }

                            string strProvince = dcCityLibrary[(string)joAddress["provinceCode"]];
                            string strCity     = dcCityLibrary[(string)joAddress["cityCode"]];
                            string strArea     = dcCityLibrary[(string)joAddress["areaCode"]];
                            strAddress = strProvince + @" " + strCity + @" " + strArea + @" " + (string)joAddress["address"];
                            Program.form1.UpdateDataGridView(strTelephone, Column.Address, strAddress);
                            break;
                        }
                    }
                }
            }

            // myOrders.action & cancel.action
            //if (AllPlayers.nLoginTimes > 1)
            {
                HttpParam pmMyOrder = new HttpParam(pmLogin);
                pmMyOrder.joBody = new JObject(
                    new JProperty("time", ulong.Parse(HttpParam.Timestamp())),
                    new JProperty("orderStatus", 0),
                    new JProperty("startIndex", 0),
                    new JProperty("pageSize", 20)
                    );
                JObject joMyOrderReturn = new JObject();
                while (true)
                {
                    DxWinHttp http = new DxWinHttp();
                    http.Open("POST", HttpParam.URL + @"user/myOrders.action", true);
                    SetHttpRequestHeader(ref http, pmMyOrder.GetSign());
                    http.Send(pmMyOrder.GetParam());

                    WaitForResponse(ref http);
                    if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                    {
                        joMyOrderReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                        if ((string)joMyOrderReturn["code"] == @"0")
                        {
                            JArray jaOrder = (JArray)joMyOrderReturn["data"]["list"];
                            foreach (JObject order in jaOrder)
                            {
                                if ((string)order["orderType"] == "3" && (string)order["orderStatus"] == "0")
                                {
                                    HttpParam pmCancel = new HttpParam(pmLogin);
                                    pmCancel.joBody = new JObject(
                                        new JProperty("orderId", (string)order["orderId"])
                                        );
                                    JObject joCancel = new JObject();
                                    while (true)
                                    {
                                        DxWinHttp httpCancel = new DxWinHttp();
                                        httpCancel.Open("POST", HttpParam.URL + @"order/cancel.action", true);
                                        SetHttpRequestHeader(ref httpCancel, pmCancel.GetSign());
                                        httpCancel.Send(pmCancel.GetParam());

                                        WaitForResponse(ref httpCancel);
                                        if (httpCancel.ResponseBody.Length > 0 && httpCancel.ResponseBody.IndexOf(@"""code"":") >= 0)
                                        {
                                            joCancel = (JObject)JsonConvert.DeserializeObject(httpCancel.ResponseBody);
                                            JToken outMsg;
                                            if ((string)joCancel["code"] == @"0" || (joCancel.TryGetValue("msg", out outMsg) && outMsg.Type != JTokenType.Null))
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
            }

            // Prices.action
            bool bNeedGetPrices = false;

            lock (this)
            {
                if (!bPricesApply)
                {
                    bNeedGetPrices = true;
                    bPricesApply   = true;
                }
            }
            if (bNeedGetPrices)
            {
                SendPricesWithThread();
            }

            // notReadNum.action
            if (AllPlayers.nLoginTimes == 1)
            {
                pmNotReadNum        = new HttpParam(pmLogin);
                pmNotReadNum.joBody = new JObject(
                    new JProperty("type", (int)16843169),
                    new JProperty(HttpParam.USERID, pmLogin.strUserId)
                    );
                Thread threadNotReadNum = new Thread(new ThreadStart(SendNotReadNum));
                threadNotReadNum.Start();

                // wait start time
                while ((DateTime.Now < AllPlayers.dtStartTime))
                {
                    if ((AllPlayers.dtStartTime - DateTime.Now).TotalMilliseconds > 60000)
                    {
                        Thread.Sleep(60000);
                    }
                    else if ((AllPlayers.dtStartTime - DateTime.Now).TotalMilliseconds > 1000)
                    {
                        Thread.Sleep(1000);
                    }
                    else if ((AllPlayers.dtStartTime - DateTime.Now).TotalMilliseconds > 50)
                    {
                        Thread.Sleep(50);
                    }
                    else
                    {
                        Thread.Sleep(1);
                    }
                }
                threadNotReadNum.Abort();
            }

            // sectionOrder.action
            HttpParam pmSectionOrder = new HttpParam(pmLogin);

            pmSectionOrder.joBody = new JObject(
                new JProperty("addressId", (string)joAddress["addressId"]),
                new JProperty("address", strAddress),
                new JProperty("phone", (string)joAddress["phone"]),
                new JProperty("goodsIds", @" "),
                new JProperty("concertId", @" "),
                new JProperty("contact", (string)joAddress["name"]),
                new JProperty("provinceCode", (string)joAddress["provinceCode"])
                );

            HttpParam pmOrderInfo = new HttpParam(pmLogin);

            pmOrderInfo.joBody = new JObject(
                new JProperty("goodsIds", @" "),
                new JProperty("concertId", @" ")
                );

            HttpParam pmAddressListForOrder = new HttpParam(pmLogin);

            pmAddressListForOrder.joBody = new JObject();

            List <Thread> listThread = new List <Thread>();

            foreach (JObject joPrice in AllPlayers.jaConcert)
            {
                int    nConcertId  = (int)joPrice["ConcertId"];
                int    nGoodsIdNum = (int)joPrice["GoodsIdNum"];
                string strGoodsIds = "{0}";
                for (int i = 1; i < nGoodsIdNum; i++)
                {
                    strGoodsIds = strGoodsIds + ",{0}";
                }
                string   strPrices   = (string)joPrice["Prices"];
                string[] arrayPrices = strPrices.Split(new Char[] { ',', ' ', ';' });
                while (!dc_ConcertId_Finished[nConcertId])
                {
                    Thread.Sleep(1);
                }

                pmOrderInfo.joBody["concertId"]    = Convert.ToString(nConcertId);
                pmSectionOrder.joBody["concertId"] = Convert.ToString(nConcertId);
                foreach (string price in arrayPrices)
                {
                    if (dc_ConcertId_dcPriceGoodId.ContainsKey(nConcertId) && dc_ConcertId_dcPriceGoodId[nConcertId].ContainsKey(price))
                    {
                        pmOrderInfo.joBody["goodsIds"]    = string.Format(strGoodsIds, dc_ConcertId_dcPriceGoodId[nConcertId][price]);
                        pmSectionOrder.joBody["goodsIds"] = string.Format(strGoodsIds, dc_ConcertId_dcPriceGoodId[nConcertId][price]);
                        HttpParam _pmSecitionOrder = new HttpParam(pmSectionOrder);
                        _pmSecitionOrder.joBody = new JObject(pmSectionOrder.joBody);
                        HttpParam _pmOrderInfo = new HttpParam(pmOrderInfo);
                        _pmOrderInfo.joBody = new JObject(pmOrderInfo.joBody);
                        HttpParam _pmAddressListForOrder = new HttpParam(pmAddressListForOrder);
                        _pmAddressListForOrder.joBody = new JObject(pmAddressListForOrder.joBody);
                        Thread threadSectionOrder = new Thread(new ThreadStart(() => SendSectionOrder(_pmOrderInfo, _pmAddressListForOrder, _pmSecitionOrder)));
                        threadSectionOrder.Start();
                        listThread.Add(threadSectionOrder);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        void SendSectionOrder(HttpParam _pmOrderInfo, HttpParam _pmAddressListForOrder, HttpParam _param)
        {
            JObject joOrderInfoReturn = new JObject();

            while (true)
            {
                DxWinHttp http = new DxWinHttp();
                http.Open("POST", HttpParam.URL + @"ticket/orderInfo.action", true);
                SetHttpRequestHeader(ref http, _pmOrderInfo.GetSign());
                http.Send(_pmOrderInfo.GetParam());

                WaitForResponse(ref http);
                if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                {
                    joOrderInfoReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                    if ((string)joOrderInfoReturn["code"] == @"0")
                    {
                        break;
                    }
                }
            }

            JObject joAddressListForOrderReturn = new JObject();

            while (true)
            {
                DxWinHttp http = new DxWinHttp();
                http.Open("POST", HttpParam.URL + @"address/addressList.action", true);
                SetHttpRequestHeader(ref http, _pmAddressListForOrder.GetSign());
                http.Send(_pmAddressListForOrder.GetParam());

                WaitForResponse(ref http);
                if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                {
                    joAddressListForOrderReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                    if ((string)joAddressListForOrderReturn["code"] == @"0")
                    {
                        break;
                    }
                }
            }

            DateTime timeStart = DateTime.Now;

            while (true)
            {
                DxWinHttp http = new DxWinHttp();
                http.Open("POST", HttpParam.URL + @"ticket/sectionOrder.action", true);
                SetHttpRequestHeader(ref http, _param.GetSign());
                http.Send(_param.GetParam());

                WaitForResponse(ref http);
                if (http.ResponseBody.Length > 0 && http.ResponseBody.IndexOf(@"""code"":") >= 0)
                {
                    JObject joSectionOrderReturn = (JObject)JsonConvert.DeserializeObject(http.ResponseBody);
                    if ((string)joSectionOrderReturn["code"] == @"0")
                    {
                        Program.form1.UpdateDataGridView(strTelephone, Column.OrderInfo, (string)joSectionOrderReturn["msg"]);
                        break;
                    }

                    JToken outMsg;
                    if (joSectionOrderReturn.TryGetValue("msg", out outMsg) && outMsg.Type != JTokenType.Null)
                    {
                        if (AllPlayers.nLoginTimes == 1)
                        {
                            if (string.Compare((string)joSectionOrderReturn["msg"], @"访问频率太频繁") == 0)
                            {
                                break;
                            }
                            else if ((int)((DateTime.Now - timeStart).TotalSeconds) > 60)
                            {
                                break;
                            }
                        }
                        else
                        {
                            if ((int)((DateTime.Now - timeStart).TotalSeconds) > 300)
                            {
                                break;
                            }
                            else if (string.Compare((string)joSectionOrderReturn["msg"], @"访问频率太频繁") == 0)
                            {
                                Thread.Sleep(60000);
                            }
                        }
                    }
                }
            }
        }