新增NicePT签到
新增https工具
This commit is contained in:
parent
7cb003544b
commit
b4484f1424
@ -4,6 +4,7 @@ import com.yutou.qqbot.QQBotManager;
|
|||||||
import com.yutou.qqbot.QQNumberManager;
|
import com.yutou.qqbot.QQNumberManager;
|
||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
import com.yutou.qqbot.models.WebSign.BaiHeHui;
|
import com.yutou.qqbot.models.WebSign.BaiHeHui;
|
||||||
|
import com.yutou.qqbot.models.WebSign.NicePT;
|
||||||
import com.yutou.qqbot.models.WebSign.Tsdm;
|
import com.yutou.qqbot.models.WebSign.Tsdm;
|
||||||
import com.yutou.qqbot.utlis.AppTools;
|
import com.yutou.qqbot.utlis.AppTools;
|
||||||
import com.yutou.qqbot.utlis.Log;
|
import com.yutou.qqbot.utlis.Log;
|
||||||
@ -159,6 +160,13 @@ public class AdminMessage extends Message {
|
|||||||
QQBotManager.getInstance().sendMessage(qq,"百合会签到失败:"+AppTools.getExceptionString(e));
|
QQBotManager.getInstance().sendMessage(qq,"百合会签到失败:"+AppTools.getExceptionString(e));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
new NicePT().sign();
|
||||||
|
}catch (Exception e){
|
||||||
|
sign=false;
|
||||||
|
QQBotManager.getInstance().sendMessage(qq,"NicePT签到失败:"+AppTools.getExceptionString(e));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
if(sign){
|
if(sign){
|
||||||
QQBotManager.getInstance().sendMessage(qq,"签到任务完成");
|
QQBotManager.getInstance().sendMessage(qq,"签到任务完成");
|
||||||
}
|
}
|
||||||
|
66
src/main/java/com/yutou/qqbot/models/WebSign/NicePT.java
Normal file
66
src/main/java/com/yutou/qqbot/models/WebSign/NicePT.java
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
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.*;
|
||||||
|
import org.openqa.selenium.Cookie;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class NicePT extends Model {
|
||||||
|
@Override
|
||||||
|
public boolean isUserPublic() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getUsePowers() {
|
||||||
|
return new String[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTime(String time) {
|
||||||
|
super.onTime(time);
|
||||||
|
if ("08:01:00".equals(time)) {
|
||||||
|
Log.i("开始天使动漫签到");
|
||||||
|
try {
|
||||||
|
sign();
|
||||||
|
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成NicePT的签到");
|
||||||
|
} catch (Exception e) {
|
||||||
|
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "NicePT签到失败:" + AppTools.getExceptionString(e));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sign(){
|
||||||
|
String url="https://www.nicept.net/attendance.php";
|
||||||
|
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("nicept.json")));
|
||||||
|
if (array == null) {
|
||||||
|
System.err.println("array is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WebDriver driver = WebClient.getInstance().getWebDriver();
|
||||||
|
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
|
||||||
|
driver.get(url);
|
||||||
|
for (Cookie _cookie : WebClient.loadCookie(array)) {
|
||||||
|
driver.manage().addCookie(_cookie);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
driver.get(url);
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
driver.close();
|
||||||
|
driver.quit();
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ package com.yutou.qqbot.utlis;
|
|||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.yutou.qqbot.interfaces.DownloadInterface;
|
import com.yutou.qqbot.interfaces.DownloadInterface;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import javax.net.ssl.HttpsURLConnection;
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
@ -14,7 +15,7 @@ public class HttpTools {
|
|||||||
private static final int HttpRequestIndex = 3;
|
private static final int HttpRequestIndex = 3;
|
||||||
|
|
||||||
public static String get(String url) {
|
public static String get(String url) {
|
||||||
return https_get(url, null);
|
return http_get(url,null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String post(final String url, final byte[] body) {
|
public static String post(final String url, final byte[] body) {
|
||||||
@ -27,29 +28,45 @@ public class HttpTools {
|
|||||||
|
|
||||||
public static String https_get(String url, Map<String, String> header) {
|
public static String https_get(String url, Map<String, String> header) {
|
||||||
try {
|
try {
|
||||||
URLConnection connection;
|
HttpsURLConnection connection;
|
||||||
connection = new URL(url).openConnection();
|
connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||||
connection.setRequestProperty("User-Agent", getExtUa());
|
return urlConnection(header, connection);
|
||||||
if (header != null) {
|
|
||||||
for (String key : header.keySet()) {
|
|
||||||
connection.addRequestProperty(key, header.get(key));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
connection.connect();
|
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
|
||||||
StringBuilder str = new StringBuilder();
|
|
||||||
String tmp;
|
|
||||||
while ((tmp = reader.readLine()) != null) {
|
|
||||||
str.append(tmp);
|
|
||||||
}
|
|
||||||
reader.close();
|
|
||||||
return str.toString();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("error url = " + url);
|
System.err.println("error url = " + url);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public static String http_get(String url,Map<String,String> header){
|
||||||
|
try {
|
||||||
|
HttpURLConnection connection;
|
||||||
|
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
return urlConnection(header, connection);
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("error url = " + url);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static String urlConnection(Map<String, String> header, HttpURLConnection connection) throws IOException {
|
||||||
|
connection.setRequestProperty("User-Agent", getExtUa());
|
||||||
|
if (header != null) {
|
||||||
|
for (String key : header.keySet()) {
|
||||||
|
connection.addRequestProperty(key, header.get(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection.connect();
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||||
|
StringBuilder str = new StringBuilder();
|
||||||
|
String tmp;
|
||||||
|
while ((tmp = reader.readLine()) != null) {
|
||||||
|
str.append(tmp);
|
||||||
|
}
|
||||||
|
reader.close();
|
||||||
|
return str.toString();
|
||||||
|
}
|
||||||
|
|
||||||
public static String http_post(String url, byte[] body, int index, Map<String, String> headers) {
|
public static String http_post(String url, byte[] body, int index, Map<String, String> headers) {
|
||||||
String tmp;
|
String tmp;
|
||||||
|
@ -62,8 +62,8 @@ public class WebClient {
|
|||||||
ChromeOptions options = new ChromeOptions();
|
ChromeOptions options = new ChromeOptions();
|
||||||
// options.addArguments("--disable-gpu");
|
// options.addArguments("--disable-gpu");
|
||||||
// options.addArguments("blink-settings=imagesEnabled=false");
|
// options.addArguments("blink-settings=imagesEnabled=false");
|
||||||
options.addArguments("--headless");
|
// options.addArguments("--headless");
|
||||||
options.addArguments("--no-sandbox");
|
// options.addArguments("--no-sandbox");
|
||||||
// options.addArguments("--incognito");
|
// options.addArguments("--incognito");
|
||||||
options.addArguments("--disable-plugins");
|
options.addArguments("--disable-plugins");
|
||||||
options.addArguments("--lang=zh-CN");
|
options.addArguments("--lang=zh-CN");
|
||||||
|
Loading…
Reference in New Issue
Block a user