java 京东登录
package org.rx.service.media; import io.netty.channel.Channel;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.rx.core.util.ImageUtil;
import org.rx.bot.util.AwtBot;
import org.rx.common.Disposable;
import org.rx.common.InvalidOperationException;
import org.rx.socks.http.HttpClient;
import org.rx.socks.proxyee.intercept.HttpProxyIntercept;
import org.rx.socks.proxyee.intercept.HttpProxyInterceptInitializer;
import org.rx.socks.proxyee.intercept.HttpProxyInterceptPipeline;
import org.rx.socks.proxyee.server.HttpProxyServer;
import org.rx.socks.proxyee.server.HttpProxyServerConfig;
import org.rx.util.ManualResetEvent; import java.awt.*;
import java.awt.image.BufferedImage; import static org.rx.util.AsyncTask.TaskFactory; /**
* helper = new JdLoginBot(config.getJd().getLoginPort());
* while (caller.getCurrentUrl().equals(loginUrl)) {
* try {
* String key = helper.produceKey();
* log.info("produce key {}", key);
* caller.navigateUrl(key, BodySelector);
* log.info("consume key {}", caller.getCurrentUrl());
*
* Thread.sleep(2000);
* } catch (Exception e) {
* log.error("login", e);
* }
* }
*/
@Deprecated
@Slf4j
public final class JdLoginBot extends Disposable {
private static final BufferedImage jdKey; static {
Class owner = JdLoginBot.class;
jdKey = ImageUtil.getImageFromResource(owner, "/bot/jdKey.png");
} private String loginKey;
private ManualResetEvent waiter;
private AwtBot bot;
private Point lastPoint;
private HttpProxyServer proxyServer; public JdLoginBot(int port) {
waiter = new ManualResetEvent();
bot = AwtBot.getBot();
TaskFactory.run(() -> listen(port));
} @Override
protected void freeObjects() {
proxyServer.close();
} private void listen(int port) {
HttpProxyServerConfig config = new HttpProxyServerConfig();
config.setHandleSsl(true);
proxyServer = new HttpProxyServer().serverConfig(config)
.proxyInterceptInitializer(new HttpProxyInterceptInitializer() {
@Override
public void init(HttpProxyInterceptPipeline pipeline) {
pipeline.addLast(new HttpProxyIntercept() {
@Override
public void beforeRequest(Channel clientChannel, HttpRequest httpRequest, HttpProxyInterceptPipeline pipeline) throws Exception {
String host = httpRequest.headers().get(HttpHeaderNames.HOST);
String s = httpRequest.headers().get(HttpHeaderNames.COOKIE);
System.out.println("[rxcookie]: " + s);
if (host != null) {
String url;
if (httpRequest.uri().indexOf("/") == 0) {
if (httpRequest.uri().length() > 1) {
url = host + httpRequest.uri();
} else {
url = host;
}
} else {
url = httpRequest.uri();
}
log.info("Request: {}", url);
if (url.startsWith("passport.jd.com/uc/nplogin?")) {
log.info("JdLoginBot detect {}", url);
loginKey = "http://" + url;
waiter.set();
Thread.sleep(3000);
clientChannel.close();
return;
}
} httpRequest.headers().set(HttpHeaderNames.USER_AGENT, HttpClient.IE_UserAgent);
pipeline.beforeRequest(clientChannel, httpRequest);
} @Override
public void afterResponse(Channel clientChannel, Channel proxyChannel, HttpResponse httpResponse, HttpProxyInterceptPipeline pipeline) throws Exception {
httpResponse.headers().add("intercept", "rxProxy");
pipeline.afterResponse(clientChannel, proxyChannel, httpResponse);
}
});
}
});
proxyServer.start(port);
} @SneakyThrows
public synchronized String produceKey() {
try {
lastPoint = bot.clickByImage(jdKey);
log.info("step1 clickByImage ok");
} catch (InvalidOperationException e) {
if (lastPoint != null) {
bot.mouseLeftClick(lastPoint);
log.info("step1 retry clickByImage {} ok", lastPoint);
} else {
throw e;
}
} waiter.waitOne(6 * 1000);
waiter.reset();
log.info("step2 wait proxy callback"); try {
log.info("step2 get key {}", loginKey);
if (loginKey == null) {
throw new InvalidOperationException("produce empty key");
}
return loginKey;
} finally {
loginKey = null;
TaskFactory.scheduleOnce(() -> {
log.info("step3 try close it");
// bot.saveScreen();
int y = (int) bot.getScreenRectangle().getHeight();
bot.clickAndAltF4(218, y - 20);
log.info("step3 closed it");
}, 2 * 1000);
}
}
}
java 京东登录的更多相关文章
- Java模拟登录系统抓取内容【转载】
没有看考勤的习惯,导致我的一天班白上了,都是钱啊,系统也不发个邮件通知下.... 为了避免以后还有类似状况特别写了个java模拟登录抓取考勤内容的方法(部分代码来自网络),希望有人修改后也可以 ...
- java web登录界面 源代码
大概流程: 在java web项目中 导入sqljdbc4的包 在java Resources中完成java代码 在webContent 下建立一个存放自己写jsp的文件夹 将sqljdbc4和jst ...
- 【转】 我的java web登录RSA加密
[转] 我的java web登录RSA加密 之前一直没关注过web应用登录密码加密的问题,这两天用appscan扫描应用,最严重的问题就是这个了,提示我明文发送密码.这个的确很不安全,以前也大概想过, ...
- python+selenium模拟京东登录后台
python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...
- C#实现京东登录密码加密POST
1.京东登录登录密码 function getEntryptPwd(pwd) { var pubKey = $('#pubKey').val(); if (!pwd || !pubKey || !Sy ...
- java京东自动登录
大部分代码都是参考的这边,我只是在他的逻辑上实现了自动通过验证码,放上主逻辑的代码吧,图片识别我用的若快,可以去接其他平台 https://blog.csdn.net/u013232789/artic ...
- java 自动登录代码
javaBean的代码 package bean; import java.io.Serializable; public class Admin implements Serial ...
- Java 简单登录MVC
构建一个简单的基于MVC模式的JavaWeb 零晨三点半了,刚刚几个兄弟一起出去吼歌,才回来,这应该是我大学第二次去K歌,第一次是大一吧,之后每次兄弟喊我,我都不想去,因为我还是很害怕去KTV,或许是 ...
- HTTPClient实现java自动登录人人网
参考网址: https://passport.csdn.net/account/login http://www.iteye.com/topic/638206 httpClient http://b ...
随机推荐
- 几乎相同的 deal.jsp 代码(index.jsp不变),在IDEA相同项目运行,结果却不一样,实在想不出来
目录 主要问题 主要项目 index.jsp: deal.jsp(正确可运行): deal.jsp(错误不可运行): 错误的代码运行图片: 可运行的代码运行图片 主要问题 几乎相同的 deal.jsp ...
- ajax请求controller出现中文乱码
ajax请求controller出现中文乱码 解决方法:在 @RequestMapping 中加上 produces = {"application/json;charset=UTF-8& ...
- Python笔记(三)_字典与集合
字典dict 映射类型,以键-值的方式存储,通过键来取相应的值 member={'one':1,'two':2,'three':3} 创建字典member=dict('苹果'='apple','桔子' ...
- XAMPP【phpmyadmin】外网访问被拒绝解决办法
问题场景: 在阿里云搭建一个apache服务器,正常访问XAMPP目录下的页面. 服务器本地是可以正常访问的 但是远程 就不可以访问了: 出现这样的画面: 解决方法 1.按照提示找到httpd-xam ...
- 【html】 两栏对比网页,同时滚动
有的时候需要左右对比环境,而且希望能同时滚动,如下这么拼接就可以了 <html> <head><meta http-equiv="content-type&qu ...
- 3.jmeter jsr232 脚本获取当前测试的正在活动的线程数
jsr232 groovy 脚本获取当前测试的正在活动的线程数 (需要选择 groovy类型, 如果使用beanshell或者javascript,请根据其语法稍作修改即可) import org.a ...
- 2019-4-8 zookeeper学习笔记
zookeeper学习 ZooKeeper集合中的节点 让我们分析在ZooKeeper集合中拥有不同数量的节点的效果. 如果我们有单个节点,则当该节点故障时,ZooKeeper集合将故障.它有助于“单 ...
- Linux GNU GAS introduction
Linux汇编语法简介(GNU GAS) 声明:本教程不是介绍汇编语言和CPU指令的书籍,只是对gas的用法做一简单介绍.市面上所有讲汇编的书都是在微软的环境下,使用的是Intel的语法格式, ...
- Ansible@一个高效的配置管理工具--Ansible configure management--翻译(三)
未经书面许可.请勿转载 一张图简单概括 Simple Playbooks Ansible is useful as a command-line tool for making small chang ...
- js的this、bind、call、apply个人领悟
this 1.非箭头函数: 如果是该函数是一个构造函数,this指针指向一个新的对象 在严格模式下的函数调用下,this指向undefined 如果是该函数是一个对象的方法,则它的this指针指向这个 ...