新增Login工具,修改部分bug

This commit is contained in:
2021-09-08 16:33:33 +08:00
parent fe58127686
commit bfdad93d83
21 changed files with 158 additions and 12 deletions

View File

@@ -6,11 +6,13 @@ import cn.hutool.setting.Setting;
import com.eg.www.common.CommonConstants;
import com.eg.www.common.utils.AliYunPanUtil;
import com.eg.www.common.utils.FileUtil;
import com.eg.www.common.utils.Login;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.*;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
/**
@@ -51,6 +53,16 @@ public class AliYunPan extends JFrame implements ActionListener {
// 迭代二单选框
private JRadioButton fenLeiRadio;
/*
//登陆按钮
private JButton loginBtn = CommonConstants.loginBtn;
//账号框
private JTextField usernameText = CommonConstants.userNameText;
//密码框
private JTextField pwdText = CommonConstants.pwdText;
*/
// 开始备份
private JButton startBackup = CommonConstants.startBackup;
// 暂停备份
@@ -130,13 +142,16 @@ public class AliYunPan extends JFrame implements ActionListener {
*/
JLabel pathTitle = new JLabel("选择目录");
pathText = new JTextField();
JLabel tokenTitle = new JLabel("Token");
//tokenText = new JTextField();
JLabel folderTitle = new JLabel("备份目录名称");
folderText = new JTextField();
JLabel backTitle = new JLabel("备份模式");
backTitle.setBounds(title_left, 150, title_width, title_high);
container.add(backTitle);
// 路径选择区域
JPanel selectPanle = new JPanel();
selectPanle.setLayout(null);
@@ -262,6 +277,7 @@ public class AliYunPan extends JFrame implements ActionListener {
//暂停按钮
if (e.getSource() == pauseBackup) {
aliYunPanUtil.stopBackup();
JOptionPane.showMessageDialog(null, "此功能正在开发中...", "提示", JOptionPane.INFORMATION_MESSAGE);
}
}

View File

@@ -24,6 +24,17 @@ public class CommonConstants {
public static JScrollBar scrollBar = consolePane.getVerticalScrollBar();
// Token文本框
public static JTextField tokenText = new JTextField();
/*
// 账号框
public static JTextField userNameText = new JTextField();
// 密码框
public static JTextField pwdText = new JTextField();
//登陆按钮
public static JButton loginBtn = new JButton("登陆");
*/
//开始备份按钮
public static JButton startBackup = new JButton("开始备份");
//当前路径

View File

@@ -76,6 +76,16 @@ public class AliYunPanUtil{
return;
}
/**
* 暂停备份
*/
public void stopBackup() {
CommonConstants.addConsole("暂停成功");
startBackup.setText("开始暂停");
startBackup.setEnabled(false);
CommonConstants.BACK_STATE = false;
}
/**
* 上传二级文件夹
* @param fileId

View File

@@ -0,0 +1,70 @@
package com.eg.www.common.utils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import javax.swing.*;
import java.util.concurrent.TimeUnit;
/**
* @author: Eg
* @Date: 2021/9/8 13:19
*/
public class Login {
/**
* @param user 用户名
* @param pwd 密码
* @return token
*/
public static String getToken(String user, String pwd) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "src/main/resources/chromedriver.exe");
//谷歌浏览器
WebDriver driver = new ChromeDriver();
//设置访问网址
String baseurl = "https://www.aliyundrive.com/sign/in?spm=aliyundrive.index.0.0.2d836020snGCDV";
driver.get(baseurl);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
WebElement loginFrame = driver.findElement(By.className("login-frame")).findElement(By.tagName("iframe"));
WebElement frame = driver.switchTo().frame(loginFrame).findElement(By.id("alibaba-login-box"));
//点击切换到账号登陆
driver.switchTo().frame(frame).findElement(By.className("block0")).findElements(By.className("sms-login-link")).get(0).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//账号框 && 密码框
driver.findElement(By.name("fm-login-id")).sendKeys(user);
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.findElement(By.name("fm-login-password")).sendKeys(pwd);
Thread.sleep(2000L);
//登陆按钮
driver.findElement(By.className("password-login")).click();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//滑动验证
WebDriver yzm = driver.switchTo().frame("baxia-dialog-content");
WebElement moveButton = yzm.findElement(By.id("nc_1_n1z"));
Actions action = new Actions(yzm);
//移到滑块元素并悬停
action.moveToElement(moveButton).clickAndHold(moveButton);
action.dragAndDropBy(moveButton,270, 0).perform();
action.release();
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
//执行js脚本
String getToken = "JSON.parse(localStorage.getItem('token'))."+"refresh_token";
return ((JavascriptExecutor) driver).executeScript(getToken).toString();
}
}

View File

@@ -26,7 +26,7 @@ public class OkHttpUtil {
/**
* 阿里云盘交互的POST请求
* @param url
* @param url https://websv.aliyundrive.com/token/refresh
* @param data
* @return
* @throws Exception
@@ -65,7 +65,7 @@ public class OkHttpUtil {
/**
* 阿里云盘上传文件的POST请求
* @param url
* @param url https://api.aliyundrive.com/v2/file/create
* @param data
* @return
* @throws Exception

View File

@@ -1,10 +0,0 @@
package com.eg.www.common.utils;
/**
* @author: Eg
* @Date: 2021/8/29 17:50
*/
public class getToken {
}