最右.apk(点击下载) / CommonParamInterception.java


package com.sina.weibo.sdk.network.intercept;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import com.sina.weibo.sdk.auth.Oauth2AccessToken;
import com.sina.weibo.sdk.net.HttpManager;
import com.sina.weibo.sdk.network.IRequestIntercept;
import com.sina.weibo.sdk.network.IRequestParam;
import com.sina.weibo.sdk.network.exception.InterceptException;
import com.sina.weibo.sdk.utils.AidTask;
import com.sina.weibo.sdk.utils.LogUtil;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class CommonParamInterception implements IRequestIntercept {
    public static String aidInfo;
    private static String appKey;

    private File getAidInfoFile(int i, Context context) {
        File filesDir = context.getFilesDir();
        return new File(filesDir, "weibo_sdk_aid" + i);
    }

    private static String getTimestamp() {
        return String.valueOf(System.currentTimeMillis() / 1000);
    }

    public static void setAppKey(String str) {
        appKey = str;
    }

    @Override // com.sina.weibo.sdk.network.IRequestIntercept
    public boolean doIntercept(IRequestParam iRequestParam, Bundle bundle) throws InterceptException {
        Bundle bundle2;
        String str;
        if (TextUtils.isEmpty(aidInfo)) {
            aidInfo = loadAidFromCache(iRequestParam.getContext());
        }
        if (TextUtils.isEmpty(aidInfo)) {
            try {
                aidInfo = AidTask.getInstance(iRequestParam.getContext()).loadAidFromNet();
            } catch (Exception unused) {
            }
        }
        if (!TextUtils.isEmpty(aidInfo)) {
            if (!TextUtils.isEmpty(aidInfo)) {
                bundle.putString("aid", aidInfo);
            }
            String url = iRequestParam.getUrl();
            if (!TextUtils.isEmpty(url)) {
                url.startsWith("https://api.weibo.cn/2/sdk/login");
            }
            IRequestParam.RequestType method = iRequestParam.getMethod();
            IRequestParam.RequestType requestType = IRequestParam.RequestType.GET;
            if (method == requestType) {
                bundle2 = iRequestParam.getGetBundle();
            } else {
                bundle2 = iRequestParam.getPostBundle();
            }
            Object obj = bundle2.get("access_token");
            Object obj2 = bundle2.get(Oauth2AccessToken.KEY_REFRESH_TOKEN);
            Object obj3 = bundle2.get("phone");
            if (obj != null && (obj instanceof String)) {
                str = (String) obj;
            } else if (obj2 == null || !(obj2 instanceof String)) {
                str = (obj3 == null || !(obj3 instanceof String)) ? "" : (String) obj3;
            } else {
                str = (String) obj2;
            }
            String timestamp = getTimestamp();
            bundle.putString("oauth_timestamp", timestamp);
            bundle.putString("oauth_sign", HttpManager.getOauthSign(iRequestParam.getContext(), aidInfo, str, appKey, timestamp));
            LogUtil.e("weiboSdk param", aidInfo + "  " + timestamp + "  " + appKey + "   " + str);
            if (iRequestParam.getMethod() == requestType) {
                iRequestParam.getGetBundle().remove("appKey");
                return false;
            }
            iRequestParam.getPostBundle().remove("appKey");
            return false;
        }
        throw new InterceptException("aid get error");
    }

    public String loadAidFromCache(Context context) {
        AidTask.AidInfo loadAidInfoFromCache = loadAidInfoFromCache(context);
        if (loadAidInfoFromCache == null || loadAidInfoFromCache.getAid() == null) {
            return "";
        }
        return loadAidInfoFromCache.getAid();
    }

    /* JADX WARNING: Exception block dominator not found, dom blocks: [] */
    /* JADX WARNING: Missing exception handler attribute for start block: B:18:0x002e */
    /* JADX WARNING: Removed duplicated region for block: B:16:0x002b A[SYNTHETIC, Splitter:B:16:0x002b] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x0032 A[SYNTHETIC, Splitter:B:23:0x0032] */
    public synchronized AidTask.AidInfo loadAidInfoFromCache(Context context) {
        FileInputStream fileInputStream;
        Throwable th;
        FileInputStream fileInputStream2 = null;
        try {
            fileInputStream = new FileInputStream(getAidInfoFile(1, context));
            try {
                byte[] bArr = new byte[fileInputStream.available()];
                fileInputStream.read(bArr);
                AidTask.AidInfo parseJson = AidTask.AidInfo.parseJson(new String(bArr));
                try {
                    fileInputStream.close();
                } catch (IOException unused) {
                }
                return parseJson;
            } catch (Exception unused2) {
                if (fileInputStream != null) {
                }
                return null;
            } catch (Throwable th2) {
                th = th2;
                fileInputStream2 = fileInputStream;
                if (fileInputStream2 != null) {
                }
                throw th;
            }
        } catch (Exception unused3) {
            fileInputStream = null;
            if (fileInputStream != null) {
                try {
                    fileInputStream.close();
                } catch (IOException unused4) {
                }
            }
            return null;
        } catch (Throwable th3) {
            th = th3;
            if (fileInputStream2 != null) {
                fileInputStream2.close();
            }
            throw th;
        }
    }

    @Override // com.sina.weibo.sdk.network.IRequestIntercept
    public boolean needIntercept(IRequestParam iRequestParam, Bundle bundle) {
        return true;
    }
}