Update API.java
This commit is contained in:
parent
39872860bd
commit
63acd722fe
|
|
@ -90,7 +90,7 @@ public class API {
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HashMap<String, String> getHeaderAuthOpen() {
|
private HashMap<String, String> getHeaderOpen() {
|
||||||
HashMap<String, String> headers = getHeader();
|
HashMap<String, String> headers = getHeader();
|
||||||
headers.put("authorization", auth.getAccessTokenOpen());
|
headers.put("authorization", auth.getAccessTokenOpen());
|
||||||
return headers;
|
return headers;
|
||||||
|
|
@ -113,15 +113,13 @@ public class API {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String auth(String url, String json, boolean retry) {
|
private String auth(String url, String json, boolean retry) {
|
||||||
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
return auth(url, json, getHeaderAuth(), retry);
|
||||||
String result = OkHttp.postJson(url, json, getHeaderAuth());
|
|
||||||
if (retry && check401(result)) return auth(url, json, false);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String authOpen(String url, String json, boolean retry) {
|
private String auth(String url, String json, Map<String, String> header, boolean retry) {
|
||||||
String result = OkHttp.postJson(url, json, getHeaderAuthOpen());
|
url = url.startsWith("https") ? url : "https://api.aliyundrive.com/" + url;
|
||||||
if (retry && check401Open(result)) return authOpen(url, json, false);
|
String result = OkHttp.postJson(url, json, header);
|
||||||
|
if (retry && check401(result)) return auth(url, json, header, false);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -139,11 +137,6 @@ public class API {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean check401Open(String result) {
|
|
||||||
if (result.contains("AccessTokenInvalid")) return refreshAccessTokenOpen();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkAccessToken() {
|
public void checkAccessToken() {
|
||||||
if (auth.getAccessToken().isEmpty()) refreshAccessToken();
|
if (auth.getAccessToken().isEmpty()) refreshAccessToken();
|
||||||
}
|
}
|
||||||
|
|
@ -178,9 +171,10 @@ public class API {
|
||||||
body.put("grant_type", "authorization_code");
|
body.put("grant_type", "authorization_code");
|
||||||
object = new JSONObject(post("https://api.nn.ci/alist/ali_open/code", body));
|
object = new JSONObject(post("https://api.nn.ci/alist/ali_open/code", body));
|
||||||
auth.setRefreshTokenOpen(object.getString("refresh_token"));
|
auth.setRefreshTokenOpen(object.getString("refresh_token"));
|
||||||
refreshAccessTokenOpen();
|
refreshOpenToken();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
SpiderDebug.log(e);
|
||||||
stopService();
|
stopService();
|
||||||
auth.clean();
|
auth.clean();
|
||||||
getQRCode();
|
getQRCode();
|
||||||
|
|
@ -190,22 +184,16 @@ public class API {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean refreshAccessTokenOpen() {
|
private void refreshOpenToken() throws Exception {
|
||||||
try {
|
SpiderDebug.log("refreshAccessTokenOpen...");
|
||||||
SpiderDebug.log("refreshAccessTokenOpen...");
|
JSONObject body = new JSONObject();
|
||||||
JSONObject body = new JSONObject();
|
String token = auth.getRefreshTokenOpen();
|
||||||
String token = auth.getRefreshTokenOpen();
|
body.put("refresh_token", token);
|
||||||
body.put("refresh_token", token);
|
body.put("grant_type", "refresh_token");
|
||||||
body.put("grant_type", "refresh_token");
|
JSONObject object = new JSONObject(OkHttp.postJson("https://api.nn.ci/alist/ali_open/token", body.toString(), getHeader()));
|
||||||
JSONObject object = new JSONObject(OkHttp.postJson("https://api.nn.ci/alist/ali_open/token", body.toString(), getHeader()));
|
auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token"));
|
||||||
auth.setAccessTokenOpen(object.optString("token_type") + " " + object.optString("access_token"));
|
auth.setRefreshTokenOpen(object.optString("refresh_token"));
|
||||||
auth.setRefreshTokenOpen(object.optString("refresh_token"));
|
auth.save();
|
||||||
auth.save();
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
refreshAccessToken();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean refreshShareToken() {
|
public boolean refreshShareToken() {
|
||||||
|
|
@ -243,6 +231,7 @@ public class API {
|
||||||
auth.save();
|
auth.save();
|
||||||
return true;
|
return true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
SpiderDebug.log(e);
|
||||||
auth.setSignature("");
|
auth.setSignature("");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -362,7 +351,7 @@ public class API {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("file_id", fileId);
|
body.put("file_id", fileId);
|
||||||
body.put("drive_id", auth.getDriveId());
|
body.put("drive_id", auth.getDriveId());
|
||||||
String url = new JSONObject(authOpen("https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl", body.toString(), true)).optString("url");
|
String url = new JSONObject(auth("https://open.aliyundrive.com/adrive/v1.0/openFile/getDownloadUrl", body.toString(), getHeaderOpen(), true)).optString("url");
|
||||||
Init.execute(() -> delete(fileId));
|
Init.execute(() -> delete(fileId));
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue