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. English-Difference between original and source

    最近跟网页翻译怼上了,在给翻译前的页面起名是纠结于使用 original page 还是 source page,就查了一下 original 和 source 的区别. original: n. 原 ...

  2. feignClient传参(参数为对象类型)的一个坑

    客户端 @RequestMapping(value = "/friendCircleComment/comment",method = RequestMethod.POST) R ...

  3. 测开之路十六:@classmethod与@staticmethod

    @classmethod 类方法 和属性一样,所有实例化的对象都共享类方法 @staticmethod 静态方法,可以理解为和类没有任何关系,只是放在了类里面 参数可以任意定义,根据自己的定义传参,也 ...

  4. jQuery:unbind方法的使用详解

    一.概述: unbind方法只能解绑用jQuery的bind方法以及用jQuery方法注册的事件处理程序.比如:$(‘a’).click(function(){})可以通过unbind解绑.用原生ad ...

  5. yii之relations关联非主键

    yii的relations里self::BELONGS_TO默认是用当前指定的键跟关联表的主键进行join,例如: return array('reply' => array(self::BEL ...

  6. 对GridFS数据进行分片

    On this page files 集合 chunks 集合 在对 GridFS 存储进行分片时,需要注意以下的情况: files 集合 大多数情况下不需要对 files 集合进行分片,这个集合通常 ...

  7. Html5 学习笔记 【PC固定布局】 实战5 咨询页面 侧栏

    最终效果图: 提出公共页脚和导航部分: 新建infomatino.html (旅游咨询)页面 <!DOCTYPE html> <html lang="zh-cn" ...

  8. AtCoder ABC 140E Second Sum

    题目链接:https://atcoder.jp/contests/abc140/tasks/abc140_e 题目大意 给定一个 1~N 的排列 P. 定义$X_{L, R}$的值为$P_L, P_{ ...

  9. 利用select单线程点对点聊天

    select的优点与使用方法 select用单线程的方法遍历所有待读写的I/O接口, 当有接口可用时就会返回. select可设置电脑阻塞或非阻塞. 特别注意: 每次select前都要重新初始化集合和 ...

  10. 【软件安装】——Robot Framework

    Robot Framework安装(win10) 一. 安装python 1.安装python2.7到本地,双击安装包进行安装,一般放入D盘,文件名默认Python27: 安装完成后进行版本检验,调出 ...