老壳兼容
This commit is contained in:
parent
1a6f0f10ae
commit
253c057eb4
|
|
@ -6,7 +6,9 @@ import android.text.TextUtils;
|
|||
import com.github.catvod.ali.API;
|
||||
import com.github.catvod.bean.Result;
|
||||
import com.github.catvod.crawler.Spider;
|
||||
import com.github.catvod.utils.ReflectUtil;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
|
@ -21,7 +23,12 @@ public class Ali extends Spider {
|
|||
|
||||
@Override
|
||||
public void init(Context context, String extend) {
|
||||
String token = getToken();
|
||||
//适配其他tvbox或者老版本tvbox,要先判断有没有getToken方法,调用setToken也是一样的
|
||||
Method method = ReflectUtil.getMethod(this, "getToken");
|
||||
String token = "";
|
||||
if (method != null) {
|
||||
token = getToken();
|
||||
}
|
||||
API.get().setRefreshToken(TextUtils.isEmpty(token) ? extend : token);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package com.github.catvod.utils;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ReflectUtil {
|
||||
/**
|
||||
* @Description: 判断是否包含某个方法
|
||||
*/
|
||||
public static Method getMethod(Object object, String methodName, Class<?> ... parameterTypes){
|
||||
Method method = null ;
|
||||
|
||||
for(Class<?> clazz = object.getClass() ; clazz != Object.class ; clazz = clazz.getSuperclass()) {
|
||||
try {
|
||||
method = clazz.getMethod(methodName,parameterTypes) ;
|
||||
return method ;
|
||||
} catch (Exception e) {
|
||||
//这里甚么都不要做!并且这里的异常必须这样写,不能抛出去。
|
||||
//如果这里的异常打印或者往外抛,则就不会执行clazz = clazz.getSuperclass(),最后就不会进入到父类中了
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue