WPF performs the 12306 Verification Code click effect, wpf12306 Verification Code click

Source: Internet
Author: User

WPF performs the 12306 Verification Code click effect, wpf12306 Verification Code click

I. Results

It is the same as 12306. When you log on to 12306, you can click multiple positions on a graph. You cannot click the positions above the horizontal line or on the left border, and click the button to output the coordinate set, parameters to be passed to the backend.

II. Implementation ideas

1. Obtain the verification code Image

First, we see the 12306 login page, F12, through the location, we can observe that the verification code request URL is "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew? Module = login & rand = sjrand & 0.8291445260649148 ",

I don't know how this string of numbers 0.8291445260649148 gets, so first remove it from it, leaving only "https://kyfw.12306.cn/otn/passcodeNew/getPassCodeNew? Module = login & rand = sjrand ",

Write a Request and find that you can Request the verification code image, which is different each time. Therefore, this URL is enough.

The image size is always 293*190, which is used to take coordinates conveniently.

2. Analyze the verification code Image

By clicking on the official website 12306, we can find that the parts above the horizontal line are not allowed to be clicked, and the blank parts on the left and right are not allowed to be clicked. When we are doing this, select a range as the clickable range.

By using the GetPosition method, you can easily obtain the coordinates of the four corners of the central image (5,180) (288,180) () that is, our clickable area is 5 = <X <= 288 & 40 = <Y <= 180.

In this case, we can determine whether the Position is in this range when the mouse clicks the practice.

3. Click the mouse and place the Logo of the iron boss.

When you click the verification code with the mouse, it is very easy to print the Logo of iron's boss. It is to set an additional Canvas attribute for the Logo, but note that when we press it by default, it is not the center of the Logo, but the upper left corner. Therefore, the computing center is required.

For example, my Logo is 32*32, that is to say Position. X-16, Position. Y-16, in this way, to ensure that after the Logo up, is the center for the mouse click Position.

When you click the Logo, the Logo is removed from the Canvas, so that you can click Cancel.

<Grid> <Grid. rowDefinitions> <RowDefinition Height = "*"/> <RowDefinition Height = "Auto"/> </Grid. rowDefinitions> <Canvas x: Name = "cav" Grid. row = "0"> <Image x: Name = "img" Height = "190" Width = "293" MouseLeftButtonDown = "img_MouseLeftButtonDown"/> </Canvas> <Button Grid. row = "1" Content = "coordinate set" x: Name = "btn" Click = "btn_Click"/> </Grid>
private void img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){    BitmapImage imageIcon = new BitmapImage(new Uri(@"pack://application:,,,/12306SecurityCode;component/favicon.ico", UriKind.RelativeOrAbsolute));    System.Windows.Point pointImg = e.GetPosition(img);    System.Windows.Point pointCav = e.GetPosition(cav);    if (pointImg.X >= 5 && pointImg.X <= 288 && pointImg.Y >= 40 && pointImg.Y <= 180)    {        System.Windows.Controls.Image imgIco = new System.Windows.Controls.Image()        {            Source = imageIcon        };        imgIco.MouseLeftButtonDown += ImgIco_MouseLeftButtonDown;        Canvas.SetLeft(imgIco, pointCav.X - 16);        Canvas.SetTop(imgIco, pointCav.Y - 16);        cav.Children.Add(imgIco);        ImgicoList.Add(imgIco);    }}
private void ImgIco_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){    System.Windows.Controls.Image imgico = (System.Windows.Controls.Image)sender;    cav.Children.Remove(imgico);    ImgicoList.Remove(imgico);}

4. Get the remaining Logo location

The Logo is constantly added, the Logo is constantly reduced, and the last Logo is obtained. In fact, a List set is used to save the Logo. At first, the coordinates are to be saved, however, if the coordinates are saved, it will be difficult to control them. Therefore, we will save the Logo set and read the coordinates of the Logo.

private System.Windows.Point GetIcoPoint(System.Windows.Controls.Image image){    System.Windows.Point point = new System.Windows.Point();    point.X = Canvas.GetLeft(image) + 16;    point.Y = Canvas.GetTop(image) + 16 - 40;    return point;}

This part of coordinates is to be returned to 12306 for resolution. Therefore, we need to first restore the coordinates of the original click, that is, the radius of the Logo is 16.

Then, let's take a look at the coordinates received by 12306: 7% 2C11% 2C282% 2C10, () (282,10). Here, Y is 11 or 10, that is, the height above the horizontal line is subtracted, for convenience, we lose 40.

5. concatenate strings

Because "all" is written in the image, we do not need to judge the order. We only need to obtain the coordinates of all the left points and then OK. We need to add "% 2C" as the mark, concatenate all X and Y values

private void btn_Click(object sender, RoutedEventArgs e){    string s = string.Empty;    foreach (var item in ImgicoList)    {        System.Windows.Point point = GetIcoPoint(item);        s += point.X + "%2C" + point.Y + "%2C";    }    s = s.Substring(0, s.Length - 3);    MessageBox.Show(s);}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.