修复FastJSON大版本更新后API变动

This commit is contained in:
Yutousama 2022-04-28 09:50:33 +08:00
parent f1ed4be143
commit 7943606dc0
22 changed files with 103 additions and 88 deletions

View File

@ -58,8 +58,8 @@
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson</artifactId> <artifactId>fastjson2</artifactId>
<version>2.0.1</version> <version>2.0.1</version>
</dependency> </dependency>

View File

@ -1,6 +1,6 @@
package com.yutou.qqbot.Controllers; package com.yutou.qqbot.Controllers;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.utlis.AppTools; import com.yutou.qqbot.utlis.AppTools;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.Controllers; package com.yutou.qqbot.Controllers;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.models.XiaoMi.MiRouter; import com.yutou.qqbot.models.XiaoMi.MiRouter;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
import com.yutou.qqbot.utlis.RedisTools; import com.yutou.qqbot.utlis.RedisTools;
@ -23,7 +24,7 @@ public class MiRouterDevices {
if (data == null) { if (data == null) {
array = new JSONArray(); array = new JSONArray();
} else { } else {
array = JSONArray.parseArray(data); array = JSON.parseArray(data);
} }
for (Object o : array) { for (Object o : array) {
JSONObject item = (JSONObject) o; JSONObject item = (JSONObject) o;
@ -47,9 +48,9 @@ public class MiRouterDevices {
if (data == null) { if (data == null) {
array = new JSONArray(); array = new JSONArray();
} else { } else {
array = JSONArray.parseArray(data); array = JSON.parseArray(data);
} }
JSONArray _array= (JSONArray) array.clone(); JSONArray _array= JSON.parseArray(array.toString());
for (Object o : array) { for (Object o : array) {
JSONObject item = (JSONObject) o; JSONObject item = (JSONObject) o;
if (item.getString("mac").equals(getRemoteAddress(request.getRemoteAddr()))) { if (item.getString("mac").equals(getRemoteAddress(request.getRemoteAddr()))) {
@ -62,7 +63,7 @@ public class MiRouterDevices {
} }
private String getRemoteAddress(String ip) { private String getRemoteAddress(String ip) {
JSONObject data = JSONObject.parseObject(HttpTools.get(XiaoMiRouter.getDeviceListUrl())); JSONObject data = JSON.parseObject(HttpTools.get(XiaoMiRouter.getDeviceListUrl()));
if (data.getInteger("code") == 0) { if (data.getInteger("code") == 0) {
JSONArray array=data.getJSONArray("list"); JSONArray array=data.getJSONArray("list");
for (Object o : array) { for (Object o : array) {

View File

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

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot; package com.yutou.qqbot;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.utlis.Log; import com.yutou.qqbot.utlis.Log;
import com.yutou.qqbot.utlis.RedisTools; import com.yutou.qqbot.utlis.RedisTools;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
@ -49,7 +50,7 @@ public class QQNumberManager {
} }
public boolean addPower(Long qq, String power){ public boolean addPower(Long qq, String power){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("power"); JSONArray array=json.getJSONArray("power");
array.add(power); array.add(power);
json.put("power",array); json.put("power",array);
@ -60,7 +61,7 @@ public class QQNumberManager {
public List<String> getPower(Long qq){ public List<String> getPower(Long qq){
List<String> list=new ArrayList<>(); List<String> list=new ArrayList<>();
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("power"); JSONArray array=json.getJSONArray("power");
for (Object power : array) { for (Object power : array) {
list.add((String) power); list.add((String) power);
@ -72,7 +73,7 @@ public class QQNumberManager {
public List<String> getUseModel(long qq) { public List<String> getUseModel(long qq) {
List<String> list=new ArrayList<>(); List<String> list=new ArrayList<>();
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("model"); JSONArray array=json.getJSONArray("model");
for (Object power : array) { for (Object power : array) {
list.add((String) power); list.add((String) power);
@ -83,7 +84,7 @@ public class QQNumberManager {
} }
public boolean delPower(Long qq, String power){ public boolean delPower(Long qq, String power){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("power"); JSONArray array=json.getJSONArray("power");
array.remove(power); array.remove(power);
json.put("power",array); json.put("power",array);
@ -93,7 +94,7 @@ public class QQNumberManager {
} }
public boolean addUseModel(Long qq,Class<?> modelClass){ public boolean addUseModel(Long qq,Class<?> modelClass){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("model"); JSONArray array=json.getJSONArray("model");
array.add(modelClass.getName()); array.add(modelClass.getName());
json.put("model",array); json.put("model",array);
@ -103,7 +104,7 @@ public class QQNumberManager {
} }
public boolean delUseModel(Long qq,Class<?> modelClass){ public boolean delUseModel(Long qq,Class<?> modelClass){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("model"); JSONArray array=json.getJSONArray("model");
array.remove(modelClass.getName()); array.remove(modelClass.getName());
json.put("model",array); json.put("model",array);
@ -113,7 +114,7 @@ public class QQNumberManager {
} }
public boolean isExistsPower(Long qq, String... power){ public boolean isExistsPower(Long qq, String... power){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("power"); JSONArray array=json.getJSONArray("power");
for (String key : power) { for (String key : power) {
if(!array.contains(key)){ if(!array.contains(key)){
@ -126,14 +127,14 @@ public class QQNumberManager {
} }
public boolean isGroup(Long qq){ public boolean isGroup(Long qq){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json= JSON.parseObject(RedisTools.get(qq));
return json.getBoolean("group"); return json.getBooleanValue("group");
} }
return false; return false;
} }
public boolean isUseModel(Long qq,Class<?> modelClass){ public boolean isUseModel(Long qq,Class<?> modelClass){
if(RedisTools.exists(qq,null)){ if(RedisTools.exists(qq,null)){
JSONObject json=JSONObject.parseObject(RedisTools.get(qq)); JSONObject json=JSON.parseObject(RedisTools.get(qq));
JSONArray array=json.getJSONArray("model"); JSONArray array=json.getJSONArray("model");
return array.contains(modelClass.getName()); return array.contains(modelClass.getName());
} }

View File

@ -1,7 +1,7 @@
package com.yutou.qqbot.bilibili; package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.interfaces.ObjectInterface;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
import lombok.Data; import lombok.Data;

View File

@ -1,9 +1,9 @@
package com.yutou.qqbot.bilibili; package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.ConfigTools;
import org.springframework.util.StringUtils; import com.yutou.qqbot.utlis.StringUtils;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.io.*; import java.io.*;
@ -109,7 +109,7 @@ public class BiliBiliUtils {
return ""; return "";
} }
JSONObject json = JSONObject.parseObject(ConfigTools.readFile(new File("bilibili.cookie"))); JSONObject json = JSON.parseObject(ConfigTools.readFile(new File("bilibili.cookie")));
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (String s : json.keySet()) { for (String s : json.keySet()) {
builder.append(s).append("=").append(json.getString(s)).append(";"); builder.append(s).append("=").append(json.getString(s)).append(";");

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.bilibili; package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.ConfigTools;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
@ -15,7 +16,7 @@ public class BiliLogin {
public JSONObject login(){ public JSONObject login(){
JSONObject login= JSONObject.parseObject(HttpTools.get("https://passport.bilibili.com/qrcode/getLoginUrl")); JSONObject login= JSON.parseObject(HttpTools.get("https://passport.bilibili.com/qrcode/getLoginUrl"));
JSONObject json=new JSONObject(); JSONObject json=new JSONObject();
json.put("code",login.getInteger("code")); json.put("code",login.getInteger("code"));
json.put("url",login.getJSONObject("data").getString("url")); json.put("url",login.getJSONObject("data").getString("url"));
@ -33,7 +34,7 @@ public class BiliLogin {
cancel(); cancel();
return; return;
} }
JSONObject json=JSONObject.parseObject(HttpTools.post("https://passport.bilibili.com/qrcode/getLoginInfo",bd.getBytes(StandardCharsets.UTF_8))); JSONObject json=JSON.parseObject(HttpTools.post("https://passport.bilibili.com/qrcode/getLoginInfo",bd.getBytes(StandardCharsets.UTF_8)));
if(json.containsKey("code")&&json.getInteger("code")==0){ if(json.containsKey("code")&&json.getInteger("code")==0){
System.out.println("json = " + json); System.out.println("json = " + json);
String _url=json.getJSONObject("data").getString("url"); String _url=json.getJSONObject("data").getString("url");

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.models.Animal; package com.yutou.qqbot.models.Animal;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
@ -94,7 +95,7 @@ public class TurnipProphet extends Model {
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有本周数据,无法预测")); QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有本周数据,无法预测"));
return; return;
} }
JSONObject json = JSONObject.parseObject(data); JSONObject json = JSON.parseObject(data);
String prices = json.getString("prices"); String prices = json.getString("prices");
String pattern = null; String pattern = null;
if (json.containsKey("old_pattern")) { if (json.containsKey("old_pattern")) {
@ -132,7 +133,7 @@ public class TurnipProphet extends Model {
array = new JSONArray(); array = new JSONArray();
json = new JSONObject(); json = new JSONObject();
if (getDay() == 0 && !StringUtils.isEmpty(data)) { if (getDay() == 0 && !StringUtils.isEmpty(data)) {
json = JSONObject.parseObject(data); json = JSON.parseObject(data);
} }
array.add(-1); array.add(-1);
array.add(-1); array.add(-1);
@ -148,7 +149,7 @@ public class TurnipProphet extends Model {
array.add(-1); array.add(-1);
array.add(-1); array.add(-1);
} else { } else {
json = JSONObject.parseObject(data); json = JSON.parseObject(data);
array = json.getJSONArray("turnip"); array = json.getJSONArray("turnip");
} }
if (array.getInteger(0) == -1 && getDay() != 0) { if (array.getInteger(0) == -1 && getDay() != 0) {
@ -231,7 +232,7 @@ public class TurnipProphet extends Model {
return null; return null;
} }
JSONObject pr = JSONObject.parseObject(map.get(TurnipData.MODEL)); JSONObject pr = JSON.parseObject(map.get(TurnipData.MODEL));
JSONArray prArray = pr.getJSONArray(TurnipData.MODEL); JSONArray prArray = pr.getJSONArray(TurnipData.MODEL);
StringBuilder out = new StringBuilder(); StringBuilder out = new StringBuilder();
out.append("预测结果如下:\n"); out.append("预测结果如下:\n");
@ -350,7 +351,7 @@ public class TurnipProphet extends Model {
map.put(TurnipProphet.TurnipData.MIX, tmp[15]); map.put(TurnipProphet.TurnipData.MIX, tmp[15]);
map.put(TurnipProphet.TurnipData.MAX, tmp[16]); map.put(TurnipProphet.TurnipData.MAX, tmp[16]);
} else { } else {
if (!array.toJSONString().contains(tmp[0])) { if (!array.toJavaList(String.class).contains(tmp[0])) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put(TurnipProphet.TurnipData.MODEL, tmp[0]); json.put(TurnipProphet.TurnipData.MODEL, tmp[0]);
json.put(TurnipProphet.TurnipData.PR, tmp[1]); json.put(TurnipProphet.TurnipData.PR, tmp[1]);

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot.models.Commands; package com.yutou.qqbot.models.Commands;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
@ -48,7 +49,7 @@ public class Moyu extends Model {
private void downloadImage() { private void downloadImage() {
String ret = HttpTools.get("https://api.j4u.ink/proxy/remote/moyu.json"); String ret = HttpTools.get("https://api.j4u.ink/proxy/remote/moyu.json");
JSONObject json = JSONObject.parseObject(ret); JSONObject json = JSON.parseObject(ret);
HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() { HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() {
@Override @Override
public void onDownload(File file) { public void onDownload(File file) {

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot.models.WebSign; package com.yutou.qqbot.models.WebSign;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
@ -53,7 +54,7 @@ public class BaiHeHui extends Model {
} }
WebDriver driver = WebClient.getInstance().getWebDriver(); WebDriver driver = WebClient.getInstance().getWebDriver();
try { try {
JSONArray array = JSONArray.parseArray(cookie); JSONArray array = JSON.parseArray(cookie);
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get("https://bbs.yamibo.com/forum.php"); driver.get("https://bbs.yamibo.com/forum.php");
driver.manage().deleteAllCookies(); driver.manage().deleteAllCookies();

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot.models.WebSign; package com.yutou.qqbot.models.WebSign;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
@ -46,7 +47,7 @@ public class NicePT extends Model {
public boolean sign() { public boolean sign() {
String url = "https://www.nicept.net/attendance.php"; String url = "https://www.nicept.net/attendance.php";
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("nicept.json"))); JSONArray array = JSON.parseArray(ConfigTools.readFile(new File("nicept.json")));
if (array == null) { if (array == null) {
System.err.println("array is null"); System.err.println("array is null");
return false; return false;

View File

@ -1,6 +1,8 @@
package com.yutou.qqbot.models.WebSign; package com.yutou.qqbot.models.WebSign;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
@ -61,7 +63,7 @@ public class Tsdm extends Model {
} }
public boolean tsdmSign() { public boolean tsdmSign() {
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json"))); JSONArray array = JSON.parseArray(ConfigTools.readFile(new File("cookie.json")));
if (array == null) { if (array == null) {
System.err.println("array is null"); System.err.println("array is null");
return false; return false;
@ -126,7 +128,7 @@ public class Tsdm extends Model {
} }
public String tsdm(String url) { public String tsdm(String url) {
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json"))); JSONArray array = JSON.parseArray(ConfigTools.readFile(new File("cookie.json")));
if (array == null) { if (array == null) {
System.err.println("array is null"); System.err.println("array is null");
return null; return null;
@ -152,7 +154,6 @@ public class Tsdm extends Model {
} }
public static void main(String[] args) { public static void main(String[] args) {
boolean sign = new Tsdm().tsdmSign();
System.out.println("sign = " + sign);
} }
} }

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.models.XiaoMi; package com.yutou.qqbot.models.XiaoMi;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
@ -63,14 +64,14 @@ public class MiRouter extends Model {
} }
private void run()throws Exception{ private void run()throws Exception{
String url = XiaoMiRouter.getDeviceListUrl(); String url = XiaoMiRouter.getDeviceListUrl();
JSONObject json = JSONObject.parseObject(HttpTools.get(url)); JSONObject json = JSON.parseObject(HttpTools.get(url));
if (json.getInteger("code") == 0) { if (json.getInteger("code") == 0) {
String _tmp = RedisTools.get(redis_key); String _tmp = RedisTools.get(redis_key);
if (_tmp == null) { if (_tmp == null) {
return; return;
} }
JSONArray devices = JSONArray.parseArray(_tmp); JSONArray devices = JSON.parseArray(_tmp);
JSONArray devs = (JSONArray) devices.clone(); JSONArray devs =JSON.parseArray(devices.toString());
JSONArray array = json.getJSONArray("list"); JSONArray array = json.getJSONArray("list");
Set<String> links = new HashSet<>(); Set<String> links = new HashSet<>();
for (Object o : array) { for (Object o : array) {
@ -78,7 +79,7 @@ public class MiRouter extends Model {
for (Object device : devices) { for (Object device : devices) {
JSONObject _device = (JSONObject) device; JSONObject _device = (JSONObject) device;
devs.remove(_device); devs.remove(_device);
if (_device.getString("mac").equals(item.getString("mac")) && !_device.getBoolean("online")) { if (_device.getString("mac").equals(item.getString("mac")) && !_device.getBooleanValue("online")) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(item.getString("oname")); builder.append(item.getString("oname"));
builder.append(" 欢迎回家!").append("\n"); builder.append(" 欢迎回家!").append("\n");
@ -88,14 +89,14 @@ public class MiRouter extends Model {
_device.put("online", true); _device.put("online", true);
_device.put("name", item.getString("oname")); _device.put("name", item.getString("oname"));
} }
if (_device.getString("mac").equals(item.getString("mac")) && _device.getBoolean("online")) { if (_device.getString("mac").equals(item.getString("mac")) && _device.getBooleanValue("online")) {
links.add(_device.getString("mac")); links.add(_device.getString("mac"));
_device.put("linkTime", Long.parseLong(item.getJSONObject("statistics").getString("online"))); _device.put("linkTime", Long.parseLong(item.getJSONObject("statistics").getString("online")));
} }
devs.add(_device); devs.add(_device);
} }
} }
devices = (JSONArray) devs.clone(); devices = JSON.parseArray(devs.toString());
for (Object device : devices) { for (Object device : devices) {
JSONObject item = (JSONObject) device; JSONObject item = (JSONObject) device;
if (!links.contains(item.getString("mac")) && item.getLong("linkTime") != 0) { if (!links.contains(item.getString("mac")) && item.getLong("linkTime") != 0) {
@ -110,7 +111,7 @@ public class MiRouter extends Model {
devs.add(item); devs.add(item);
} }
} }
RedisTools.set(redis_key, devs.toJSONString()); RedisTools.set(redis_key, devs.toString());
}else { }else {
XiaoMiRouter.setNotToken(); XiaoMiRouter.setNotToken();
} }

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.models.setu; package com.yutou.qqbot.models.setu;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
@ -64,7 +65,7 @@ public class GetSeTu extends Model {
redis.close(); redis.close();
MessageChainBuilder builder = null; MessageChainBuilder builder = null;
if (!StringUtils.isEmpty(ret)) { if (!StringUtils.isEmpty(ret)) {
JSONArray array = JSONArray.parseArray(ret); JSONArray array = JSON.parseArray(ret);
builder = new MessageChainBuilder(); builder = new MessageChainBuilder();
builder.append("各位老色胚们晚上好,现在公布本群涩图数据!"); builder.append("各位老色胚们晚上好,现在公布本群涩图数据!");
builder.append("\n"); builder.append("\n");
@ -147,7 +148,7 @@ public class GetSeTu extends Model {
String redis = RedisTools.get("Setu_" + qq); String redis = RedisTools.get("Setu_" + qq);
JSONArray array = new JSONArray(); JSONArray array = new JSONArray();
if (!StringUtils.isEmpty(redis)) { if (!StringUtils.isEmpty(redis)) {
array = JSONArray.parseArray(redis); array = JSON.parseArray(redis);
} }
array.add(data); array.add(data);
RedisTools.set("Setu_" + qq, array.toString()); RedisTools.set("Setu_" + qq, array.toString());
@ -182,7 +183,7 @@ public class GetSeTu extends Model {
} }
System.out.println("url = " + url); System.out.println("url = " + url);
String ret = HttpTools.get(url); String ret = HttpTools.get(url);
JSONObject json = JSONObject.parseObject(ret); JSONObject json = JSON.parseObject(ret);
if (json.getJSONArray("data").size() == 0) { if (json.getJSONArray("data").size() == 0) {
return false; return false;
} }
@ -194,7 +195,7 @@ public class GetSeTu extends Model {
builder.append(item.getInteger("pid")); builder.append(item.getInteger("pid"));
builder.append("\n"); builder.append("\n");
builder.append("R18:"); builder.append("R18:");
if (item.getBoolean("r18")) { if (item.getBooleanValue("r18")) {
builder.append("YES!"); builder.append("YES!");
} else { } else {
builder.append("NO~"); builder.append("NO~");

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.models.setu; package com.yutou.qqbot.models.setu;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.Annotations.UseModel;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
@ -35,8 +36,8 @@ public class QQSetu extends Model {
Log.i("今日涩图 redisKey = " + redisKey); Log.i("今日涩图 redisKey = " + redisKey);
String js = RedisTools.get(redisKey, db_print); String js = RedisTools.get(redisKey, db_print);
if (js != null) { if (js != null) {
JSONObject json = JSONObject.parseObject(js); JSONObject json = JSON.parseObject(js);
if(json.containsKey("isPrint")&&json.getBoolean("isPrint")){ if(json.containsKey("isPrint")&&json.getBooleanValue("isPrint")){
return; return;
} }
Map<String,Float> groupAverage=new HashMap<>(); Map<String,Float> groupAverage=new HashMap<>();
@ -128,7 +129,7 @@ public class QQSetu extends Model {
} }
private void printSetu(long group) { private void printSetu(long group) {
JSONObject jt = JSONObject.parseObject(RedisTools.get(group+"setu", db_user)); JSONObject jt = JSON.parseObject(RedisTools.get(group+"setu", db_user));
String id = jt.getString("id"); String id = jt.getString("id");
float average = 0; float average = 0;
float max = 0; float max = 0;
@ -169,7 +170,7 @@ public class QQSetu extends Model {
if (st == null) { if (st == null) {
json = new JSONObject(); json = new JSONObject();
} else { } else {
json = JSONObject.parseObject(st); json = JSON.parseObject(st);
} }
if (!json.containsKey(id)) { if (!json.containsKey(id)) {
JSONObject item; JSONObject item;

View File

@ -1,7 +1,8 @@
package com.yutou.qqbot.utlis; package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
@ -25,7 +26,7 @@ public class BangumiTools {
*/ */
public static JSONObject getBangumi(int day) { public static JSONObject getBangumi(int day) {
String str = HttpTools.get(toDayBangumi); String str = HttpTools.get(toDayBangumi);
JSONArray main = JSONArray.parseArray(str); JSONArray main = JSON.parseArray(str);
if (day == -1) { if (day == -1) {
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
json.put("bangumi", main); json.put("bangumi", main);
@ -60,7 +61,7 @@ public class BangumiTools {
*/ */
public static JSONObject getBangumiInfo(int id) { public static JSONObject getBangumiInfo(int id) {
String str = HttpTools.get(String.format(BangumiInfo, id + "")); String str = HttpTools.get(String.format(BangumiInfo, id + ""));
return JSONObject.parseObject(str); return JSON.parseObject(str);
} }
public static JSONArray getPeople(int id) { public static JSONArray getPeople(int id) {
@ -117,7 +118,7 @@ public class BangumiTools {
*/ */
public static JSONObject search(String key) { public static JSONObject search(String key) {
String str = HttpTools.get(String.format(SearchBangumi, URLEncoder.encode(key, StandardCharsets.UTF_8))); String str = HttpTools.get(String.format(SearchBangumi, URLEncoder.encode(key, StandardCharsets.UTF_8)));
return JSONObject.parseObject(str); return JSON.parseObject(str);
} }
/** /**

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot.utlis; package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import java.io.*; import java.io.*;
@ -44,7 +45,7 @@ public class ConfigTools {
String src = readFile(file); String src = readFile(file);
if (src != null) { if (src != null) {
try { try {
JSONObject json = JSONObject.parseObject(src); JSONObject json = JSON.parseObject(src);
return json.getObject(key, t); return json.getObject(key, t);
} catch (Exception e) { } catch (Exception e) {
} }
@ -80,7 +81,7 @@ public class ConfigTools {
if (src == null) { if (src == null) {
src = "{}"; src = "{}";
} }
JSONObject json = JSONObject.parseObject(src); JSONObject json = JSON.parseObject(src);
json.put(key, data); json.put(key, data);
saveFile(file, json.toJSONString()); saveFile(file, json.toJSONString());
return false; return false;

View File

@ -1,6 +1,6 @@
package com.yutou.qqbot.utlis; package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.DownloadInterface;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot.utlis; package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.interfaces.ObjectInterface;
import redis.clients.jedis.Jedis; import redis.clients.jedis.Jedis;
@ -292,7 +293,7 @@ public class RedisTools {
public static void bot(String value) { public static void bot(String value) {
switch (value) { switch (value) {
case "getip": case "getip":
JSONObject json = JSONObject.parseObject(HttpTools.get("https://api.asilu.com/ip/")); JSONObject json = JSON.parseObject(HttpTools.get("https://api.asilu.com/ip/"));
String ip = json.getString("ip"); String ip = json.getString("ip");
QQBotManager.getInstance().sendMessage("服务器IP:\n" + ip); QQBotManager.getInstance().sendMessage("服务器IP:\n" + ip);
break; break;

View File

@ -1,7 +1,7 @@
package com.yutou.qqbot.utlis; package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSONObject;
import org.openqa.selenium.Cookie; import org.openqa.selenium.Cookie;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeDriver;
@ -49,8 +49,8 @@ public class WebClient {
json.getString("domain"), json.getString("domain"),
json.getString("path"), json.getString("path"),
containsDate ? new Date(t) : new Date(), containsDate ? new Date(t) : new Date(),
json.containsKey("secure")?json.getBoolean("secure"):false, json.getBooleanValue("secure"),
json.containsKey("httpOnly")?json.getBoolean("httpOnly"):false json.getBooleanValue("httpOnly")
); );
list.add(cookie); list.add(cookie);

View File

@ -1,6 +1,7 @@
package com.yutou.qqbot.utlis; package com.yutou.qqbot.utlis;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@ -24,7 +25,7 @@ public class XiaoMiRouter {
json.put("password", oldPwd); json.put("password", oldPwd);
json.put("logtype", 2); json.put("logtype", 2);
json.put("nonce", nonce); json.put("nonce", nonce);
json = JSONObject.parseObject(HttpTools.http_post("http://192.168.31.1/cgi-bin/luci/api/xqsystem/login", HttpTools.toUrlParams(json).getBytes(StandardCharsets.UTF_8), 1, null)); json = JSON.parseObject(HttpTools.http_post("http://192.168.31.1/cgi-bin/luci/api/xqsystem/login", HttpTools.toUrlParams(json).getBytes(StandardCharsets.UTF_8), 1, null));
if (json.getInteger("code") == 0) { if (json.getInteger("code") == 0) {
token = json.getString("token"); token = json.getString("token");
return token; return token;
@ -42,7 +43,7 @@ public class XiaoMiRouter {
public static void main(String[] args) { public static void main(String[] args) {
String url = XiaoMiRouter.getDeviceListUrl(); String url = XiaoMiRouter.getDeviceListUrl();
JSONObject json = JSONObject.parseObject(HttpTools.get(url)); JSONObject json = JSON.parseObject(HttpTools.get(url));
System.out.println("json = " + json); System.out.println("json = " + json);
} }
} }