登录流程:
1.注册易码平台,通过易码平台获取 随机的手机号码
3.将平台中提供的手机号填入饿了么登录页
饿了么登录网址:https://h5.ele.me/login/#redirect=https%3A%2F%2Fh5.ele.me%2Fprofile%2F%23come_from%3Dlogout
可能需要点击滑块
4.点击验证码, 现在易码平台开始不断的获取饿了么短信内容,直到获取到短信时停止获取。
5.把获取到的短信,填入饿了么密码框中,点击登录 ok
二、流程大概就是这个流程, 现在看看程序流程
1.通过易码平台的接口获取手机号
短信接口:url=http://api.fxhyd.cn/appapi.aspx?callback=jQuery223020313014864680334_1554895202047&jsonp=MobileSeachJsonCallback&actionid=getmobile&token=自己的用户token&itemid=352&province=110000&city=0&isp=0&mobile=&excludeno=&_="+System.currentTimeMillis()+"049
"+System.currentTimeMillis()+"为时间戳
/**
* httpclient请求url返回短信内容
* */
public static String getHtmlByHttpclient(String url) throws ClientProtocolException, IOException{
//httpclient访问
CloseableHttpClient httpclient = HttpClients.createDefault();
HttpGet httpget = new HttpGet(url);
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
String ahtml = EntityUtils.toString(entity, "UTF-8");
httpget.releaseConnection();//释放连接
//System.out.println(ahtml);
return ahtml;
}
正常把自己的token放到url中,通过getHtmlByHttpclient这个get请求返回一个json字符串,其中就有手机号,自行获取
2.把获取的手机号放到饿了么登录框中
LoggerProvider.getBrowserLogger().setLevel(Level.SEVERE);
LoggerProvider.getIPCLogger().setLevel(Level.SEVERE);
LoggerProvider.getChromiumProcessLogger().setLevel(Level.SEVERE);
final Browser browser = new Browser();
BrowserView browserView = new BrowserView(browser);
BrowserPreferences preferences = browser.getPreferences();
preferences.setImagesEnabled(false);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(browserView, BorderLayout.CENTER);
frame.setSize(1000, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
invokeAndWaitReady(browser, new Runnable() {
public void run() {
// 加载路径
browser.loadURL("https://h5.ele.me/login/#redirect=https%3A%2F%2Fh5.ele.me%2Fprofile%2F%23come_from%3Dlogout");
}
});
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("已获取到的手机号:"+phoneNum);
//3.输入手机号(输入手机号必须用Robot,这个是控制鼠标和键盘, 这个工具类的代码我会贴在最后)
RobotUtil.mouseAndClick(600,240,phoneNum);
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
//4.点击验证码
browser.executeJavaScriptAndReturnValue("document.getElementsByClassName('CountButton-3e-kd')[0].click();");
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
//5.判断是否需要 滑动
if(Jsoup.parse(browser.getHTML()).text().contains("请按住滑块,拖动到最右边")){
RobotUtil.mouseAndMove();(必须用Robot,这个是控制鼠标和键盘, 这个工具类的代码我会贴在最后))
}
//6.获取手机短信验证码
String MessageTxt=getMessage(phoneNum); //这个不断获取短信验证码的方法贴上
System.out.println("MessageTxt="+MessageTxt);
String yzmtxt=MessageTxt.split("您的验证码是")[1].split(",")[0];
System.out.println("yzmtxt="+yzmtxt);
/**
* 获取手机短信验证码
* */
public static String getMessage(String phoneNum){
String messageurl="http://api.fxhyd.cn/appapi.aspx" +
"?callback=jQuery223020313014864680334_1554895202047" +
"&jsonp=GetSMSJsonCallback&actionid=getsms" +
"&token=自己的token" +
"&itemid=352&mobile="+phoneNum+"&release=1&_="+System.currentTimeMillis()+"124";
String MessageTxt="";
int nums=0;
while(true){
nums++;
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
try {
MessageTxt =HttpClientUtils.getHtmlByHttpclient(messageurl);
if(MessageTxt.contains("您的验证码是")){
return MessageTxt.replace("GetSMSJsonCallback(", "").replace(")", "");
}else{
System.out.println("获取第"+nums+"次短信验证码");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//7.释放手机号
clearPhone(phoneNum);
//8.把短信验证码放入并进行登录
RobotUtil.mouseAndClickyzm(600,320,yzmtxt);(必须用Robot,这个是控制鼠标和键盘, 这个工具类的代码我会贴在最后))
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
browser.getCookieStorage().deleteAll();
//9.点击登录按钮
browser.executeJavaScriptAndReturnValue("document.getElementsByClassName('SubmitButton-2wG4T')[0].click();");
try {
Thread.sleep(2000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
String cookiss="";
//10.打印登录后的cookie信息
for ( Cookie cok : browser.getCookieStorage().getAllCookies()) {
String ddd=cok.getName()+"="+cok.getValue()+";";
cookiss=cookiss+ddd;
}
System.err.println("cookiss="+cookiss);
//11关闭模拟器
CloseBrowser(browser,frame);
鼠标和键盘的工具类RobotUtil源码:--------------------------------------------------->
public class RobotUtil {
//输入手机号
public static void mouseAndClick(int x ,int y,String phoneNum){
Robot myRobot;
try {
myRobot = new Robot();
myRobot.mouseMove(x, y); // 移动鼠标到坐标(x,y)处
Thread.sleep(300);
myRobot.mousePress(KeyEvent.BUTTON1_DOWN_MASK); // 模拟按下鼠标左键
myRobot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); // 模拟释放鼠标左键
//输入字母手机号
char[] ar = phoneNum.toCharArray();//char数组
for(int i =0;i=840){
break;
}
}
myRobot.mouseRelease(KeyEvent.BUTTON1_DOWN_MASK); // 模拟释放鼠标左键
} catch (Exception e1) {
e1.printStackTrace();
}
}
}