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. 01 【零基础入门】html学习笔记(1)

    之前学习了前端的一些基础知识,现在想深入地.精通地学习前端,往前端和全栈工程师方向发展. 之前学习前端主要是通过看视频,结合动手练习.现在认为看书+视频+实践,应该是最高效的学习方法.对于html.c ...

  2. php 封装原生数据导入的方法(csv文件格式)

    //前端---部分代码 <form class="form-inline" style="margin-top: 20px" method="p ...

  3. CPU C-States Power Saving Modes

    http://www.hardwaresecrets.com/article/611 Everything You Need to Know About the CPU C-States Power ...

  4. linux超级块和inode 详解 和 df 、du 命令详解与环境变量

    一.inode块,Unix文件的核心. 首先需要明白的是,在Unix操作系统中的任何资源都被当作文件来管理.如目录.光驱.终端设备等等,都被当作是一种文件.从这方面来说,Unix操作系统中的所有的目录 ...

  5. Python 进阶_OOP 面向对象编程_组合与继承

    #目录 前言 组合 派生 通过继承来覆盖重载方法 最常用的重载场景实例方法的重载 从标准类中派生类方法的重载 前言 我们定义一个类是希望能够把类当成模块来使用,并把类嵌入到我们的应用代码中,与其他的数 ...

  6. appium常见问题07_appium输入中文无效

    前几天在appium android自动化测试过程中,使用send_keys()输入中文,发现只能输入字母和数字,输入中文无反应. 大家是否同样遇到过该问题,当大家同样遇到该问题时,在配置参数desi ...

  7. VB - 循环

    循环控制语句有for……next循环.for……each循环.do……while循环.do……until循环.while循环五种形式. 1. 在使用循环控制语句前,首先要对循环条件进行判断,如果循环次 ...

  8. cf:c题

    题目: 代码: #include<iostream> #include<algorithm> #include<vector> #include<string ...

  9. sql优化案例1

    --访客数 ) from ( select v.idvisitor from ods.piwik_log_visit v , , group by v.idvisitor) --优化后的访客数查询 s ...

  10. android jni控制gpio (rk3288)

    1.添加驱动程序 2.编写jni c程序编译为库给java调用 3.app调用jni静态链接库操作底层驱动 1.添加驱动程序 修改/work/rk3288/firefly-rk3288_android ...