使用httpclient模拟登录京东帐户并抓取帐户信息

这个,前几天有个人出2000软妹币让我做这个功能,应该是风控系统需要吧,我就鼓捣起来,先分析了一下京东的请求,发现未加密密码,呵呵呵呵呵呵,故意的吧喂,那我就不客气哦 
项目百度云地址:http://pan.baidu.com/s/1kVGtgRt 
上代码: 
主攻登录的:

package clent.http;

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;

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;

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");

         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");

            } 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()+"");

        System.out.println(url);
        try {

            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");

            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);
    }
}
这就登录成功了,亲测可以没问题,鹅鹅鹅,强哥还是敦促开发人员填了这个坑吧

需要完整的代码可以留言哦,还有,网上其他的一些登录京东的,有问题,估计是那人故意留的坑

转载于:https://my.oschina.net/u/200350/blog/3004517

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值