新增Login工具,修改部分bug

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

View File

@ -10,4 +10,9 @@
</profile> </profile>
</annotationProcessing> </annotationProcessing>
</component> </component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_OVERRIDE">
<module name="aliyunpan-autobackup" options="-extdirs src/main/webapp/WEB-INF/lib/" />
</option>
</component>
</project> </project>

View File

@ -6,6 +6,11 @@
<option name="name" value="Central Repository" /> <option name="name" value="Central Repository" />
<option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" /> <option name="url" value="http://maven.aliyun.com/nexus/content/groups/public/" />
</remote-repository> </remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository> <remote-repository>
<option name="id" value="central" /> <option name="id" value="central" />
<option name="name" value="Maven Central repository" /> <option name="name" value="Maven Central repository" />

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RunConfigurationProducerService">
<option name="ignoredProducers">
<set>
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
</set>
</option>
</component>
</project>

5
back_config.setting Normal file
View File

@ -0,0 +1,5 @@
[]
tokenText =
pathText =
folderText =
backType = 0

24
pom.xml
View File

@ -41,6 +41,16 @@
<artifactId>flatlaf</artifactId> <artifactId>flatlaf</artifactId>
<version>0.26</version> <version>0.26</version>
</dependency> </dependency>
<dependency>
<groupId>org.opencb.opencga</groupId>
<artifactId>opencga</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
@ -85,7 +95,21 @@
<artifactId>maven-project-info-reports-plugin</artifactId> <artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version> <version>3.0.0</version>
</plugin> </plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${jdk-source.version}</source>
<target>${jdk-target.version}</target>
<encoding>UTF-8</encoding>
<compilerArguments>
<!--加载手工添加的jar包-->
<extdirs>src/main/webapp/WEB-INF/lib/</extdirs>
</compilerArguments>
</configuration>
<version>${maven-compiler-plugin.version}</version>
</plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
</build> </build>

View File

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

View File

@ -24,6 +24,17 @@ public class CommonConstants {
public static JScrollBar scrollBar = consolePane.getVerticalScrollBar(); public static JScrollBar scrollBar = consolePane.getVerticalScrollBar();
// Token文本框 // Token文本框
public static JTextField tokenText = new JTextField(); 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("开始备份"); public static JButton startBackup = new JButton("开始备份");
//当前路径 //当前路径

View File

@ -76,6 +76,16 @@ public class AliYunPanUtil{
return; return;
} }
/**
* 暂停备份
*/
public void stopBackup() {
CommonConstants.addConsole("暂停成功");
startBackup.setText("开始暂停");
startBackup.setEnabled(false);
CommonConstants.BACK_STATE = false;
}
/** /**
* 上传二级文件夹 * 上传二级文件夹
* @param fileId * @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请求 * 阿里云盘交互的POST请求
* @param url * @param url https://websv.aliyundrive.com/token/refresh
* @param data * @param data
* @return * @return
* @throws Exception * @throws Exception
@ -65,7 +65,7 @@ public class OkHttpUtil {
/** /**
* 阿里云盘上传文件的POST请求 * 阿里云盘上传文件的POST请求
* @param url * @param url https://api.aliyundrive.com/v2/file/create
* @param data * @param data
* @return * @return
* @throws Exception * @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 {
}

Binary file not shown.

Binary file not shown.

Binary file not shown.