예제 #1
0
        public void Login(string account, int deviceType, string imei, string deviceName, string deviceId, string password)
        {
            string parameter = "&account=" + account
                               + "&deviceType=" + deviceType
                               + "&imei=" + imei
                               + "&deviceName=" + deviceName
                               + "&deviceId=" + deviceId
                               + "&password=" + password;

            Thread thread = new Thread(() =>
            {
                string url = this.m_Url;

                bool iss       = false;
                string content = HttpHelper2.HttpGet(url, parameter, out iss);

                if (LoginEvent != null)
                {
                    if (iss)
                    {
                        LoginEvent(content, new EventArgs());
                    }
                    else
                    {
                        LoginEvent(content, null);
                    }
                }
            });

            thread.Start();
        }
예제 #2
0
        public void HttpPostTest()
        {
            string s;
            bool   b = false;

            //测试用例1
            s = HttpHelper2.HttpPost((string)null, (string)null, out b);
            //测试用例2
            s = HttpHelper2.HttpPost((string)null, "", out b);
            //测试用例3
            s = HttpHelper2.HttpPost("", "", out b);
            //测试用例4
            s = HttpHelper2.HttpPost("Ā", "", out b);
            //测试用例5
            s = HttpHelper2.HttpPost(":", "", out b);
            //测试用例6
            s = HttpHelper2.HttpPost(" ", "", out b);
            //测试用例7
            s = HttpHelper2.HttpPost((string)null, "�ࠀ\0", out b);
            //测试用例8
            s = HttpHelper2.HttpPost("k|\0", "�ࠀ\0", out b);
            //测试用例9
            s = HttpHelper2.HttpPost(" €", "�ࠀ\0", out b);
            //测试用例10
            s = HttpHelper2.HttpPost("€|\0", "�ࠀ\0", out b);
            //测试用例11
            s = HttpHelper2.HttpPost("///", "�ࠀ\0", out b);
            //测试用例12
            s = HttpHelper2.HttpPost("€\0\0", "�ࠀ\0", out b);
            //测试用例13
            s = HttpHelper2.HttpPost("/\\/", "�ࠀ\0", out b);
            //测试用例14
            s = HttpHelper2.HttpPost("/\\\\", "�ࠀ\0", out b);
            //测试用例15
            s = HttpHelper2.HttpPost("P|\\", "�ࠀ\0", out b);
            //测试用例16
            s = HttpHelper2.HttpPost("b|\\", "�ࠀ\0", out b);
            //测试用例17
            s = HttpHelper2.HttpPost(" \0\0\0\0\0", "", out b);
            //测试用例18
            s = HttpHelper2.HttpPost("x", "", out b);
            //测试用例19
            s = HttpHelper2.HttpPost("\0\0:", "�ࠀ\0", out b);
            //测试用例20
            s = HttpHelper2.HttpPost("a0: ", "�ࠀ\0", out b);
            //测试用例21
            s = HttpHelper2.HttpPost("b0:\r", "�ࠀ\0", out b);
            //测试用例22
            s = HttpHelper2.HttpPost("b0:\r", "�ࠀ\0", out b);
            //测试用例23
            s = HttpHelper2.HttpPost("r0:\r", "�ࠀ\0", out b);
            //测试用例24
            s = HttpHelper2.HttpPost("w1: ", "�ࠀ\0", out b);
        }
예제 #3
0
        public string SendTemplete(string access_token, string temid, string touser, string form_id, string page, object data)
        {
            var postUrl = string.Format("https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token={0}", access_token);
            var msgData = new
            {
                touser      = touser,
                template_id = temid,
                form_id     = form_id,
                page        = page,
                data        = data
            };
            JavaScriptSerializer js = new JavaScriptSerializer();

            var         j    = js.Serialize(msgData);
            HttpHelper2 http = new HttpHelper2();
            string      res  = GetDataByPost(postUrl, j);

            return(res);
        }
