Example #1
0
        bool CheckValidateCode()
        {
            //获取选中图片坐标
            foreach (Control c in picValidate.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    answer += (c.Location.X + 25).ToString() + "," + (c.Location.Y + 25).ToString() + ",";
                }
            }
            string json = _requestHelper.GetData("get", Api12306.getCaptchaCheck() + "&answer=" + answer);

            if (json != null && Common.IsJson(json))
            {
                if (JObject.Parse(json)["result_code"].ToString() == "4")
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show(JObject.Parse(json)["result_message"].ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GetValidateCode();
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("网络异常!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                GetValidateCode();
                return(false);
            }
        }
Example #2
0
        void GetValidateCode()
        {
            //清空选中图片
            foreach (Control c in picValidate.Controls)
            {
                if (c.Controls.Count > 0)
                {
                    c.Controls.Clear();
                }
            }
            answer = "";
            string json = _requestHelper.GetData("get", Api12306.getCaptcha());

            if (json != null && Common.IsJson(json))
            {
                var obj = JObject.Parse(json);
                if (obj["result_code"].ToString() == "0")
                {
                    picValidate.Image = Image.FromStream(GetImageFromBase64(obj["image"].ToString()));
                }
                else
                {
                    MessageBox.Show(obj["result_message"].ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GetValidateCode();
                }
            }
            else
            {
                MessageBox.Show("加载验证码失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                GetValidateCode();
            }
        }
Example #3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUserName.Text.Trim();
            string password = txtPassword.Text.Trim();

            if (username == "")
            {
                MessageBox.Show("账号不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            if (password == "")
            {
                MessageBox.Show("密码不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //if (answer == "")
            //{
            //    MessageBox.Show("验证码不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //    return;
            //}

            if (!CheckValidateCode())
            {
                return;
            }

            string json = _requestHelper.GetData("post", Api12306.passport_login, $"username={username}&password={password }&appid=otn&answer={answer}");

            if (json != null && Common.IsJson(json))
            {
                if (Convert.ToInt32(JObject.Parse(json)["result_code"]) == 0)
                {
                    json = _requestHelper.GetData("post", Api12306.passport_authuam, "appid=otn");

                    if (Convert.ToInt32(JObject.Parse(json)["result_code"]) == 0)
                    {
                        json = _requestHelper.GetData("post", Api12306.getAuthclient(), "tk=" + JObject.Parse(json)["newapptk"]);
                        if (Convert.ToInt32(JObject.Parse(json)["result_code"]) == 0)
                        {
                            this.Hide();
                            FrmMain main = new FrmMain();
                            main.Show();
                        }
                    }
                }
                lblError.Text = JObject.Parse(json)["result_message"].ToString();
                GetValidateCode();
            }
            else
            {
                MessageBox.Show("登录失败!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                GetValidateCode();
            }
        }
Example #4
0
        bool CheckValidateCode()
        {
            string json = _requestHelper.GetData("get", Api12306.getCaptchaCheck() + "&answer=" + answer);

            if (json != null && Common.IsJson(json))
            {
                if (JObject.Parse(json)["result_code"].ToString() == "4")
                {
                    return(true);
                }
                else
                {
                    MessageBox.Show(JObject.Parse(json)["result_message"].ToString(), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    GetValidateCode();
                    return(false);
                }
            }
            else
            {
                MessageBox.Show("网络异常!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                GetValidateCode();
                return(false);
            }
        }
Example #5
0
        //查询
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string train_date   = trainDate.Value.ToString("yyyy-MM-dd");
            string from_station = cmbFromStation.SelectedValue.ToString();

            if (from_station == "")
            {
                MessageBox.Show("出发站不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string to_station = cmbToStation.SelectedValue.ToString();

            if (to_station == "")
            {
                MessageBox.Show("目的站不能为空!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string purpose_codes = "ADULT";

            if (radStudent.Checked)
            {
                purpose_codes = "0X00";
            }

            string url = Api12306.getQuery() + $"?leftTicketDTO.train_date={ train_date }&leftTicketDTO.from_station={from_station }&leftTicketDTO.to_station={to_station }&purpose_codes={ purpose_codes}";

            string json = _requestHelper.GetData("get", url);

            if (json == null || !Common.IsJson(json))
            {
                txtMessage.AppendText("查询车票失败,网络异常!\r\n");
                return;
            }
            else
            {
                JObject obj = JObject.Parse(json);


                if (bool.Parse(obj["status"].ToString()))
                {
                    List <string> listResult = JsonConvert.DeserializeObject <List <string> >(obj["data"]["result"].ToString());
                    if (listResult != null && listResult.Count > 0)
                    {
                        List <dynamic> searchResult = new List <dynamic>();
                        foreach (var item in listResult)
                        {
                            var arr = item.Split('|');
                            if (chbG.Checked)
                            {
                                if (arr[3].IndexOf("G") == -1 && arr[3].IndexOf("D") == -1)
                                {
                                    continue;
                                }
                            }


                            searchResult.Add(new
                            {
                                train_name          = arr[3], // 车次
                                from_station        = arr[6], //始发、终点站
                                from_station_name   = searchStationName(arr[6]),
                                to_station          = arr[7],
                                to_station_name     = searchStationName(arr[7]),
                                from_time           = arr[8],  //出发时间、到达时间
                                to_time             = arr[9],
                                total_time          = arr[10], //历时
                                business_seat       = arr[32], //商务座
                                first_class_seat    = arr[31], //一等座
                                second_class_seat   = arr[30], //二等座
                                senior_soft_sleeper = arr[21], //高级软卧
                                soft_sleeper        = arr[23], //软卧
                                move_sleeper        = arr[33], //动卧
                                hard_sleeper        = arr[28], //硬卧
                                soft_seat           = arr[24], //软座
                                hard_seat           = arr[29], //硬座
                                no_seat             = arr[26], //无座
                                other = arr[22],               //其他

                                mark = arr[1],                 //备注


                                train_no        = arr[2],  //列车编号
                                seat_type       = arr[35], //座位类型
                                from_station_no = arr[16], //当前站的编号
                                to_station_no   = arr[17], //终点站的编号
                                secretStr       = arr[0]
                            });
                        }
                        dgvResult.DataSource = searchResult;
                        dgvResult.AllowUserToOrderColumns = true;


                        chkTrainNo.DataSource    = searchResult;
                        chkTrainNo.ValueMember   = "train_no";
                        chkTrainNo.DisplayMember = "train_name";



                        dgvResult.Columns["train_name"].HeaderText          = "车次";
                        dgvResult.Columns["train_name"].ToolTipText         = "双击查看价格";
                        dgvResult.Columns["from_station_name"].HeaderText   = "始发站";
                        dgvResult.Columns["from_station_name"].ToolTipText  = "双击查看停靠站";
                        dgvResult.Columns["to_station_name"].HeaderText     = "终点站";
                        dgvResult.Columns["from_time"].HeaderText           = "出发时间";
                        dgvResult.Columns["to_time"].HeaderText             = "到达时间";
                        dgvResult.Columns["total_time"].HeaderText          = "历时";
                        dgvResult.Columns["business_seat"].HeaderText       = "商务座";
                        dgvResult.Columns["first_class_seat"].HeaderText    = "一等座";
                        dgvResult.Columns["second_class_seat"].HeaderText   = "二等座";
                        dgvResult.Columns["senior_soft_sleeper"].HeaderText = "高级软卧";
                        dgvResult.Columns["soft_sleeper"].HeaderText        = "软卧";
                        dgvResult.Columns["move_sleeper"].HeaderText        = "动卧";
                        dgvResult.Columns["hard_sleeper"].HeaderText        = "硬卧";
                        dgvResult.Columns["soft_seat"].HeaderText           = "软座";
                        dgvResult.Columns["hard_seat"].HeaderText           = "硬座";
                        dgvResult.Columns["no_seat"].HeaderText             = "无座";
                        dgvResult.Columns["other"].HeaderText = "其他";
                        dgvResult.Columns["mark"].HeaderText  = "备注";


                        dgvResult.Columns["from_station"].Visible    = false;
                        dgvResult.Columns["to_station"].Visible      = false;
                        dgvResult.Columns["train_no"].Visible        = false;
                        dgvResult.Columns["seat_type"].Visible       = false;
                        dgvResult.Columns["from_station_no"].Visible = false;
                        dgvResult.Columns["to_station_no"].Visible   = false;
                        dgvResult.Columns["secretStr"].Visible       = false;

                        dgvResult.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                    }
                }
                else
                {
                    txtMessage.AppendText("查询车票失败," + obj["message"].ToString() + "!\r\n");
                }
            }
        }