
INTRODUCTION
Once upon a time, my classmate and I were thinking about how to make money. Then, we didn’t come up with anything but sending advertising sms. It didn’t work out because we didn’t have the knowledge and skills. But the desire to recognize the picture and send sms for free (although in our region the Internet was oh how expensive) remained.
CAPHCHA OF MY OPERATOR
Having installed PHP, I decided to start exploring it with some problem. It was then remembered school years. Now I have a mobile operator Tele2, the cheapest in my region. This means that we will work with him. I went to the site
free shipment . I saw how things are with SMS. Pretty simple pictures.

But it was enough to look at them under a microscope ... I must say right away that I did everything in the simplest, first available way, which it was just me and six months ago that seemed the simplest.
')
Yes, pictures. On closer examination, it turned out that the value of the background color is rarely less than 0x7FFFFF. Great, then you can get rid of the noise and see what happens. But how? The first thing I came across in my tutorial is the GDlib library. With this library, you can very easily determine or set the color of a pixel. Replaced the color of each background pixel to black.

So, not bad. Only here clearly some kind of interference remains around the numbers. In fact, captcha has almost always numbers in different colors. Moreover, the numbers are always six. That is, it suffices to find the six most popular colors, and paint the remaining colors with black.

It turned out that all the numbers are separate. After all, this is only a plus.
Now we divide the whole picture into six parts. Each part will contain a number, and a little black background. To do this, we find the highest and the lowest coordinates in y, and the most left and right coordinates in x.

But the numbers at an angle and a different size. For good it is necessary to rotate them and lead to the same size. And it can be easier. Each digit has its own width and height, in my opinion, as unique a parameter as the angle of rotation relative to the vertical axis. We confine ourselves to this one parameter, without rotating anything.
We were able to get six digits from one picture, but we need to recognize them. And what would recognize it is necessary to compare with something. While there was nothing to compare with. At least a small base of standards was needed. It was decided to write a script that downloads a dozen images that were further recognized by a person (me or mom). After recognition, standards were obtained that were preserved in a certain way.

We have ten folders with the names 0,1,2,3,4,5,6,7,8 and 9. Inside each of them are directories that correspond to the geometric dimensions of the recognized digit. This is where the image of the reference figure will remain.
Now you can easily recognize. Each new captcha was getting rid of noise, broken into six numbers. Each figure, passing through the directories that corresponded to its geometric size, was compared with the standards. The comparison is stupid - by the number of matched pixels.
The result was a rather long, but working script. Recognition with a 90% chance lasts an average of five seconds. By reducing the base of the standards, we will reduce the recognition time, but also reduce the probability.
ANNEX OF MY SOCIAL NETWORK
All I could send sms. I wanted to screw this opportunity somewhere. Where?
The choice fell on the social network, which I use the contact. The idea was simple. Send SMS about new messages. Of course, everything could have been done using VK_api, but for sending one SMS, 0.1 votes are deducted from the application (approximately 1 ruble). And the devil knows how to throw these voices there.
So, I need to:
- get access to your own messages;
- view unread;
- identify the sender of the message;
- create SMS text, like: "Message sender", "Message content";
- actually send SMS to your number;
- Mark a message as read.
Still, the very first step is to create a standalone application. Because Only such an application can access private messages. For a long time I was looking for where to create it. The link
by which it is necessary to go is not immediately striking
to create such applications .
To be able to work with user messages, you first need to get
accesss_token . This process is described on
the developer page . We allow our application to access messages at any time (scope = messages, offline). In general, we get approximately the following line:
http://api.vkontakte.ru/oauth/authorize?client_id=__&scope=messages,offline&redirect_uri=http://api.vkontakte.ru/blank.html &display=page&response_type=token
Enter it into the browser. Allow the application access. And safely copy the accesss_token to some file.

Further easier.
We get all unread messages:
https://api.vkontakte.ru/method/messages.get?out=0&offset=0&count=1000&filters=1&preview_lengt=0&time_offset=0 &access_token=__
After processing the
json_decode response, we get an object containing the sender ID, message ID, message content and a bunch of useless information for us. Based on the sender's identifier, we will determine his first and last name:
https://api.vkontakte.ru/method/getProfiles?uid=_&fields=first_name,last_name &access_token=__
In advance, we will write down the phone number in some file, so that it does not store it in the source code. Everything is ready to send SMS. We send (in source code function
send_sms_VK ). It remains to mark the message sent as read:
https://api.vkontakte.ru/method/messages.markAsRead?mids=_ &access_token=__
Let's put all this into a loop that every five seconds will look if someone has written a message to us.
CONCLUSION
All my code is posted
here . It leaves much to be desired and needs some work. There are no small checks, but still he is working. I recall:
$dir_were_expamples="C:\\www\\TEST_DIR2";
The archived sample folder is located
here .
Files
access_token.txt and
tel.txt must be created and filled in advance.
The number format should be
xxxxxxxxxxxx (ten digits). Example 0001234567.
Have a nice summer everyone.