What is it for?
It is worth considering two levels of using this feature:
- The usual, household need to send a relatively long message (unless of course you have the same typing speed on the phone as on the computer)
- Unusual, geeky need to receive mailing information where there is no computer, mixed with unwillingness to pay extra money for delivering this information
Normal application
So, for sure, many were faced with a situation when it is necessary to write a relatively long SMS message:
- copy someone the information you need
- describe in detail any details of the meeting, when your interlocutor does not have the opportunity to talk
- well, or trite to write something in the spirit of those most sins-sms-ok: 3
Unusual use
Here, use options are limited only by your imagination and skills to parse the necessary information flows, for example:
- weather forecast
- rss feed headers
- twitter tape
- your server load data
- ?????
- PROFIT!
Select service to send
Immediately I hasten to warn you that initially everything was done for myself, so the decision is tied to the Moscow megaphone, but for other regions the megaphone also has similar services, I hope for other operators.Obviously, for domestic use it is extremely necessary to send messages from your own number and without advertising, so the service
sendsms.megafon.ru does not fit, the more you need to enter a captcha, and how to show it in the console? And if you also like
framebuffer , how do I love him? And if you take into account the recent
incident with prompted SMS?
Fortunately, the megaphone has
a Service-Guide subscribers self-service system , which I used for these purposes for quite a long time, and there are other useful functions there, and https security inspires some confidence.
')
Relatively recently, when entering the service guide, they stopped offering to introduce captcha, which made me think about using this site for my “dirty” purposes.
Just in case, I will answer those who are wondering why to write a console script instead of entering the site and pressing three buttons: “enter” → “menu: sending sms” → “item: sending sms”:
- I would like to have a direct link to the sending form
- javascript is not enabled by default in text browsers.
- The script can be used not only for normal use, but also to automate the distribution.
Service Guide Site Analysis
Go to
the service guide page and see the following:
- how to get, change, recover password
- special remarks for users of the tariff megaphone Internet
- how to get a link to a Java application Service Guide for your phone
The last point seemed to me very attractive, especially since the traffic promised not to charge, but, unfortunately, it was not possible to install my relatively old Samsung SGH-E200 phone due to the large volume of the application (I didn’t throw out the extra files either).
We proceed to the analysis of the form of entry to the site. I use Mozilla Firefox and
Firebug , Google Chrome has its own toolkit for this purpose.
Open the "Console" tab, turn on the display of AJAX requests, click the "Do not clear" button (so that when you redirect the page, these same requests are not stuck) and try to access the site.
POST request:
www.serviceguide.megafonmoscow.ru/ps/scc/php/check.php?CHANNEL=WWW&LOGIN=_&PASSWORD=_
Answer:
<SESSION_ID>AAAAkljkLFJ9JKJk3fowmcoOW3fds</SESSION_ID>
<LANG_ID>1</LANG_ID>
<AUTH_MODE>U</AUTH_MODE>
It seems everything is clear, we easily get SESSION_ID.
Script writing
The attentive reader will notice that another POST request must be executed when redirecting:
www.serviceguide.megafonmoscow.ru/SCWWW/ACCOUNT_INFO?CHANNEL=WWW&P_USER_LANG_ID=1&SESSION_ID=AAAAkljkLFJ9JKJk3fowmcoOW3fds
Here the answer is much more complicated:
...
<text-phrase xmlns: xalan = "
xml.apache.org/xalan " id = "js-dict-form"> </ text-phrase>
...
I didn’t have much desire to parse this format, so I used the xpath and python-lxml that I already know (this is a good
example of use ).
Suppose we get the data on the balance on the account:
The code is intentionally written without checking for correct execution so as not to clutter the post with a bunch of try-except.
Now we proceed directly to sending SMS:
#
prefix='926' print 'prefix=', prefix addr=raw_input('number (7 digits: 1234567): ') msg=raw_input('message: ') msg=msg.decode('utf8').encode('cp1251') sms_url="https://www.serviceguide.megafonmoscow.ru/SCWWW/SUBS_SEND_SMS_ACTION?" sms_params={'CUR_SUBS_MSISDN': login, 'prefix': prefix, 'addr': addr, 'CHANNEL': 'WWW', 'SESSION_ID': session_id, 'SUBSCRIBER_MSISDN': login, 'MSISDN_TO': prefix+addr, 'P_USER_LANG_ID': lang_id, 'MESSAGE': msg} sms_root=get_root(sms_url,sms_params) divs=sms_root.findall(".//div") for div in divs: print div.text.strip()
Well, it would be nice to log out:
It is easy to write scripts that will send you (or someone else) sms with the information you need: twitter tape, rss, weather forecast and so on. Tying it to the schedule or any events is also not difficult.
Summarizing
Of course, many of the techniques used in the script snippets are not examples of good code. It may be worth using an ssl connection instead of a simple urllib.urlopen (). It is possible that you should not completely translate the page into an etree object, but try to deal with xmlns: xalan. But one of the goals of the article is to show that there is a convenient way to send SMS without typing it on the telephone keypad, and also to provide a tool for automatic SMS messages with sending information.
There are plans to write an article about a script for console viewing the number of tickets for trains from the Russian Railways site. In principle, it is easy to make a connection between these two scripts: send an SMS notification that the tickets you need have appeared.
UPD:Thanks for the valuable comments, a brief summary:
- In some regions, sending SMS via the service guide is paid, be careful
- Some places require captcha input, maybe somewhere it can not be removed, somewhere you can use these tricks:
- "Setting service guide" -> "Automatic access systems" - some captcha removes
- change user agent to iphone / androids and go to the service guide - redirects to another page where there is no captcha
Comparison of shipping methods:
Way | Cost of | room | Note |
---|
Service Guide | Is free | Your | Not for all regions for free, but in some places more captcha remained |
SMS + | 2 rub / day | Your | No more than 70 sms per day, but there are other useful services |
PHP-library for Megafon SOAP API | Depends on your fare | Your | Thanks for the synchrone library |
GSM-modem | Depends on your fare | Your | For fans of Arduino link from Prometheus |
Via mail server | Is free | Other | Not used, information from the words interrupt_controller |