论坛首页 Java企业应用论坛

HttpClient 实现快盘签到

浏览 3976 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-04-20  
引用
模拟POST提交实现快盘签到




import java.io.IOException;
import java.io.UnsupportedEncodingException;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
/**
 * @author  <a href="mailto:foohsinglong@gmail.com">kevin.long</a>
 * @description
 */
public class TestKlive {

	private static HttpClient hc = new DefaultHttpClient();

	public static String postXml(String url, String xmlData) {
		String body = null;
		try {
			HttpPost httppost = new HttpPost(url);
			httppost.setHeader("Content-Type", "text/xml;charset=utf-8");
			httppost.setHeader("v", "2");
			// 设置参数
			httppost.setEntity(new StringEntity(xmlData));
			// 发送请求
			HttpResponse httpresponse = hc.execute(httppost);
			// 获取返回数据
			HttpEntity entity = httpresponse.getEntity();
			body = EntityUtils.toString(entity);
			if (entity != null) {
				entity.consumeContent();
			}
            
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 * @param args
	 * @throws DocumentException 
	 */
	public static void main(String[] args) throws DocumentException {
		String getTokenUrl = "http://api-filesys.wps.cn/xsvr/login/";
		String signUrl = "http://point.wps.cn/kpoints/submit/sign/";
		StringBuffer xmlData = new StringBuffer();
		xmlData.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><xLive><user>");
		xmlData.append("jinshany000@sina.com");
		xmlData.append("</user><password>");
		xmlData.append("123456");
		xmlData.append("</password><deviceId>greenx-a34064b5b75e0c100f52c6c0fe80d887|

GEBINWIN</deviceId><clientName>greenx</clientName><clientVersion>1.0.0.90</clientVersion></xLive>");
		System.out.println(xmlData);
		String body = postXml(getTokenUrl, xmlData.toString());
		System.out.println(body);
		Document document = DocumentHelper.parseText(body);
		Element rootElt = document.getRootElement();
		String userId = rootElt.elementTextTrim("userId");
		String token = rootElt.elementTextTrim("token");
		System.out.println("获取信息\t"+userId+":"+token);
		xmlData.delete(0, xmlData.length());
		xmlData.append("<?xml version=\"1.0\" encoding=\"utf-8\" ?><xLive><token>");
		xmlData.append(token);
		xmlData.append("</token><userId>");
		xmlData.append(userId);
		xmlData.append("</userId></xLive>");
		body = postXml(signUrl, xmlData.toString());
		System.out.println(body);
	}
}

   发表时间:2012-04-23  
thanks for sharing
0 请登录后投票
   发表时间:2012-04-23  
之前公司OA也要先打开浏览器输入用户名密码(没有验证码),然后进行签到签退感觉挺麻烦的,也用HTTPclient做了一个快速签到签退的东东
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics