在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#网络编程 → C# 全国车辆违章查询 实例源码下载

C# 全国车辆违章查询 实例源码下载

C#网络编程

下载此实例
  • 开发语言:C#
  • 实例大小:5.90M
  • 下载次数:72
  • 浏览次数:831
  • 发布时间:2017-01-19
  • 实例类别:C#网络编程
  • 发 布 人:吉娃娃
  • 文件格式:.rar
  • 所需积分:4
 相关标签: 查询

实例介绍

【实例简介】

【实例截图】

【核心代码】

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using 全国违章车辆查询.ToosClass;
using 全国违章车辆查询.EntiyClass;
using System.Threading;
using System.Net;
using System.IO;

namespace 全国违章车辆查询
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
        }
        DateTime startTime;
        long timeStamp;
        HttpHelper httphelper = null;
        HttpItem item1 = null;
        HttpItem item2 = null;
        HttpItem item3 = null;
        bool isFist = true;
        private void Form1_Load(object sender, EventArgs e)
        {
            #region 绑定省市
            List<ProvinceInfo> prinfo = new List<ProvinceInfo>()
            {
              new ProvinceInfo {cityName="北京市",cityValue="bj" },new ProvinceInfo {cityName="天津市",cityValue="tj" },
              new ProvinceInfo {cityName="重庆市",cityValue="cq" },new ProvinceInfo {cityName="上海市",cityValue="sh" },
              new ProvinceInfo {cityName="河北省",cityValue="he" },new ProvinceInfo {cityName="海南省",cityValue="hi" },
              new ProvinceInfo {cityName="山西省",cityValue="sx" },new ProvinceInfo {cityName="四川省",cityValue="sc" },
              new ProvinceInfo {cityName="辽宁省",cityValue="ln" },new ProvinceInfo {cityName="贵州省",cityValue="gz" },
              new ProvinceInfo {cityName="吉林省",cityValue="jl" },new ProvinceInfo {cityName="云南省",cityValue="yn" },
              new ProvinceInfo {cityName="黑龙江省",cityValue="hl"},new ProvinceInfo {cityName="陕西省",cityValue="sn" },
              new ProvinceInfo {cityName="江苏省",cityValue="" },new ProvinceInfo {cityName="甘肃省",cityValue="gs" },
              new ProvinceInfo {cityName="浙江省",cityValue="" },new ProvinceInfo {cityName="青海省",cityValue="qh" },
              new ProvinceInfo {cityName="安徽省",cityValue="ah" },new ProvinceInfo {cityName="台湾省",cityValue="" },
              new ProvinceInfo {cityName="福建省",cityValue="fj" },new ProvinceInfo {cityName="内蒙古自治区",cityValue="nm" },
              new ProvinceInfo {cityName="江西省",cityValue="jx" },new ProvinceInfo {cityName="广西壮族自治区",cityValue="gx" },
              new ProvinceInfo {cityName="山东省",cityValue="sd" },new ProvinceInfo {cityName="宁夏回族自治区",cityValue="nx" },
              new ProvinceInfo {cityName="河南省",cityValue="ha"},new ProvinceInfo {cityName="新疆维吾尔自治区",cityValue="xj" },
              new ProvinceInfo {cityName="湖北省",cityValue="hb" },new ProvinceInfo {cityName="西藏自治区",cityValue="xz" },
              new ProvinceInfo {cityName="湖南省",cityValue="hn" },new ProvinceInfo {cityName="香港特别行政区",cityValue="" },
              new ProvinceInfo {cityName="广东省",cityValue="gd" },new ProvinceInfo {cityName="澳门特别行政区",cityValue="" },
            };
            cboProvice.DataSource = prinfo;
            cboProvice.DisplayMember = "cityname";
            cboProvice.ValueMember = "cityValue";
            #endregion
            #region 绑定车辆类型
            List<PlateType> plate = new List<PlateType>()
            {
             new PlateType {PlateName="大型汽车",PlateValue="01"},new PlateType {PlateName="小型汽车",PlateValue="02" },
             new PlateType {PlateName="使馆汽车",PlateValue="03"},new PlateType {PlateName="领馆汽车",PlateValue="04" },
             new PlateType {PlateName="境外汽车",PlateValue="05"},new PlateType {PlateName="外籍汽车",PlateValue="06" },
             new PlateType {PlateName="普通摩托车",PlateValue="07"},new PlateType {PlateName="轻便摩托车",PlateValue="08" },
             new PlateType {PlateName="使馆摩托车",PlateValue="09"},new PlateType {PlateName="领馆摩托车",PlateValue="10" },
             new PlateType {PlateName="境外摩托车",PlateValue="11"},new PlateType {PlateName="外籍摩托车",PlateValue="12" },
             new PlateType {PlateName="低速车",PlateValue="13"},new PlateType {PlateName="拖拉机",PlateValue="14" },
             new PlateType {PlateName="挂车",PlateValue="15"},new PlateType {PlateName="教练汽车",PlateValue="16" },
             new PlateType {PlateName="教练摩托车",PlateValue="17"},new PlateType {PlateName="实验汽车",PlateValue="18" },
             new PlateType {PlateName="实验摩托车",PlateValue="19"},new PlateType {PlateName="临时入境汽车",PlateValue="20" },
             new PlateType {PlateName="临时入境摩托车",PlateValue="21"},new PlateType {PlateName="临时行驶车",PlateValue="22" },
             new PlateType {PlateName="警用汽车",PlateValue="23"},new PlateType {PlateName="警用摩托",PlateValue="24" },
             new PlateType {PlateName="原农机号码",PlateValue="25"},new PlateType {PlateName="香港入境车",PlateValue="26" },
             new PlateType {PlateName="澳门入境车",PlateValue="27"}
            };
            cboType.DataSource = plate;
            cboType.DisplayMember = "PlateName";
            cboType.ValueMember = "PlateValue";
            richTextBox1.AppendText("绑定数据完成..."   "\r\n");
            #endregion
            richTextBox1.AppendText("窗口加载完成..." "\r\n");
            richTextBox1.AppendText("等待用户输入数据..."   "\r\n");
        }
        private void txtCaptcha_Enter(object sender, EventArgs e)
        {
            if (!txtCarnum.Text.Equals("")&&!txtFadongji.Text.Equals(""))
            {
                if (isFist)
                {
                    richTextBox1.AppendText("正在抓取网页验证码....."   "\r\n");
                    GetVerificationCode();
                    isFist = false;
                }
            }
            else
            {
                MessageBox.Show("请查看数据是否填写完整!");
            }
        }
        /// <summary>
        /// 获取网页验证码
        /// </summary>
        private void GetVerificationCode()
        {
            startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            timeStamp = (long)(DateTime.Now - startTime).TotalMilliseconds; // 相差毫秒数
            if (cboProvice.Text.Equals("浙江省") || cboProvice.Text.Equals("江苏省"))
            {
                #region 根据浙江,江苏的城市获取验证码
                try
                {
                    httphelper = new HttpHelper();
                    item1 = new HttpItem()
                    {
                        URL = "http://"   cboCity.SelectedValue   ".122.gov.cn/views/inquiry.html",
                        Method = "get",
                    };
                    HttpResult res = httphelper.GetHtml(item1);
                    string cookie = res.Cookie;
                    item2 = new HttpItem()
                    {
                        URL = "http://"   cboCity.SelectedValue   ".122.gov.cn/captcha?nocache="   timeStamp,
                        Cookie = cookie,
                        Method = "get",
                        ResultType = ResultType.Byte
                    };
                }
                catch (Exception)
                {
                    MessageBox.Show("打开网页失败,请查看网络连接");
                }
                HttpResult res1 = httphelper.GetHtml(item1);
                HttpResult res2 = httphelper.GetHtml(item2);
                MemoryStream ms = new MemoryStream(res2.ResultByte);//获取验证码图片
                Image image = Image.FromStream(ms);
                this.pictureBox1.Image = image;
                ms.Close();
                richTextBox1.AppendText("抓取验证码成功....."   "\r\n");
                #endregion
                
            }
            else
            {
                #region 根据省份获取验证码
                try
                {
                    httphelper = new HttpHelper();
                    item1 = new HttpItem()
                    {
                        URL = "http://"   cboProvice.SelectedValue   ".122.gov.cn/views/inquiry.html",
                        Method = "get",
                    };
                    HttpResult res = httphelper.GetHtml(item1);
                    string cookie = res.Cookie;
                    item2 = new HttpItem()
                    {
                        URL = "http://"   cboProvice.SelectedValue   ".122.gov.cn/captcha?nocache="   timeStamp,
                        Cookie = cookie,
                        Method = "get",
                        ResultType = ResultType.Byte
                    };
                }
                catch (Exception)
                {
                    MessageBox.Show("打开网页失败,请查看网络连接");
                }
                HttpResult res1 = httphelper.GetHtml(item1);
                HttpResult res2 = httphelper.GetHtml(item2);
                MemoryStream ms = new MemoryStream(res2.ResultByte);//获取验证码图片
                Image image = Image.FromStream(ms);
                this.pictureBox1.Image = image;
                ms.Close();
                richTextBox1.AppendText("抓取验证码成功....."   "\r\n");
                #endregion
            }
        }
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSeach_Click(object sender, EventArgs e)
        {
           richTextBox1.AppendText("正在准备提交参数..."   "\r\n");
            string carIdnum = txtCarnum.Text.Trim();//车牌号码
            string hpzl = cboType.SelectedValue.ToString();//号牌类型
            string carid = cboCarnum.Text   carIdnum;//详细车牌号
            string caridStr = TransferEncoding(Encoding.UTF8, Encoding.Default, carid);
            string fdjh = txtFadongji.Text.Trim();//发动机号
            string captcar = txtCaptcha.Text.Trim();//验证码
            richTextBox1.AppendText("正在查询..." "\r\n");
            if (CheckIsNull())
            {
                try
                {
                    #region 浙江和江苏按照城市查询的
                    if (cboProvice.Text.Equals("浙江省") || cboProvice.Text.Equals("江苏省"))
                    {
                        httphelper = new HttpHelper();
                        item3 = new HttpItem()
                        {
                            URL = "http://"   cboCity.SelectedValue   ".122.gov.cn/m/publicquery/vio",
                            Method = "post",
                            UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0",
                            Accept = "application/json, text/javascript, */*; q=0.01",
                            Host = "ha.122.gov.cn",
                            Cookie = item2.Cookie,
                            Referer = "http://"   cboCity.SelectedValue   ".122.gov.cn/views/inquiry.html",
                            ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                            Postdata = "hpzl="   hpzl   "&hphm1b="   carIdnum   "&hphm="   caridStr   "&fdjh="   fdjh   "&captcha="   captcar   "&qm=wf&page=1"
                        };
                        HttpResult res3 = httphelper.GetHtml(item3);
                        string resultStr1 = res3.Html;
                        var submitinfo1 = JsonHelper.JsonDeserialize<SubmitInfo>(resultStr1);
                        rtbInfo.BodyInnerHTML = submitinfo1.message  "<br/><br/>";
                        richTextBox1.AppendText("查询完成..."   "\r\n");
                    }
                    #endregion
                    #region 按照省份查的
                    else
                    {
                        item3 = new HttpItem()
                        {
                            URL = "http://"   cboProvice.SelectedValue   ".122.gov.cn/m/publicquery/vio",
                            Method = "post",
                            UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0",
                            Accept = "application/json, text/javascript, */*; q=0.01",
                            Host = "ha.122.gov.cn",
                            Cookie = item2.Cookie,
                            Referer = "http://"   cboProvice.SelectedValue   ".122.gov.cn/views/inquiry.html",
                            ContentType = "application/x-www-form-urlencoded; charset=UTF-8",
                            Postdata = "hpzl="   hpzl   "&hphm1b="   carIdnum   "&hphm="   caridStr   "&fdjh="   fdjh   "&captcha="   captcar   "&qm=wf&page=1"
                        };
                        HttpResult res3 = httphelper.GetHtml(item3);
                        string resultStr = res3.Html;
                        var submitinfo = JsonHelper.JsonDeserialize<SubmitInfo>(resultStr);
                        rtbInfo.BodyInnerHTML = submitinfo.message;
                        richTextBox1.AppendText("查询完成..."   "\r\n");
                    }    
                    #endregion
                }
                catch (Exception)
                {
                    MessageBox.Show("网络连接错误,请查看网络连接!");
                }
            }
        }
        private void cboProvice_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboProvice.Text.Equals("台湾省") || cboProvice.Text.Equals("香港特别行政区") || cboProvice.Text.Equals("澳门特别行政区"))
            {
                MessageBox.Show("该省份还没有开通该服务!");
            }
            #region 绑定省对应的城市
            else if (cboProvice.Text == "江苏省")
            {
                List<CityInfo> cityinfo = new List<CityInfo>() {
                new CityInfo {CityName="徐州市",CityValue="xuz" },new CityInfo {CityName="连云港市",CityValue="lyg"},
                new CityInfo {CityName="宿迁市",CityValue="suq" },new CityInfo {CityName="淮安市",CityValue="has" },
                new CityInfo {CityName="盐城市",CityValue="ynz"},new CityInfo {CityName="扬州市",CityValue="yzo"},
                new CityInfo {CityName="泰州市",CityValue="tzs" },new CityInfo {CityName="南京市",CityValue="nkg" },
                new CityInfo {CityName="镇江市",CityValue="zhe" },new CityInfo {CityName="南通市",CityValue="ntg" },
                new CityInfo {CityName="常州市",CityValue="czx" },new CityInfo {CityName="无锡市",CityValue="wux"},
                new CityInfo {CityName="苏州市",CityValue="szv" },
                };
                cboCity.DataSource = cityinfo;
                cboCity.DisplayMember = "CityName";
                cboCity.ValueMember = "CityValue";
            }
            else if (cboProvice.Text == "浙江省")
            {
                List<CityInfo> cityinfo = new List<CityInfo>() {
                new CityInfo {CityName="湖州市",CityValue="hzh" },new CityInfo {CityValue="jix",CityName="嘉兴市"},
                new CityInfo {CityName="舟山市",CityValue="zos" },new CityInfo {CityName="绍兴市",CityValue="sxg" },
                new CityInfo {CityName="宁波市",CityValue="ngb"},new CityInfo {CityName="衢州市",CityValue="quz"},
                new CityInfo {CityName="金华市",CityValue="jha" },new CityInfo {CityName="台州市",CityValue="tzz" },
                new CityInfo {CityName="丽水市",CityValue="lss" },new CityInfo {CityName="温州市",CityValue="wnz" },
                new CityInfo {CityName="杭州市",CityValue="hgh" },
                };
                cboCity.DataSource = cityinfo;
                cboCity.DisplayMember = "CityName";
                cboCity.ValueMember = "CityValue";

            }
            #endregion
            #region 根据省份绑定简称

            switch (cboProvice.Text)
            {
                case "北京市":
                    cboCarnum.Text = "京";
                    break;
                case "上海市":
                    cboCarnum.Text = "沪";
                    break;
                case "广东省":
                    cboCarnum.Text = "粤";
                    break;
                case "山东省":
                    cboCarnum.Text = "鲁";
                    break;
                case "山西省":
                    cboCarnum.Text = "晋";
                    break;
                case "河北省":
                    cboCarnum.Text = "冀";
                    break;
                case "河南省":
                    cboCarnum.Text = "豫";
                    break;
                case "四川省":
                    cboCarnum.Text = "川";
                    break;
                case "重庆市":
                    cboCarnum.Text = "渝";
                    break;
                case "辽宁省":
                    cboCarnum.Text = "辽";
                    break;
                case "吉林省":
                    cboCarnum.Text = "吉";
                    break;
                case "黑龙江省":
                    cboCarnum.Text = "黑";
                    break;
                case "湖北省":
                    cboCarnum.Text = "鄂";
                    break;
                case "湖南省":
                    cboCarnum.Text = "湘";
                    break;
                case "江西省":
                    cboCarnum.Text = "赣";
                    break;
                case "福建省":
                    cboCarnum.Text = "闽";
                    break;
                case "陕西省":
                    cboCarnum.Text = "陕";
                    break;
                case "甘肃省":
                    cboCarnum.Text = "甘";
                    break;
                case "宁夏回族自治区":
                    cboCarnum.Text = "宁";
                    break;
                case "内蒙古自治区":
                    cboCarnum.Text = "蒙";
                    break;
                case "天津市":
                    cboCarnum.Text = "津";
                    break;
                case "贵州省":
                    cboCarnum.Text = "贵";
                    break;
                case "云南省":
                    cboCarnum.Text = "云";
                    break;
                case "广西壮族自治区":
                    cboCarnum.Text = "桂";
                    break;
                case "海南省":
                    cboCarnum.Text = "琼";
                    break;
                case "青海省":
                    cboCarnum.Text = "青";
                    break;
                case "新疆维吾尔自治区":
                    cboCarnum.Text = "新";
                    break;
                case "西藏自治区":
                    cboCarnum.Text = "藏";
                    break;
                case "江苏省":
                    cboCarnum.Text = "苏";
                    break;
                case "浙江省":
                    cboCarnum.Text = "浙";
                    break;
                default:
                    break;
            }

            #endregion
        }
        //utf8 编码
        static string TransferEncoding(Encoding srcEncoding, Encoding dstEncoding, string srcStr)
        {
            byte[] srcBytes = srcEncoding.GetBytes(srcStr);
            byte[] bytes = Encoding.Convert(srcEncoding, dstEncoding, srcBytes);
            return dstEncoding.GetString(bytes);
        }
        /// <summary>
        /// 非空验证
        /// </summary>
        /// <returns></returns>
        private bool CheckIsNull()
        {
            if (string.IsNullOrEmpty(txtCarnum.Text))
            {
                MessageBox.Show("请输入车牌号");
                txtCarnum.Focus();
                return false;
            }
            else
            {
                if (string.IsNullOrEmpty(txtFadongji.Text))
                {
                    MessageBox.Show("请输入发动机号");
                    txtFadongji.Focus();
                    return false;
                }
                else if (string.IsNullOrEmpty(txtCaptcha.Text))
                {
                    MessageBox.Show("请填写验证码");
                    txtCaptcha.Focus();
                    return false;
                }
                return true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            tsl2.Text = DateTime.Now.ToLongDateString()   DateTime.Now.ToLongTimeString();
        }
        /// <summary>
        /// 刷新验证码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            GetVerificationCode();
        }

        private void txtCarnum_KeyPress(object sender, KeyPressEventArgs e)
        {
            txtCarnum.CharacterCasing = CharacterCasing.Upper;
        }
        private void btnHelper_Click(object sender, EventArgs e)
        {
            Help help = new Help();
            help.Show();
        }
    }
}

标签: 查询

实例下载地址

C# 全国车辆违章查询 实例源码下载

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 LDQ123456 发表于: 2022-07-11 16:04 29
验证码爬取不了

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有1条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警