使用httpclient模擬登陸京東賬戶並抓取賬戶信息

這個,前幾天有我的出2000軟妹幣讓我作這個功能,應該是風控系統須要吧,我就鼓搗起來,先分析了一下京東的請求,發現未加密密碼,呵呵呵呵呵呵,故意的吧喂,那我就不客氣哦 
項目百度雲地址:http://pan.baidu.com/s/1kVGtgRt 
上代碼: 
主攻登陸的:html

package clent.http;java

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;node

import org.apache.http.Consts;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
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.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.message.BufferedHeader;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;apache

public class LoginJD {
     CloseableHttpClient httpClient=null;
    Fromdata form=new Fromdata();
    String loginUrl = "http://passport.jd.com/uc/login";
    String redirectURL="http://order.jd.com/center/list.action";
    String home="http://home.jd.com/";
    public void initpage(String username,String pwd)
    {
        String url="http://passport.jd.com/uc/login";
         HttpGet httpPost=new HttpGet(url);
         httpPost.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36");
         String html="";
            try {
                CloseableHttpResponse response = httpClient.execute(httpPost);
                 HttpEntity entity = response.getEntity();  
                 html=EntityUtils.toString(entity, "utf-8");
                 Elements els=Jsoup.parse(html).getElementsByTag("input");
                 for(Element e:els)
                 {
                     String value=e.val();
                     String name=e.attr("name");
                     if(!"uuid".equals(name)&&!"machineNet".equals(name)&&!"machineCpu".equals(name)&&!"machineDisk".equals(name)&&!"eid".equals(name)&&!"fp".equals(name)&&!"_t".equals(name)&&!"loginType".equals(name)&&!"loginname".equals(name)&&!"nloginpwd".equals(name)&&!"loginpwd".equals(name)&&!"chkRememberMe".equals(name)&&!"authcode".equals(name))
                     {
                         form.key=name;
                         form.value=value;
                     }
                         form.init(name, value);
                         form.setLoginname(username);
                         form.setNloginpwd(pwd);
                         form.setLoginpwd(pwd);
                 }
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println(html);
    }
    public void login()
    {
        String url=UrlConfig.loginurl;
        url=url.replace("#{uuid}", this.form.getUuid());
         HttpPost httpPost=new HttpPost(url);
         httpPost.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36");ui

         UrlEncodedFormEntity entity = new UrlEncodedFormEntity(this.form.getbase(), Consts.UTF_8);
         try {
            System.out.println(EntityUtils.toString(entity, "utf-8"));
        } catch (ParseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
         httpPost.setEntity(entity);
         String html="";
            try {
                CloseableHttpResponse response = httpClient.execute(httpPost);
                HttpEntity entitySort = response.getEntity();
                 html=EntityUtils.toString(entitySort, "utf-8");this

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("++++++\t"+html);加密

    }
    public void getImage()
    {
        String url=UrlConfig.imageurl;
        System.out.println(url);
        url=url.replace("#{acid}", this.form.getUuid()).replace("#{uid}", this.form.getUuid()).replace("#{time}", System.currentTimeMillis()+"");url

        System.out.println(url);
        try {code

            HttpGet httpimg = new HttpGet(url);
            httpimg.setHeader("Connection", "keep-alive");
            httpimg.setHeader("Host", "authcode.jd.com");
            httpimg.setHeader("Referer", "https://passport.jd.com/uc/login?ltype=logout");
            httpimg.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36");orm

            HttpResponse responseimg =  httpClient.execute(httpimg);
            File file=new File("D:\\ss.gif");
            OutputStream out=new FileOutputStream(file);
            responseimg.getEntity().writeTo(out);
            out.close();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public String  getpage_1(String url)
    {
         HttpGet httpPost=new HttpGet(url);
         httpPost.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36");
            try {
                CloseableHttpResponse response = httpClient.execute(httpPost);
                BufferedHeader locationHeader = (BufferedHeader) response.getFirstHeader("Location");
                if (locationHeader == null) {
                    return null;
                }
                return locationHeader.getValue();

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return null;
    }
    public void  getpage_2(String url)
    {
         HttpGet httpPost=new HttpGet(url);
         httpPost.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36");
         String html="";   
         try {
                CloseableHttpResponse response = httpClient.execute(httpPost);
                HttpEntity entitySort = response.getEntity();
                 html=EntityUtils.toString(entitySort, "utf-8");

            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
           System.out.println("getpage_2\n"+html);
    }
    public static void main(String[] args)
    {
        Scanner scan = new Scanner(System.in);//輸入
        LoginJD jd=new LoginJD();
        jd.httpClient=HttpClients.createDefault();
        jd.initpage("xxxxxx","xxxxxxxxxxx");
        jd.getImage();
        String validate="";
        validate = scan.next();
        jd.form.setAuthcode(validate);
        jd.login();
        jd.getpage_2(jd.home);
    }
}
這就登陸成功了,親測能夠沒問題,鵝鵝鵝,強哥仍是敦促開發人員填了這個坑吧

須要完整的代碼能夠留言哦,還有,網上其餘的一些登陸京東的,有問題,估計是那人故意留的坑

相關文章
相關標籤/搜索