Currently, many third-party Apsara stack APIs are available on the Internet. The disadvantage is that they are not very stable, and many of them have expired and cannot be used. In addition, we will worry about information leakage. In fact, we can implement such an interface by ourselves. The idea I provided here is very simple: Simulate login to the WAP version of The Apsara stack to implement the operations such as sending emails. The main reason for choosing WAP
Currently, many third-party Apsara stack APIs are available on the Internet. The disadvantage is that they are not very stable, and many of them have expired and cannot be used. In addition, we will worry about information leakage. In fact, we can implement such an interface by ourselves. The idea I provided here is very simple: Simulate login to the WAP version of The Apsara stack to implement the operations such as sending emails. The main reason for choosing WAP
Currently, many third-party Apsara stack APIs are available on the Internet. The disadvantage is that they are not very stable, and many of them have expired and cannot be used. In addition, we will worry about information leakage. In fact, we can implement such an interface by ourselves. The idea I provided here is very simple: Simulate login to the WAP version of The Apsara stack to implement the operations such as sending emails. The choice of WAP fetion is mainly because its interface is relatively simple, easy to analyze, and there is no verification code.
1. Install the Firefox Plugin wmlbrowser
In this way, we can directly use Firefox to browse WAP web pages, and use Firebug to analyze the interface. : Https://addons.mozilla.org/zh-CN/firefox/search? Q = wmlbrowser & cat = all & x = 17 & y = 11
2. Analysis of the logon page
The WAP fetion entrance is http://f.10086.cn/, click to chat about the wapfetion into the entrance page (http://f.10086.cn/im/login/login.action ). Firebug shows that:
There are three fields: pass (password), loginstatus (logon status), and m (mobile phone number)
Action submitted to: http://f.10086.cn/im/login/inputpasssubmit1.action
In fact, there is a clever way to get the field submitted by the form: Modify the action and let it point to its own program, such:
I changed the action to a local php program. This program is just a simple sentence of print_r ($ _ POST). The result is:
The content is the data to be submitted by the form.
3. Use CURL to simulate Logon
From the above analysis, the content submitted during logon is relatively simple, without verification codes or anti-Cross-origin hash value verification. Then we use CURL to simulate the submission of this login form. Actually, a POST-based HTTP request is sent. CURL can save the returned Cookie as a file. This Cookie file will be used for subsequent operations such as sending emails.
The Code is as follows:
01 |
$cookie = dirname(__FILE__).'/cookie.txt'; |
08 |
$curl = curl_init('http://f.10086.cn/im/login/inputpasssubmit1.action'); |
09 |
curl_setopt($curl, CURLOPT_HEADER, 0); |
10 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
11 |
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); // Pay attention to this! Save Cookie |
12 |
curl_setopt($curl, CURLOPT_POST, 1); |
13 |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); |
14 |
$result = curl_exec($curl); |
If the logon is successful, you can determine the value of $ result.
4. Carry a Cookie and send a flying mail to yourself.
Sending emails to yourself is easier than sending emails to friends. There is a dedicated page. You can go to the "homepage after logon => materials => send a text message to yourself":
Http://f.10086.cn/im/user/sendmsgtomyself.action.
Analyze the form using the same method as above:
There is only one field: msg (SMS content)
Action submitted to: http://f.10086.cn/im/user/sendMsgToMyselfs.action
Use CURL to send a POST request to this URL, and add the Cookie saved above. The following code is used:
02 |
'msg' => 'Hello Fetion', |
05 |
$curl = curl_init('http://f.10086.cn/im/user/sendMsgToMyselfs.action'); |
06 |
curl_setopt($curl, CURLOPT_HEADER, 0); |
07 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
08 |
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); // Pay attention to this! |
09 |
curl_setopt($curl, CURLOPT_POST, 1); |
10 |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); |
11 |
$result = curl_exec($curl); |
Based on the returned $ result, you can determine whether the message is successfully sent.
5. Obtain the userid corresponding to the mobile phone number of a friend before sending a flying mail to a friend.
Because the form sent to a friend is submitted by userid instead of the mobile phone number (this form is analyzed in the next step), we must find a way to find the userid corresponding to the mobile phone number. Here I am using the "Search for friends" function, which is on the homepage after the login of Apsara stack, such:
Search by phone number to get a unique and accurate result. Then we use regular expressions to match the userid on the result page.
First, analyze the form:
Sent field: searchText (only one)
Action submitted to: http://f.10086.cn/im/index/searchOtherInfoList.action
Use CURL to send a request. The Code is as follows:
02 |
'searchText' => '18700008888', |
05 |
$curl = curl_init('http://f.10086.cn/im/index/searchOtherInfoList.action'); |
06 |
curl_setopt($curl, CURLOPT_HEADER, 0); |
07 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
08 |
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); // Pay attention to this! |
09 |
curl_setopt($curl, CURLOPT_POST, 1); |
10 |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); |
11 |
$result = curl_exec($curl); |
Obtain the userid In the result using the regular expression:
1 |
preg_match('/toinputMsg\.action\?touserid=(\d+)/si', $result, $matches); |
2 |
$userid = isset($matches[1]) ? $matches[1] : ''; |
This can be used as a prompt when the userid cannot be found.
6. Send a flying letter to a friend
Send a letter to a friend. Form HTML, for example:
Analyze this form:
Submitted fields: backUrl, touchTitle, touchTextLength, msg
Action: http://f.10086.cn/im/chat/sendMsg.action? Touserid = the userid obtained above
The Code is as follows:
02 |
'msg' => 'Hello Fetion', |
05 |
$curl = curl_init('http://f.10086.cn/im/chat/sendMsg.action?touserid='.$userid); // Pay attention to this! |
06 |
curl_setopt($curl, CURLOPT_HEADER, 0); |
07 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
08 |
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); // Pay attention to this! |
09 |
curl_setopt($curl, CURLOPT_POST, 1); |
10 |
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post)); |
11 |
$result = curl_exec($curl); |
The above $ post only contains one field, because during the test, I found that other fields are not required. You can determine whether the message is successfully sent based on the returned $ result.
7. Exit Apsara stack.
If you do not exit, you can only view the message on the WAP, rather than automatically sending it to your mobile phone. The exit operation is simple, but a GET request is sent. The "exit" link is displayed in the lower-right corner of the homepage after logon,
The Code is as follows:
1 |
$curl = curl_init('http://f.10086.cn/im/index/logoutsubmit.action'); |
2 |
curl_setopt($curl, CURLOPT_HEADER, 0); |
3 |
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); |
4 |
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookie); // Pay attention to this! |
5 |
$result = curl_exec($curl); |
8. Summary
By sorting out the above code, you can make a mail sending class. It can also be used as a mail sending service, such as an easy-to-use HTTP interface. The biggest benefit of Apsara is that it is free of charge and can send messages to mobile phones in real time. It can be used to provide some functions similar to scheduled text messages or monitoring reminders.
I have encapsulated a PHP fetion class here. You can download it from Google Code: http://code.google.com/p/php-fetion/downloads/list. Do not abuse it to avoid issues such as block numbers.
From: http://blog.quanhz.com/archives/118
Php fetion: http://www.oschina.net/code/snippet_114572_12155