Alas mop and did not punch in, the front more than 10 Tianquan No, like us it code farmers, although every day online, but always forget to punch in, this is not the wrong generation of hate, failed Isaac. Hard to punch every time you can get hundreds of copies, alas.
? 1. Code [Java] Code
Package Com.mop.core;
Import java.io.IOException;
Import java.net.URISyntaxException;
Import Java.util.HashMap;
Import Java.util.Map;
Import org.apache.http.HttpException;
Import org.apache.http.client.HttpClient;
Import org.apache.http.impl.client.DefaultHttpClient;
Import Com.mop.util.HttpUtil;
/**
* MOP Punch-in small application
*
* @author Jeson.sha
* @website www.ij2ee.com
*/
public class Mop {
private static final String Login_url = "Http://passport.mop.com/Login?url=http://www.mop.com&charset=utf-8";
private static final String User_info = "http://passport.mop.com/common/user-info?callback=jsonp1338724243937";
private static final String PUNCH = "http://passport.mop.com/punch-the-clock/punch?callback=jsonp1338724243939";
private static final String charset= "Utf-8";
/**
* @param args
* @throws interruptedexception
* @throws HttpException
* @throws IOException
* @throws URISyntaxException
* @throws IllegalStateException
*/
public static void Main (string[] args) throws IllegalStateException, URISyntaxException, IOException, HttpException, interruptedexception {
HttpClient client = new Defaulthttpclient ();
String userName = "Cat house Three Little";
MOP MOP = new mop ();
Mop.login (Client,username, "111111");
Boolean islogin = Mop.getiscangetuserinfo (client,username);
if (!islogin) {http://www.huiyi8.com/bgm/?
SYSTEM.OUT.PRINTLN ("Login Failed");
}
if (mop.punch (client)) {
SYSTEM.OUT.PRINTLN ("Punch-out success");
}else{background music
SYSTEM.OUT.PRINTLN ("Punch-out failed");
}
}
/**
* Punch-in points
* Success will return jsonp1338724243939 ({"mpplused": +, "status": 200}) score and status
* Failed to return jsonp1338724243939 ({"Status": 404})
* The difference is there's no mpplused JSON property
* @param Client
* @return If the clock is successful
* @throws IllegalStateException
* @throws URISyntaxException
* @throws IOException
* @throws HttpException
* @throws interruptedexception
*/
Private Boolean punch (HttpClient client) throws IllegalStateException, URISyntaxException, IOException, HttpException, interruptedexception {
String punchres = httputil.doget (client, PUNCH, CHARSET);
Return Punchres.indexof ("mpplused")!=-1;
}
/**
* Can I get user information?
* Success JSON will appear with login name so here is the existence of a user name to determine
* @param Client
* @param userName
* @return
* @throws IllegalStateException
* @throws URISyntaxException
* @throws IOException
* @throws HttpException
* @throws interruptedexception
*/
Private Boolean Getiscangetuserinfo (HttpClient client,string userName) throws IllegalStateException, URISyntaxException, IOException, HttpException, interruptedexception {
Boolean iscangetuserinfo = false;
String res = httputil.doget (client, User_info, CHARSET);
Iscangetuserinfo = Res.indexof (userName)!=-1;
return iscangetuserinfo;
}
/**
* Login
* No header or header error will cause login failure
* @param Client
* @param userName
* @param password
* @throws IllegalStateException
* @throws URISyntaxException
* @throws IOException
* @throws HttpException
* @throws interruptedexception
*/
private void Login (HttpClient client,string username,string password) throws IllegalStateException, URISyntaxException , IOException, HttpException, interruptedexception{
map<string, string> param = new hashmap<string, string> ();
Param.put ("user_name", userName);
Param.put ("password", password);
map<string, string> loginheader = new hashmap<string, string> ();
Loginheader.put ("Content-type", "application/x-www-form-urlencoded");
Loginheader.put ("User-agent", "mozilla/4.0" (compatible; MSIE 8.0; Windows NT 5.1; trident/4.0; Qqwubi 133; CIBA;. NET CLR 2.0.50727) ");
Loginheader.put ("Host", "passport.mop.com");
Loginheader.put ("Referer", "http://www.mop.com/");
Loginheader.put ("Cookie", "mopst_ssid=13387192652653136; mopst_ssid_time=1338719327796; base_domain_ 629695a417eb49ada2a6bc2f67b3f7ef=mop.com; mopst_unique=13387192636401978; mop_locale=0086320500; maxfxbidw2010=935; xnsetting_629695a417eb49ada2a6bc2f67b3f7ef=%7b%22connectstate%22%3a2%2c%22onelinestorysetting%22%3a3%2c% 22shortstorysetting%22%3a3%2c%22shareauth%22%3anull%7d ");
String postres = httputil.dopost (client, Login_url, param, loginheader,charset);
System.out.println (Postres);
}
}