예제 #4
0
        public static CreateResponse GetTask(Train train, string date, SeatsType seat, List <Contact> selectContactList)
        {
            string seatType = "";

            switch (seat)
            {
            case SeatsType.商务座:
                seatType = "9";
                break;

            case SeatsType.特等座:
                seatType = "P";
                break;

            case SeatsType.一等座:
                seatType = "M";
                break;

            case SeatsType.二等座:
                seatType = "O";
                break;

            case SeatsType.高级软卧:
                seatType = "5";
                break;

            case SeatsType.软卧:
                seatType = "4";
                break;

            case SeatsType.硬卧:
                seatType = "3";
                break;

            case SeatsType.软座:
                seatType = "2";
                break;

            case SeatsType.硬座:
                seatType = "1";
                break;

            case SeatsType.无座:
                seatType = "1";
                break;
            }

            StringBuilder passengerTicketStr = new StringBuilder();
            StringBuilder oldPassengerStr    = new StringBuilder();

            foreach (Contact contact in selectContactList)
            {
                passengerTicketStr.AppendFormat("{0},0,1,{1},{2},{3},{4},N_", seatType, contact.Name, contact.IdTypeCode, contact.IdNo, contact.Mobile);
                oldPassengerStr.AppendFormat("{1},{2},{3},1_", seatType, contact.Name, contact.IdTypeCode, contact.IdNo, contact.Mobile);
            }


            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("secretStr", train.Id);
            dic.Add("train_date", date);
            dic.Add("tour_flag", "dc");
            dic.Add("purpose_codes", "ADULT");
            dic.Add("query_from_station_name", From.Name);
            dic.Add("query_to_station_name", To.Name);
            dic.Add("", "");
            dic.Add("cancel_flag", "2");
            dic.Add("bed_level_order_num", "000000000000000000000000000000");
            dic.Add("passengerTicketStr", passengerTicketStr.ToString().TrimEnd('_'));
            dic.Add("oldPassengerStr", oldPassengerStr.ToString());

            var codeResquest = new HttpHelper2().Post(GetTask_1_GetToken,
                                                      dic, Encoding.UTF8, Encoding.UTF8, Referer: "https://kyfw.12306.cn/otn/leftTicket/init", cookies: Cookies
                                                      , headers: new Dictionary <string, string>()
            {
                { "Origin", "https://kyfw.12306.cn" }
            });

            if (codeResquest == null)
            {
                return(new CreateResponse()
                {
                    IsCreate = false, Message = "Errorl"
                });
            }

            var serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic data = serializer.Deserialize <object>(codeResquest);

            if (data.status == null || !data.status || data.data == null || data.data.result == null)
            {
                try
                {
                    return(new CreateResponse()
                    {
                        IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误"
                    });
                }
                catch (Exception)
                {
                    return(new CreateResponse()
                    {
                        IsCreate = false, Message = data.errMsg ?? "未知错误"
                    });
                }
            }

            //Q6#BA6C4F23E49E84F96A07B8ECA37A9FF350DAD2E2F484AD96F61C2046#O007450669M0099501499019950025#1
            Token token = new Token();

            string[] tokens = data.data.result.Split('#');;

            token.Q          = tokens[0];
            token.LongToken  = tokens[1];
            token.ShortToken = tokens[2];


            dic.Clear();
            dic.Add("train_date",
                    (Convert.ToDateTime(date).ToString("ddd MMM dd yyy ", DateTimeFormatInfo.InvariantInfo) +
                     DateTime.Now.ToString("HH:mm:ss").Replace(":", "%3A") + " GMT%2B0800  (China Standard Time)").Replace(' ', '+'));
            dic.Add("train_no", train.TrainNo);
            dic.Add("stationTrainCode", train.StationTrainCode);
            dic.Add("seatType", seatType);
            dic.Add("fromStationTelecode", train.from_station_telecode);
            dic.Add("toStationTelecode", train.end_station_telecode);
            dic.Add("leftTicket", token.ShortToken);
            dic.Add("purpose_codes", "ADULT");
            dic.Add("_json_att", "");


            CookieCollection cookiesTemp = new CookieCollection();

            cookiesTemp.Add(Cookies);

            cookiesTemp.Add(new Cookie("_jc_save_fromStation", escape(From.Name) + "%2C" + From.Code, "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_toStation", escape(To.Name) + "%2C" + To.Code, "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_fromDate", date, "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_toDate", Convert.ToDateTime(date).AddDays(15).ToString("yyyy-MM-dd"), "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_wfdc_flag", "dc", "/otn")
            {
                Domain = "kyfw.12306.cn"
            });

            codeResquest = new HttpHelper2().Post(GetTask_2_GetQueueCount,
                                                  dic, Encoding.UTF8, Encoding.UTF8, cookies: cookiesTemp,
                                                  Referer: "https://kyfw.12306.cn/otn/leftTicket/init"
                                                  ,
                                                  headers:
                                                  new Dictionary <string, string>()
            {
                { "Origin", "https://kyfw.12306.cn" },
                { "X-Requested-With", "XMLHttpRequest" }
            });

            serializer = new JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            data = serializer.Deserialize <object>(codeResquest);

            if (data.status == null || !data.status || data.data == null || data.data.ticket == null)
            {
                return(new CreateResponse()
                {
                    IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误"
                });
            }

            token.ticket = data.data.ticket;
            string Code = "";

            try
            {
                do
                {
                    var response = HttpHelper.CreateGetHttpResponse(GetTask_3_Image + new Random().NextDouble().ToString(),
                                                                    null, "https://kyfw.12306.cn/otn/leftTicket/init", Cookies);
                    Stream resStream = response.GetResponseStream(); //得到验证码数据流
                    Bitmap bmp       = new Bitmap(resStream);        //初始化Bitmap图片
                    new Music(2).Play();
                    ImageFrom.GetImageFrom.Show(bmp);
                    Code = ImageFrom.GetImageFrom.Code;
                } while (Code.Length != 4 && Program.mainForm.GetRunStatus());
            }
            catch (Exception)
            {
                return(new CreateResponse()
                {
                    IsCreate = false, Message = data.data.errMsg ?? "未知错误"
                });
            }

            //dic.Clear();
            //dic.Add("randCode", Code);
            //dic.Add("rand", "sjrand");
            //dic.Add("_json_att", "");

            //codeResquest = new HttpHelper2().Post("https://kyfw.12306.cn/otn/passcodeNew/checkRandCodeAnsyn",
            //  dic, Encoding.UTF8, Encoding.UTF8, Referer: "https://kyfw.12306.cn/otn/leftTicket/init", cookies: cookiesTemp
            //  , headers:
            //      new Dictionary<string, string>()
            //        {
            //            {"Origin", "https://kyfw.12306.cn"},
            //            {"X-Requested-With", "XMLHttpRequest"}
            //        });



            dic.Clear();
            dic.Add("passengerTicketStr", System.Web.HttpUtility.UrlEncode((passengerTicketStr.ToString().TrimEnd('_'))).ToUpper());
            dic.Add("oldPassengerStr", System.Web.HttpUtility.UrlEncode(oldPassengerStr.ToString()).ToUpper());
            dic.Add("randCode", Code);
            dic.Add("purpose_codes", "ADULT");
            dic.Add("key_check_isChange", token.LongToken);
            dic.Add("leftTicketStr", token.ShortToken);
            dic.Add("train_location", token.Q);
            dic.Add("_json_att", "");

            cookiesTemp = new CookieCollection();

            cookiesTemp.Add(Cookies);

            cookiesTemp.Add(new Cookie("_jc_save_fromStation", escape(From.Name) + "%2C" + From.Code, "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_toStation", escape(To.Name) + "%2C" + To.Code, "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_fromDate", date, "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_toDate", Convert.ToDateTime(date).AddDays(15).ToString("yyyy-MM-dd"), "/otn")
            {
                Domain = "kyfw.12306.cn"
            });
            cookiesTemp.Add(new Cookie("_jc_save_wfdc_flag", "dc", "/otn")
            {
                Domain = "kyfw.12306.cn"
            });

            codeResquest = new HttpHelper2().Post(GetTask_4_SubmitStatus,
                                                  dic, Encoding.UTF8, Encoding.UTF8, Referer: "https://kyfw.12306.cn/otn/leftTicket/init", cookies: cookiesTemp
                                                  , headers:
                                                  new Dictionary <string, string>()
            {
                { "Origin", "https://kyfw.12306.cn" },
                { "X-Requested-With", "XMLHttpRequest" }
            });


            if (codeResquest == null)
            {
                return(new CreateResponse()
                {
                    IsCreate = false, Message = "Errorl"
                });
            }

            serializer = new JavaScriptSerializer();
            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            data = serializer.Deserialize <object>(codeResquest);

            if (data.status == null || !data.status || data.data == null || data.data.submitStatus == null)
            {
                try
                {
                    return(new CreateResponse()
                    {
                        IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误"
                    });
                }
                catch (Exception)
                {
                    return(new CreateResponse()
                    {
                        IsCreate = false, Message = data.data.errMsg ?? "未知错误"
                    });
                }
            }
            else if (data.data != null && data.data.submitStatus != null)
            {
                if (data.data.submitStatus)
                {
                    TickCute.ChangeTickCount(-1);
                    new Music(1).Play();
                    Program.mainForm.SetLinkLabelText("订票成功!登录12306查看!<-");
                    return(new CreateResponse()
                    {
                        IsCreate = true, Message = "订票成功!"
                    });
                }
                else
                {
                    return(new CreateResponse()
                    {
                        IsCreate = false, Message = "订票失败!"
                    });
                }
            }


            return(new CreateResponse()
            {
                IsCreate = false, Message = data.messages != null ? data.messages[0] ?? "未知错误" : "未知错误"
            });
            //else if (data.messages.Count <=0)
            //{
            //    return new LoginResponse() { IsLogined = true, Message = "", type = ErrorType.None, LoginName = userName };

            //}
        }
