Update mobile token fetch

This commit is contained in:
FongMi 2023-05-03 15:33:31 +08:00
parent 59fe1d09da
commit 84c1ad8514
5 changed files with 41 additions and 7 deletions

View File

@ -7,6 +7,8 @@ import android.graphics.drawable.ColorDrawable;
import android.os.SystemClock; import android.os.SystemClock;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Gravity; import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
@ -79,6 +81,14 @@ public class API {
this.refreshToken = token; this.refreshToken = token;
} }
public Object[] getToken() {
Object[] result = new Object[3];
result[0] = 200;
result[1] = "text/plain";
result[2] = new ByteArrayInputStream(user.getRefreshToken().getBytes());
return result;
}
public void setShareId(String shareId) { public void setShareId(String shareId) {
this.shareId = shareId; this.shareId = shareId;
refreshShareToken(); refreshShareToken();
@ -178,6 +188,7 @@ public class API {
if (oauth.getAccessToken().isEmpty()) oauthRequest(); if (oauth.getAccessToken().isEmpty()) oauthRequest();
return true; return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace();
user.clean().save(); user.clean().save();
SpiderDebug.log(e); SpiderDebug.log(e);
stopService(); stopService();
@ -436,14 +447,35 @@ public class API {
private void getQRCode() { private void getQRCode() {
if (Utils.isMobile()) { if (Utils.isMobile()) {
user.setRefreshToken(refreshToken); Init.run(this::showInput);
refreshAccessToken();
} else { } else {
Data data = Data.objectFrom(OkHttp.string("https://passport.aliyundrive.com/newlogin/qrcode/generate.do?appName=aliyun_drive&fromSite=52&appName=aliyun_drive&appEntrance=web&isMobile=false&lang=zh_CN&returnUrl=&bizParams=&_bx-v=2.2.3")).getContent().getData(); String url = "https://passport.aliyundrive.com/newlogin/qrcode/generate.do?appName=aliyun_drive&fromSite=52&appName=aliyun_drive&appEntrance=web&isMobile=false&lang=zh_CN&returnUrl=&bizParams=&_bx-v=2.2.3";
Data data = Data.objectFrom(OkHttp.string(url)).getContent().getData();
Init.run(() -> showQRCode(data)); Init.run(() -> showQRCode(data));
} }
} }
private void showInput() {
try {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(Utils.dp2px(16), Utils.dp2px(16), Utils.dp2px(16), Utils.dp2px(16));
FrameLayout frame = new FrameLayout(Init.context());
EditText input = new EditText(Init.context());
frame.addView(input, params);
dialog = new AlertDialog.Builder(Init.getActivity()).setTitle("請輸入Token").setView(frame).setNegativeButton(android.R.string.cancel, null).setPositiveButton(android.R.string.ok, (dialog, which) -> onPositive(input.getText().toString())).show();
} catch (Exception ignored) {
}
}
private void onPositive(String text) {
dialog.dismiss();
Init.execute(() -> {
if (text.startsWith("http")) setToken(OkHttp.string(text));
else if (text.length() == 32) setToken(text);
else if (text.contains(":")) setToken(OkHttp.string("http://" + text + "/proxy?do=ali&type=token"));
});
}
private void showQRCode(Data data) { private void showQRCode(Data data) {
try { try {
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240)); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Utils.dp2px(240), Utils.dp2px(240));
@ -470,7 +502,8 @@ public class API {
} }
private void setToken(String value) { private void setToken(String value) {
Init.show("請重新進入播放頁"); SpiderDebug.log("Token:" + value);
Init.show("Token:" + value);
this.refreshToken = value; this.refreshToken = value;
refreshAccessToken(); refreshAccessToken();
stopService(); stopService();

View File

@ -41,9 +41,10 @@ public class Ali extends Spider {
return Result.get().url(url).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string(); return Result.get().url(url).subs(API.get().getSub(ids)).header(API.get().getHeader()).parse(0).string();
} }
public static Object[] vod(Map<String, String> params) { public static Object[] proxy(Map<String, String> params) {
String type = params.get("type"); String type = params.get("type");
if (type.equals("sub")) return API.get().proxySub(params); if (type.equals("sub")) return API.get().proxySub(params);
if (type.equals("token")) return API.get().getToken();
return null; return null;
} }
} }

View File

@ -17,7 +17,7 @@ public class Proxy extends Spider {
case "ck": case "ck":
return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream("ok".getBytes("UTF-8"))}; return new Object[]{200, "text/plain; charset=utf-8", new ByteArrayInputStream("ok".getBytes("UTF-8"))};
case "ali": case "ali":
return Ali.vod(params); return Ali.proxy(params);
case "webdav": case "webdav":
return WebDAV.vod(params); return WebDAV.vod(params);
default: default:

Binary file not shown.

View File

@ -1 +1 @@
dadcea0e365a64c6cd3c48b7dd948772 73d83409ac27b38de28c7eb6ddcc1c0f