Update ali api flow - part 3
This commit is contained in:
parent
dac8c20afb
commit
dcabc66a01
|
|
@ -125,11 +125,12 @@ public class API {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String alist(String url, JSONObject body) throws Exception {
|
private boolean alist(String url, JSONObject body) {
|
||||||
url = "https://api.nn.ci/alist/ali_open/" + url;
|
|
||||||
OkResult result = OkHttp.postJson(url, body.toString(), getHeader());
|
OkResult result = OkHttp.postJson(url, body.toString(), getHeader());
|
||||||
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
SpiderDebug.log(result.getCode() + "," + url + "," + result.getBody());
|
||||||
return result.getBody();
|
if (isManyRequest(result.getBody())) return false;
|
||||||
|
oauth = OAuth.objectFrom(result.getBody()).save();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String post(String url, JSONObject body) {
|
private String post(String url, JSONObject body) {
|
||||||
|
|
@ -206,7 +207,7 @@ public class API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void oauthRequest() {
|
private boolean oauthRequest() {
|
||||||
try {
|
try {
|
||||||
SpiderDebug.log("OAuth Request...");
|
SpiderDebug.log("OAuth Request...");
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
|
|
@ -214,37 +215,35 @@ public class API {
|
||||||
body.put("scope", "user:base,file:all:read,file:all:write");
|
body.put("scope", "user:base,file:all:read,file:all:write");
|
||||||
String url = "https://open.aliyundrive.com/oauth/users/authorize?client_id=" + BuildConfig.CLIENT_ID + "&redirect_uri=https://alist.nn.ci/tool/aliyundrive/callback&scope=user:base,file:all:read,file:all:write&state=";
|
String url = "https://open.aliyundrive.com/oauth/users/authorize?client_id=" + BuildConfig.CLIENT_ID + "&redirect_uri=https://alist.nn.ci/tool/aliyundrive/callback&scope=user:base,file:all:read,file:all:write&state=";
|
||||||
String result = auth(url, body.toString(), true);
|
String result = auth(url, body.toString(), true);
|
||||||
oauthRedirect(Code.objectFrom(result).getCode());
|
return oauthRedirect(Code.objectFrom(result).getCode());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void oauthRedirect(String code) {
|
private boolean oauthRedirect(String code) {
|
||||||
try {
|
try {
|
||||||
SpiderDebug.log("OAuth Redirect...");
|
SpiderDebug.log("OAuth Redirect...");
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("code", code);
|
body.put("code", code);
|
||||||
body.put("grant_type", "authorization_code");
|
body.put("grant_type", "authorization_code");
|
||||||
String result = alist("code", body);
|
return alist("https://api.nn.ci/alist/ali_open/code", body);
|
||||||
if (isManyRequest(result)) return;
|
|
||||||
oauth = OAuth.objectFrom(result).save();
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
oauth.clean().save();
|
oauth.clean().save();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean refreshOpenToken() {
|
private boolean refreshOpenToken() {
|
||||||
try {
|
try {
|
||||||
|
if (oauth.getRefreshToken().isEmpty()) return oauthRequest();
|
||||||
SpiderDebug.log("refreshOpenToken...");
|
SpiderDebug.log("refreshOpenToken...");
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("grant_type", "refresh_token");
|
body.put("grant_type", "refresh_token");
|
||||||
body.put("refresh_token", oauth.getRefreshToken());
|
body.put("refresh_token", oauth.getRefreshToken());
|
||||||
String result = alist("token", body);
|
return alist("https://api.nn.ci/alist/ali_open/token", body);
|
||||||
if (isManyRequest(result)) return false;
|
|
||||||
oauth = OAuth.objectFrom(result).save();
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
oauth.clean().save();
|
oauth.clean().save();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue