java京东自动登录
大部分代码都是参考的这边,我只是在他的逻辑上实现了自动通过验证码,放上主逻辑的代码吧,图片识别我用的若快,可以去接其他平台
https://blog.csdn.net/u013232789/article/details/74456204?locationNum=5&fps=1
public synchronized boolean login() { //判断是否已登录 String verify = HttpClientUtil.get("https://home.jd.com/getUserVerifyRight.action"); if (verify.length() < 200) { return true; } try { Document doc = Jsoup.parse(HttpClientUtil.get("https://passport.jd.com/new/login.aspx")); Thread.sleep(1000); Elements elements = doc.select("form[id=formlogin] input[type=hidden]"); Map<String, String> map = new HashMap<String, String>(); String k, v; for (Element input : elements) { k = input.attr("name"); v = input.attr("value"); if (StringUtils.isNotBlank(k)) { map.put(k, v); System.out.println(input); } } map.put("loginname", keyValueMap.get("JDAccount")); map.put("nloginpwd", keyValueMap.get("JDPassword")); map.put("eid", "RXI4RZELZBUFTKRYDTWZHA734GHXAKCA5SJQSPGLJ2RXCIZUT3PAYXSRGSC57USYLK6432Z7WJW36ZEEGVWMLILT3E"); map.put("fp", "ccbe046c9993c80f4838e591159ce563"); String result = HttpClientUtil.get( "https://seq.jd.com/jseqf.html?bizId=passport_jd_com_login_pc&platform=js&version=1"); Thread.sleep(1000); String pattern = "sessionId=.+_jdtdseq_config_data"; // 创建 Pattern 对象 Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(result); if (m.find()) { System.out.println(m.group().substring(11, 29)); map.put("seqSid", m.group().substring(11, 29)); } String url = "https://passport.jd.com/uc/loginService?"; url = url + "&uuid=" + map.get("uuid") + "&r=" + Math.random() + "&version=2015"; System.out.println("url: " + url); String post = HttpClientUtil.post(url, map); System.out.println(post); String ans = decodeUnicode(post); System.out.println(ans); if (ans.contains("emptyAuthcode")) { String authUrl = "https://authcode.jd.com/verify/image"; Map<String, String> param = new HashMap<>(); param.put("a", "1"); param.put("acid", map.get("uuid")); param.put("uid", map.get("uuid")); param.put("yys", String.valueOf(System.currentTimeMillis())); Map<String, String> header = new HashMap<>(); header.put("Referer", "https://passport.jd.com/new/login.aspx"); HttpResponse response = HttpClientUtil.getForResponse(authUrl, param, header); String authCode = RuoKuai.createByPost(keyValueMap.get("RKAccount"), keyValueMap.get("RKPassword"), response.getEntity().getContent()); System.out.println(authCode); map.put("authcode", authCode); ans = decodeUnicode(HttpClientUtil.post(url, map)); log.info(ans); } if (ans.contains("success")) { return true; } else { return false; } } catch (Exception e) { log.error(TypeUtil.getErrorInfoFromException(e)); return false; } }