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 京东登录的更多相关文章

  1. Java模拟登录系统抓取内容【转载】

    没有看考勤的习惯,导致我的一天班白上了,都是钱啊,系统也不发个邮件通知下....     为了避免以后还有类似状况特别写了个java模拟登录抓取考勤内容的方法(部分代码来自网络),希望有人修改后也可以 ...

  2. java web登录界面 源代码

    大概流程: 在java web项目中 导入sqljdbc4的包 在java Resources中完成java代码 在webContent 下建立一个存放自己写jsp的文件夹 将sqljdbc4和jst ...

  3. 【转】 我的java web登录RSA加密

    [转] 我的java web登录RSA加密 之前一直没关注过web应用登录密码加密的问题,这两天用appscan扫描应用,最严重的问题就是这个了,提示我明文发送密码.这个的确很不安全,以前也大概想过, ...

  4. python+selenium模拟京东登录后台

    python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...

  5. C#实现京东登录密码加密POST

    1.京东登录登录密码 function getEntryptPwd(pwd) { var pubKey = $('#pubKey').val(); if (!pwd || !pubKey || !Sy ...

  6. java京东自动登录

    大部分代码都是参考的这边,我只是在他的逻辑上实现了自动通过验证码,放上主逻辑的代码吧,图片识别我用的若快,可以去接其他平台 https://blog.csdn.net/u013232789/artic ...

  7. java 自动登录代码

    javaBean的代码    package bean;    import java.io.Serializable;    public class Admin implements Serial ...

  8. Java 简单登录MVC

    构建一个简单的基于MVC模式的JavaWeb 零晨三点半了,刚刚几个兄弟一起出去吼歌,才回来,这应该是我大学第二次去K歌,第一次是大一吧,之后每次兄弟喊我,我都不想去,因为我还是很害怕去KTV,或许是 ...

  9. HTTPClient实现java自动登录人人网

    参考网址: https://passport.csdn.net/account/login  http://www.iteye.com/topic/638206 httpClient http://b ...

随机推荐

  1. LINUX shell脚本相关

    调试脚本 测试脚本语法:bash -n file.sh 查看脚本每一步执行情况:bash -x file.sh   位置变量:$1,$2,... 特殊变量:           %?:最后一个命令的执 ...

  2. spring cloud gateway 拦截request Body

    在接入Spring-Cloud-Gateway时,可能有需求进行缓存Json-Body数据或者Form-Urlencoded数据的情况. 由于Spring-Cloud-Gateway是以WebFlux ...

  3. 使用Gradle打出带签名的apk包

    step1:配置build.gradle文件 step1:切换到项目所在目录,用build命令打包 首先 gradle clean 命令清理一下当前项目 E:\AndroidStudioProject ...

  4. windows10激活

    (1).首先,我们先查看一下Win10正式专业版系统的激活状态:按住win+r键,运行命令提示符,输入slmgr.vbs -xpr,点击确定,查看系统的状态是什么时候到期或者是处于通知状态. (2). ...

  5. exception中return方法

    public class ExceptionPitfall { public static void main(String[] args) { try { throw new RuntimeExce ...

  6. <读书笔记>JavaScript系列之7种创建对象(面向对象)

    写在前面: 以下三选一: 阅读博文JavaScript 对象详解. 阅读<JavaScript权威指南>第6章. 阅读<JavaScript高级程序设计>第6章. 注意:只需要 ...

  7. <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">

    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalabl ...

  8. Mycat+Pxc的配置

    1 schema.xml配置文件 Balance属性 负载均称类型 0:不开启读写分离机制,所有读操作都发送到当前可用的writeHost上 1:全部的readHost与stand by writeH ...

  9. Cocos2d-x之MessageBox

    |   版权声明:本文为博主原创文章,未经博主允许不得转载. 在cocos2d-x中使用的对话框为MessageBox,因为cocos2d-x已经包装好了:但是在一般的游戏设置中,我们不会使用coco ...

  10. if语句的嵌套使用之获取三个数据的最大值

    获取三个数据的最大值: class Hello2 { public static void main(String[] args) { int a = 10; int b = 20; int c = ...