Ali support scan code
This commit is contained in:
parent
11b8ca624a
commit
3f16482614
|
|
@ -1,12 +1,24 @@
|
|||
package com.github.catvod.spider;
|
||||
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.bean.Vod;
|
||||
import com.github.catvod.bean.ali.Item;
|
||||
import com.github.catvod.net.OkHttpUtil;
|
||||
import com.github.catvod.utils.Misc;
|
||||
import com.github.catvod.utils.Prefers;
|
||||
import com.github.catvod.utils.Trans;
|
||||
|
||||
import org.json.JSONArray;
|
||||
|
|
@ -30,13 +42,14 @@ import java.util.regex.Pattern;
|
|||
public class Ali {
|
||||
|
||||
private final Pattern pattern = Pattern.compile("www.aliyundrive.com/s/([^/]+)(/folder/([^/]+))?");
|
||||
private final String refreshToken;
|
||||
private static String accessToken;
|
||||
private String refreshToken;
|
||||
private ImageView code;
|
||||
|
||||
public Ali(String token) {
|
||||
if (TextUtils.isEmpty(token)) Init.show("尚未設定 Token");
|
||||
if (token.startsWith("http")) token = OkHttpUtil.string(token);
|
||||
refreshToken = token;
|
||||
refreshToken = Prefers.getString("token", token);
|
||||
}
|
||||
|
||||
private static HashMap<String, String> getHeaders() {
|
||||
|
|
@ -162,8 +175,8 @@ public class Ali {
|
|||
JSONObject object = new JSONObject(post("https://auth.aliyundrive.com/v2/account/token", body));
|
||||
accessToken = object.getString("token_type") + " " + object.getString("access_token");
|
||||
} catch (JSONException e) {
|
||||
Init.show("Token 已失效");
|
||||
e.printStackTrace();
|
||||
getToken();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -264,4 +277,38 @@ public class Ali {
|
|||
result[2] = new ByteArrayInputStream(text.getBytes());
|
||||
return result;
|
||||
}
|
||||
|
||||
private void getToken() {
|
||||
Misc.loadWebView("https://easy-token.cooluc.com/", new WebViewClient() {
|
||||
@Override
|
||||
public void onLoadResource(WebView view, String url) {
|
||||
if (url.endsWith("/ck")) {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> view.evaluateJavascript("document.getElementsByTagName('input')[0].value", value -> saveToken(value)), 1000);
|
||||
} else if (url.endsWith("/qr")) {
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> view.evaluateJavascript("document.getElementsByTagName('img')[0].src", value -> showQRCode(value)), 1000);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void saveToken(String value) {
|
||||
if (value.length() == 2) return;
|
||||
Prefers.put("token", refreshToken = value.replace("\"", ""));
|
||||
Init.show("請重新進入播放頁");
|
||||
code.setVisibility(View.GONE);
|
||||
Misc.removeView(code);
|
||||
}
|
||||
|
||||
private void showQRCode(String value) {
|
||||
code = new ImageView(Init.context());
|
||||
code.setPadding(Misc.dp2px(20), Misc.dp2px(20), Misc.dp2px(20), Misc.dp2px(20));
|
||||
code.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
code.setBackgroundColor(Color.WHITE);
|
||||
byte[] bytes = Base64.decode(value.split("base64,")[1], Base64.DEFAULT);
|
||||
code.setImageBitmap(BitmapFactory.decodeByteArray(bytes, 0, bytes.length));
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(Misc.dp2px(250), Misc.dp2px(250));
|
||||
Init.show("請使用阿里雲盤 App 掃描二維碼");
|
||||
params.gravity = Gravity.CENTER;
|
||||
Misc.addView(code, params);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
|
@ -143,14 +146,31 @@ public class Misc {
|
|||
}
|
||||
}
|
||||
|
||||
public static DisplayMetrics getDisplayMetrics() {
|
||||
return Init.context().getResources().getDisplayMetrics();
|
||||
}
|
||||
|
||||
public static int dp2px(int dp) {
|
||||
return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getDisplayMetrics());
|
||||
}
|
||||
|
||||
public static void addView(View view, ViewGroup.LayoutParams params) {
|
||||
ViewGroup group = Init.getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
group.addView(view, params);
|
||||
}
|
||||
|
||||
public static void removeView(View view) {
|
||||
ViewGroup group = Init.getActivity().getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
group.removeView(view);
|
||||
}
|
||||
|
||||
public static void loadWebView(String url, WebViewClient client) {
|
||||
Init.run(() -> {
|
||||
WebView webView = new WebView(Init.context());
|
||||
webView.getSettings().setDatabaseEnabled(true);
|
||||
webView.getSettings().setDomStorageEnabled(true);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(0, 0);
|
||||
Init.getActivity().addContentView(webView, params);
|
||||
addView(webView, new ViewGroup.LayoutParams(0, 0));
|
||||
webView.setWebViewClient(client);
|
||||
webView.loadUrl(url);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,53 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
import static android.content.Context.MODE_PRIVATE;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.github.catvod.spider.Init;
|
||||
|
||||
public class Prefers {
|
||||
|
||||
private static SharedPreferences getPrefers() {
|
||||
return Init.context().getSharedPreferences(Init.context().getPackageName() + "_preferences", MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static String getString(String key, String defaultValue) {
|
||||
return getPrefers().getString(key, defaultValue);
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
return getString(key, "");
|
||||
}
|
||||
|
||||
public static int getInt(String key, int defaultValue) {
|
||||
return getPrefers().getInt(key, defaultValue);
|
||||
}
|
||||
|
||||
public static int getInt(String key) {
|
||||
return getInt(key, 0);
|
||||
}
|
||||
|
||||
public static boolean getBoolean(String key, boolean defaultValue) {
|
||||
return getPrefers().getBoolean(key, defaultValue);
|
||||
}
|
||||
|
||||
public static boolean getBoolean(String key) {
|
||||
return getPrefers().getBoolean(key, false);
|
||||
}
|
||||
|
||||
public static void put(String key, Object obj) {
|
||||
if (obj == null) return;
|
||||
if (obj instanceof String) {
|
||||
getPrefers().edit().putString(key, (String) obj).apply();
|
||||
} else if (obj instanceof Boolean) {
|
||||
getPrefers().edit().putBoolean(key, (Boolean) obj).apply();
|
||||
} else if (obj instanceof Float) {
|
||||
getPrefers().edit().putFloat(key, (Float) obj).apply();
|
||||
} else if (obj instanceof Integer) {
|
||||
getPrefers().edit().putInt(key, (Integer) obj).apply();
|
||||
} else if (obj instanceof Long) {
|
||||
getPrefers().edit().putLong(key, (Long) obj).apply();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:background="#000000">
|
||||
|
||||
</FrameLayout>
|
||||
Binary file not shown.
|
|
@ -1 +1 @@
|
|||
cdac5d0feef2fb20bb47496ec835a0a2
|
||||
ada79cfb8f05a9146ecc90b844b760b9
|
||||
|
|
|
|||
Loading…
Reference in New Issue