Update ali api flow - part 1

This commit is contained in:
FongMi 2023-05-11 02:04:28 +08:00
parent 5d4d95d7de
commit dac8c20afb
1 changed files with 11 additions and 9 deletions

View File

@ -128,10 +128,8 @@ public class API {
private String alist(String url, JSONObject body) throws Exception {
url = "https://api.nn.ci/alist/ali_open/" + url;
OkResult result = OkHttp.postJson(url, body.toString(), getHeader());
if (isManyRequest(result.getBody())) return "";
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
if (result.getCode() == 200) return result.getBody();
throw new Exception(result.getBody());
return result.getBody();
}
private String post(String url, JSONObject body) {
@ -160,7 +158,6 @@ public class API {
if (!result.contains("Too Many Requests")) return false;
Init.show("洗洗睡吧Too Many Requests。");
oauth.clean().save();
user.clean().save();
return true;
}
@ -229,7 +226,9 @@ public class API {
JSONObject body = new JSONObject();
body.put("code", code);
body.put("grant_type", "authorization_code");
oauth = OAuth.objectFrom(alist("code", body)).save();
String result = alist("code", body);
if (isManyRequest(result)) return;
oauth = OAuth.objectFrom(result).save();
} catch (Exception e) {
e.printStackTrace();
oauth.clean().save();
@ -242,12 +241,14 @@ public class API {
JSONObject body = new JSONObject();
body.put("grant_type", "refresh_token");
body.put("refresh_token", oauth.getRefreshToken());
oauth = OAuth.objectFrom(alist("token", body)).save();
String result = alist("token", body);
if (isManyRequest(result)) return false;
oauth = OAuth.objectFrom(result).save();
return true;
} catch (Exception e) {
e.printStackTrace();
oauth.clean().save();
return true;
return false;
}
}
@ -495,8 +496,9 @@ public class API {
private void startService(Map<String, String> params) {
service = Executors.newScheduledThreadPool(1);
service.scheduleAtFixedRate(() -> {
Data result = Data.objectFrom(OkHttp.post("https://passport.aliyundrive.com/newlogin/qrcode/query.do?appName=aliyun_drive&fromSite=52&_bx-v=2.2.3", params)).getContent().getData();
if (result.hasToken()) setToken(result.getToken());
String result = OkHttp.post("https://passport.aliyundrive.com/newlogin/qrcode/query.do?appName=aliyun_drive&fromSite=52&_bx-v=2.2.3", params);
Data data = Data.objectFrom(result).getContent().getData();
if (data.hasToken()) setToken(data.getToken());
}, 1, 1, TimeUnit.SECONDS);
}