更新依赖

百合会签到改为模拟登陆行为
WebClient导入Cookie修复时间异常问题
This commit is contained in:
Yutousama 2022-06-27 10:02:47 +08:00
parent 8ddfc339dd
commit 299bc17758
5 changed files with 40 additions and 17 deletions

View File

@ -81,24 +81,24 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.1.4</version>
<version>4.2.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.1.4</version>
<version>4.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>4.1.4</version>
<version>4.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-remote-driver</artifactId>
<version>4.1.4</version>
<version>4.2.1</version>
</dependency>

View File

@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class QQBotApplication {
public static final String version="QQBot v.1.2.28";
public static final String version="QQBot v.1.2.29";
public static void main(String[] args) {
System.out.println("version = " + version);
SpringApplication.run(QQBotApplication.class, args);

View File

@ -6,7 +6,6 @@ import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*;
import org.openqa.selenium.By;
import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
@ -37,7 +36,7 @@ public class BaiHeHui extends Model {
try {
if (sign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到成功");
}else{
} else {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到失败");
}
} catch (Exception e) {
@ -57,19 +56,24 @@ public class BaiHeHui extends Model {
JSONArray array = JSON.parseArray(cookie);
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get("https://bbs.yamibo.com/forum.php");
driver.manage().deleteAllCookies();
login(driver);
// driver.manage().deleteAllCookies();
/* Thread.sleep(1000);
for (Cookie _cookie : WebClient.loadCookie(array)) {
System.err.println(_cookie);
driver.manage().addCookie(_cookie);
}
Thread.sleep(100);
}*/
try {
Thread.sleep(500);
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.navigate().refresh();
driver.get("https://bbs.yamibo.com/forum.php");
for (WebElement element : driver.findElements(By.xpath("//a"))) {
if ("打卡签到".equals(element.getText())) {
element.click();
element.click();
break;
}
}
@ -78,12 +82,24 @@ public class BaiHeHui extends Model {
e.printStackTrace();
return false;
} finally {
driver.close();
driver.quit();
driver.close();
driver.quit();
}
}
private void login(WebDriver driver) {
driver.get("https://bbs.yamibo.com/member.php?mod=logging&action=login");
driver.findElement(By.name("username")).sendKeys("z583819556");
driver.findElement(By.name("password")).sendKeys("u8fi4Qfr.5D2wZ5");
driver.findElement(By.name("loginsubmit")).submit();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
public static void main(String[] args) {
new BaiHeHui().sign();
}
}

View File

@ -154,6 +154,6 @@ public class Tsdm extends Model {
}
public static void main(String[] args) {
new Tsdm().tsdmSign();
}
}

View File

@ -38,14 +38,21 @@ public class WebClient {
boolean containsDate = json.containsKey("expirationDate");
long t = 0;
if (containsDate) {
t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000;
String _time=json.getString("expirationDate");
if(_time.contains(".")){
_time =_time.split("\\.")[0];
}
t = Long.parseLong(_time);
}else{
t=(System.currentTimeMillis())/1000;
}
t*=1000;
Cookie cookie = new Cookie(json.getString("name"),
json.getString("value"),
json.getString("domain"),
json.getString("path"),
containsDate ? new Date(t) : new Date(),
new Date(t),
json.getBooleanValue("secure"),
json.getBooleanValue("httpOnly")