Python to realize the automatic check-in of mobile app

Source: Internet
Author: User
Today is the world of mobile apps, a lot of app software in order to attract customers to use every day, set a daily check-in to send some reward activities. Here with a very fire network phone software echoes (every day to send long) as an example, through Python to achieve automatic check-in.

First, Fiddler grab bag

Fiddler not only intercepts HTTP requests from various browsers, but also intercepts HTTP/HTTPS requests made by various smartphones. Fiddler can capture requests from iOS devices, such as the iphone, IPad, and MacBook.  Wait for the Apple device. Similarly, can also intercept andriod,windows phone and other devices issued by the HTTP/HTTPS packet.

The prerequisite is: Install Fiddler machine, with mobile phone in the same network segment (this is not simple, a wireless router to do).

1, Fiddler Configuration

After the Fiddler installation is complete, the following steps are required to configure, click: Tools->fiddler Options are checked in the corresponding blocks of HTTPS and connections items respectively:

2, mobile phone-side configuration

Here assume that the PC installed fiddler software IP for 192.168.1.104, use the mobile browser to open http://192.168.1.104:8888, point "Fiddlerroot certificate" and then install the certificate. After installation, in the mobile phone network connection to find proxy settings, the proxy IP set to 192.168.1.104, port 8888. Here's an example of an iOS phone:

3. Grab Bag and filter

At this time access to mobile apps on the app or through the phone to open the page can be viewed on the PC fiddler the corresponding package, and can be caught on the Fiddler packet Filter, only take the package we want:

Second, the Echo automatic check-in


1. Package Analysis


after grasping the packet analysis, we obtained four URLs (login, sign in, sign-in information, time long information), this four URLs are the pass near get method to make the request, four URLs request returns after all is the XML format.

Login URL:

Http://pes.huying-network.com:9999/httpservice?cmd=getuserinfo&name= Mobile phone number &password= cipher string%3d&appid=5 &v=2.0.0.800&sign=sign string
Return information:

<root>
<result>1</result>
<uid> User id</uid>
<number> Echo Number </number>
<name> Mobile phone number </name>
<issetpwd>1</issetpwd>
<invitecode>1nsye8</invitecode>
<at>at Series </at>
<expire>864000</expire>
</root>

The login URL returns the above information after the request, which is useful for the at string, which is used when the three URL requests follow.

# check-in Implementation
http://pes.huyingdianhua.com:9999/httpservice?cmd=givegift&uid= User Id&type=4&subtype=12&at=at string 3D &v=2.0.0.800&sign=sign string
# check-in Information
http://pes.huyingdianhua.com:9999/httpservice?cmd=getusertaskdetail&uid= User id&type=4&subtype=12 &at=at string%3d&v=2.0.0.800&sign=sign string
# Time-long information
http://pes.huyingdianhua.com:9999/httpservice?cmd=getusertimer&uid= User Id&at=at string 3d&v=2.0.0.800& Sign=sign string

2. Self-check-in code

Here to achieve the function is, automatic check-in, through the XML parsing to obtain the relevant information, and notify by mail confirmation:

#!/usr/bin/python
#coding =utf-8
Import Sys
Reload (SYS)
Sys.setdefaultencoding (' Utf-8 ')
Import Pycurl,stringio
Import Smtplib
From Email.mime.text import Mimetext
def curlget (URL):
c = Pycurl. Curl ()
C.setopt (Pycurl. Followlocation, 1) #允许跟踪来源
C.setopt (Pycurl. Maxredirs, 5)
C.setopt (Pycurl. ConnectTimeout, 8)
head = [' Accept-encoding:gzip '
' User-agent: Echoing 2.0.0 rv:2.0.0.2 (iphone; iphone OS 8.4; zh_cn) ']
BUF = Stringio.stringio ()
C.setopt (Pycurl. Writefunction, Buf.write)
C.setopt (Pycurl. URL, url)
C.setopt (Pycurl. Httpheader, head)
C.perform ()
The_page =buf.getvalue ()
Buf.close ()
Return The_page
def send_mail (to_list,sub,content):
Me= "huying" + "<" +mail_user+ "@" +mail_postfix+ ">"
msg = Mimetext (content,_subtype= ' plain ', _charset= ' utf-8 ')
msg[' Subject ' = Sub
msg[' from ' = Me
Msg[' to '] = ";". Join (To_list)
Try
Server = Smtplib. SMTP ()
Server.connect (Mail_host)
Server.login (Mail_user,mail_pass)
Server.sendmail (Me, To_list, msg.as_string ())
Server.close ()
Return True
Except Exception, E:
Print str (e)
Return False
Logintxt = Curlget (' http://pes.huying-network.com:9999/httpservice?cmd=getuserinfo&name= mobile phone number &password= cipher string %3d&appid=5&v=2.0.0.800&sign=sign string ')
Getgift = Curlget (' http://pes.huyingdianhua.com:9999/httpservice?cmd=givegift&uid= user id&type=4& Subtype=12&at=at string 3d&v=2.0.0.800&sign=sign string ')
Getdetail = Curlget (' http://pes.huyingdianhua.com:9999/httpservice?cmd=getusertaskdetail&uid= user id&type=4 &subtype=12&at=at string%3d&v=2.0.0.800&sign=sign string ')
gettime = Curlget (' http://pes.huyingdianhua.com:9999/httpservice?cmd=getusertimer&uid= user Id&at=at string 3d& V=2.0.0.800&sign=sign string ')
Try
Import Xml.etree.cElementTree as ET
Except Importerror:
Import Xml.etree.ElementTree as ET
Login = et.fromstring (logintxt)
Detail = et.fromstring (Getdetail)
FreeTime = et.fromstring (gettime)
Login_at = Login.find (' at '). Text
longtime = Freetime.find (' Freethreshold '). Text
SignDate = Detail.find (' signdate '). Text
Signday = Detail.find (' Signday '). Text
msg = ' Login string: ' + login_at + ' \ n ' + ' at present free length: ' + longtime + ' \ n ' + ' check-in Date: ' + signdate + ' \ n ' + ' consecutive check-in days: ' + signday
if __name__ = = ' __main__ ':
mailto_list=[' Mail Recipient ']
Mail_host= "Smtp.163.com" #设置服务器
Mail_user= "username" #用户名
mail_pass= "Password" #口令
mail_postfix= "163.com" #发件箱的后缀
If Send_mail (Mailto_list, "Echo Automatic check-in", msg):
Print "Send Success"
Else
Print "Send Failed"
Since the at string has a log of 10 days, there is no variable replacement for the at string for research purposes, and the at string information needs to be replaced when used specifically.

3, the effect

The effect of the final mail received is as follows, another purpose of sending through the mail is to make it easier to analyze the package and update the software two times when the software version is updated, the URL is changed, and the check-in fails.

Write in the end: Because the echo of the URL package is relatively simple, such as Penguin micro-letter, QQ message packet is involved in content encryption, want to achieve some of its functions automatically completed, it is not so simple

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.