package com.yutou.qqbot.models.WebSign; import com.alibaba.fastjson.JSONArray; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.Model; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.StringUtils; import com.yutou.qqbot.utlis.WebClient; import net.mamoe.mirai.event.events.MessageEvent; import org.openqa.selenium.By; import org.openqa.selenium.Cookie; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import java.io.File; import java.util.concurrent.TimeUnit; import static com.yutou.qqbot.utlis.WebClient.getOptions; public class Tsdm extends Model { @Override public boolean isUserPublic() { return false; } @Override public String[] getUsePowers() { return new String[]{ QQFromCommands.TSDM_PAY }; } @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); if(msg.startsWith(QQFromCommands.TSDM_PAY)){ String url=msg.replace(QQFromCommands.TSDM_PAY,"").trim(); if(StringUtils.isEmpty(url)){ QQBotManager.getInstance().sendMessage(qq,"使用说明:!tsdm [url]"); return; } QQBotManager.getInstance().sendMessage(qq,"正在获取,请稍等..."); QQBotManager.getInstance().sendMessage(qq,tsdm(url)); } } @Override public void onTime(String time) { super.onTime(time); if("08:00".equals(time)){ tsdmSign(); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"已完成天使动漫的签到"); } } public void tsdmSign(){ JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json"))); if (array == null) { System.err.println("array is null"); return; } WebDriver driver =WebClient.getInstance().getWebDriver(); driver.get("https://www.tsdm39.net/forum.php"); getTsdm(array, driver); try { ((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')"); }catch (Exception ignored){ } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } driver.findElement(By.id("wl")).click(); driver.findElement(By.xpath("//input[@value='3']")).click(); driver.findElement(By.id("qiandao")).submit(); driver.close(); driver.quit(); } private void getTsdm(JSONArray array, WebDriver driver) { driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } for (Cookie cookie : WebClient.loadCookie(array)) { driver.manage().addCookie(cookie); } driver.navigate().refresh(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } public String tsdm(String url) { JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json"))); if (array == null) { System.err.println("array is null"); return null; } WebDriver driver =WebClient.getInstance().getWebDriver(); driver.get(url); getTsdm(array, driver); try { ((JavascriptExecutor) driver).executeScript("document.getElementsByClassName('y viewpay')[0].click()"); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } driver.findElement(By.id("payform")).submit(); } catch (Exception ignored) { } String body = driver.findElement(By.name("tsdmlz")).getText(); driver.close(); driver.quit(); return body; } }