예제 #5
0
        /// <summary>
        /// 获取车次信息
        /// </summary>
        /// <param name="date"></param>
        /// <param name="fromstation"></param>
        /// <param name="tostation"></param>
        /// <param name="timeout"></param>
        /// <param name="userAgent"></param>
        /// <param name="cookie"></param>
        /// <returns></returns>
        public static List <Train> GetTrains(string date, string fromstation, string tostation,
                                             int?timeout = null, string userAgent = null, CookieCollection cookie = null)
        {
            List <Train> list = new List <Train>();
            string       str  = "";

            try
            {
                str = new HttpHelper2().Get(string.Format(UrlGetTrains, date, fromstation, tostation), Encoding.UTF8
                                            , timeout, userAgent, cookie ?? Cookies, "https://kyfw.12306.cn/otn/leftTicket/init"
                                            , new Dictionary <string, string>()
                {
                    { "X-Requested-With", "XMLHttpRequest" }
                });
            }
            catch (Exception)
            {
                return(new List <Train>());
            }
            if (!string.IsNullOrEmpty(str))
            {
                var serializer = new JavaScriptSerializer();
                serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
                try
                {
                    dynamic data = serializer.Deserialize <object>(str);
                    if (data.data != null)
                    {
                        foreach (dynamic o in data.data)
                        {
                            list.Add(new Train()
                            {
                                Id                    = o.secretStr,
                                EndStation            = o.queryLeftNewDTO.to_station_name,
                                EndTime               = o.queryLeftNewDTO.arrive_time,
                                StartStation          = o.queryLeftNewDTO.start_station_name,
                                StartTime             = o.queryLeftNewDTO.start_time,
                                TrainValue            = o.queryLeftNewDTO.station_train_code,
                                StationTrainCode      = o.queryLeftNewDTO.station_train_code,
                                TrainNo               = o.queryLeftNewDTO.train_no,
                                end_station_telecode  = o.queryLeftNewDTO.end_station_telecode,
                                from_station_telecode = o.queryLeftNewDTO.from_station_telecode,
                                SWZ                   = o.queryLeftNewDTO.swz_num,
                                TZ                    = o.queryLeftNewDTO.tz_num,
                                ZY                    = o.queryLeftNewDTO.zy_num,
                                ZE                    = o.queryLeftNewDTO.ze_num,
                                GR                    = o.queryLeftNewDTO.gr_num,
                                RW                    = o.queryLeftNewDTO.rw_num,
                                RZ                    = o.queryLeftNewDTO.rz_num,
                                YW                    = o.queryLeftNewDTO.yw_num,
                                YZ                    = o.queryLeftNewDTO.yz_num,
                                WZ                    = o.queryLeftNewDTO.wz_num,
                                QT                    = o.queryLeftNewDTO.qt_num
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    return(new List <Train>());
                }
            }
            return(list);
        }
예제 #6
0
        public void HttpGetTest()
        {
            string s;
            bool   b = false;

            //测试用例1
            s = HttpHelper2.HttpGet((string)null, (string)null, out b);
            //测试用例2
            s = HttpHelper2.HttpGet((string)null, "", out b);
            //测试用例3
            s = HttpHelper2.HttpGet((string)null, "Ā", out b);
            //测试用例4
            s = HttpHelper2.HttpGet("", (string)null, out b);
            //测试用例5
            s = HttpHelper2.HttpGet("", "", out b);
            //测试用例6
            s = HttpHelper2.HttpGet((string)null, ":", out b);
            //测试用例7
            s = HttpHelper2.HttpGet((string)null, "%", out b);
            //测试用例8
            s = HttpHelper2.HttpGet(":\0\0", (string)null, out b);
            //测试用例9
            s = HttpHelper2.HttpGet((string)null, "x", out b);
            //测试用例10
            s = HttpHelper2.HttpGet(" ", (string)null, out b);
            //测试用例11
            s = HttpHelper2.HttpGet("P|\0", (string)null, out b);
            //测试用例12
            s = HttpHelper2.HttpGet("P|\0", (string)null, out b);
            //测试用例13
            s = HttpHelper2.HttpGet("/\\\\", (string)null, out b);
            //测试用例14
            s = HttpHelper2.HttpGet("%\0\0\0\0\0", (string)null, out b);
            //测试用例15
            s = HttpHelper2.HttpGet("%%\0\0\0\0", (string)null, out b);
            //测试用例16
            s = HttpHelper2.HttpGet("%A\0\0\0\0", (string)null, out b);
            //测试用例17
            s = HttpHelper2.HttpGet("%AD\0\0\0", (string)null, out b);
            //测试用例18
            s = HttpHelper2.HttpGet("%0D\0\0\0", (string)null, out b);
            //测试用例19
            s = HttpHelper2.HttpGet("%2d\0\0\0", (string)null, out b);
            //测试用例20
            s = HttpHelper2.HttpGet("%73\0\0\0", (string)null, out b);
            //测试用例21
            s = HttpHelper2.HttpGet("%31\0\0\0", (string)null, out b);
            //测试用例22
            s = HttpHelper2.HttpGet("\\\\/", (string)null, out b);
            //测试用例23
            s = HttpHelper2.HttpGet("\0\0:", (string)null, out b);
            //测试用例24
            s = HttpHelper2.HttpGet("xn: ", (string)null, out b);
            //测试用例25
            s = HttpHelper2.HttpGet("/\0::", (string)null, out b);
            //测试用例26
            s = HttpHelper2.HttpGet("x0::", (string)null, out b);
            //测试用例27
            s = HttpHelper2.HttpGet("x0:<", (string)null, out b);
            //测试用例28
            s = HttpHelper2.HttpGet("x0:?", (string)null, out b);
            //测试用例29
            s = HttpHelper2.HttpGet("x0:#", (string)null, out b);
            //测试用例30
            s = HttpHelper2.HttpGet("x0:^", (string)null, out b);
            //测试用例31
            s = HttpHelper2.HttpGet("x0:.", (string)null, out b);
            //测试用例32
            s = HttpHelper2.HttpGet("x0:\"", (string)null, out b);
            //测试用例33
            s = HttpHelper2.HttpGet("x0:/", (string)null, out b);
            //测试用例34
            s = HttpHelper2.HttpGet("x0:\0", (string)null, out b);
            //测试用例35
            s = HttpHelper2.HttpGet("x0:!", (string)null, out b);
            //测试用例36
            s = HttpHelper2.HttpGet("x0:_", (string)null, out b);
            //测试用例37
            s = HttpHelper2.HttpGet("x1:\0", (string)null, out b);
            //测试用例38
            s = HttpHelper2.HttpGet("x0:>", (string)null, out b);
            //测试用例39
            s = HttpHelper2.HttpGet("x0:\\", (string)null, out b);
            //测试用例40
            s = HttpHelper2.HttpGet("x0:{", (string)null, out b);
            //测试用例41
            s = HttpHelper2.HttpGet("x0:~", (string)null, out b);
            //测试用例42
            s = HttpHelper2.HttpGet("x0:[", (string)null, out b);
            //测试用例43
            s = HttpHelper2.HttpGet("x0:", (string)null, out b);
        }