得物.apk(点击下载) / OpenAuthTask.java


package com.alipay.sdk.app;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Base64;
import com.alipay.sdk.m.l.a;
import com.alipay.sdk.m.r.a;
import com.alipay.sdk.m.t.e;
import com.alipay.sdk.m.t.n;
import com.meizu.cloud.pushsdk.constants.PushConstants;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONException;
import org.json.JSONObject;

public final class OpenAuthTask {
    public static final Map<String, Callback> e = new ConcurrentHashMap();
    public static long f = -1;

    /* renamed from: a  reason: collision with root package name */
    public volatile boolean f3485a = false;
    public final Activity b;

    /* renamed from: c  reason: collision with root package name */
    public Callback f3486c;
    public final Handler d = new Handler(Looper.getMainLooper());

    public enum BizType {
        Invoice("20000920"),
        AccountAuth("20000067"),
        Deduct("60000157");
        
        public String appId;

        /* access modifiers changed from: public */
        BizType(String str) {
            this.appId = str;
        }
    }

    public interface Callback {
        void onResult(int i, String str, Bundle bundle);
    }

    public static /* synthetic */ class a {

        /* renamed from: a  reason: collision with root package name */
        public static final /* synthetic */ int[] f3487a;

        /* JADX WARNING: Can't wrap try/catch for region: R(6:0|1|2|3|4|(3:5|6|8)) */
        /* JADX WARNING: Failed to process nested try/catch */
        /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0012 */
        /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001d */
        static {
            int[] iArr = new int[BizType.values().length];
            f3487a = iArr;
            iArr[BizType.Deduct.ordinal()] = 1;
            f3487a[BizType.AccountAuth.ordinal()] = 2;
            try {
                f3487a[BizType.Invoice.ordinal()] = 3;
            } catch (NoSuchFieldError unused) {
            }
        }
    }

    public final class b implements Runnable {

        /* renamed from: a  reason: collision with root package name */
        public final int f3488a;
        public final String b;

        /* renamed from: c  reason: collision with root package name */
        public final Bundle f3489c;

        public /* synthetic */ b(OpenAuthTask openAuthTask, int i, String str, Bundle bundle, a aVar) {
            this(i, str, bundle);
        }

        public void run() {
            if (OpenAuthTask.this.f3486c != null) {
                OpenAuthTask.this.f3486c.onResult(this.f3488a, this.b, this.f3489c);
            }
        }

        public b(int i, String str, Bundle bundle) {
            this.f3488a = i;
            this.b = str;
            this.f3489c = bundle;
        }
    }

    public OpenAuthTask(Activity activity) {
        this.b = activity;
        com.alipay.sdk.m.r.b.d().a(activity);
    }

    public void execute(String str, BizType bizType, Map<String, String> map, Callback callback, boolean z) {
        Activity activity = this.b;
        String valueOf = String.valueOf(map);
        com.alipay.sdk.m.r.a aVar = new com.alipay.sdk.m.r.a(activity, valueOf, "oa-" + bizType);
        this.f3486c = callback;
        if (a(aVar, str, bizType, map, z)) {
            com.alipay.sdk.m.j.a.b(this.b, aVar, "", aVar.d);
        }
    }

    private boolean a(com.alipay.sdk.m.r.a aVar, String str, BizType bizType, Map<String, String> map, boolean z) {
        PackageInfo packageInfo;
        if (this.f3485a) {
            this.d.post(new b(this, 4000, "该 OpenAuthTask 已在执行", null, null));
            return true;
        }
        this.f3485a = true;
        long elapsedRealtime = SystemClock.elapsedRealtime();
        if (elapsedRealtime - f <= 3000) {
            this.d.post(new b(this, 5000, "3s 内重复支付", null, null));
            return true;
        }
        f = elapsedRealtime;
        com.alipay.sdk.m.i.a.a("");
        String a5 = n.a(32);
        HashMap hashMap = new HashMap(map);
        hashMap.put("mqpPkgName", this.b.getPackageName());
        hashMap.put("mqpScene", "sdk");
        List<a.b> l = com.alipay.sdk.m.l.a.z().l();
        if (!com.alipay.sdk.m.l.a.z().f3550g || l == null) {
            l = com.alipay.sdk.m.i.a.d;
        }
        n.c a12 = n.a(aVar, this.b, l);
        if (a12 != null && !a12.a(aVar) && !a12.a() && (packageInfo = a12.f3607a) != null && packageInfo.versionCode >= 122) {
            try {
                HashMap<String, String> a13 = com.alipay.sdk.m.r.a.a(aVar);
                a13.put("ts_scheme", String.valueOf(SystemClock.elapsedRealtime()));
                hashMap.put("mqpLoc", new JSONObject(a13).toString());
            } catch (Throwable unused) {
                this.d.post(new b(this, 4000, "业务参数错误", null, null));
                return true;
            }
            String a14 = a(bizType, hashMap);
            e.put(a5, this.f3486c);
            String str2 = null;
            try {
                str2 = a(elapsedRealtime, a5, bizType, a14);
            } catch (JSONException e6) {
                com.alipay.sdk.m.j.a.a(aVar, "biz", "JSONEx", e6);
            }
            if (TextUtils.isEmpty(str2)) {
                this.d.post(new b(this, 4000, "参数错误", null, null));
                return true;
            }
            Intent intent = new Intent("android.intent.action.VIEW", new Uri.Builder().scheme("alipays").authority("platformapi").path("startapp").appendQueryParameter("appId", "20001129").appendQueryParameter("payload", str2).build());
            intent.addFlags(268435456);
            intent.setPackage(a12.f3607a.packageName);
            try {
                com.alipay.sdk.m.j.a.a(aVar, "biz", "PgOpenStarting", "" + elapsedRealtime);
                a.C0082a.a(aVar, a5);
                this.b.startActivity(intent);
                try {
                    a31.a.a();
                } catch (Exception unused2) {
                }
            } catch (Throwable th2) {
                com.alipay.sdk.m.j.a.a(aVar, "biz", "StartWalletEx", th2);
            }
            return false;
        } else if (z) {
            hashMap.put("mqpScheme", String.valueOf(str));
            hashMap.put("mqpNotifyName", a5);
            hashMap.put("mqpScene", "landing");
            String a15 = a(bizType, hashMap);
            Intent intent2 = new Intent(this.b, H5OpenAuthActivity.class);
            intent2.putExtra(PushConstants.WEB_URL, String.format("https://render.alipay.com/p/s/i?scheme=%s", Uri.encode(a15)));
            a.C0082a.a(aVar, intent2);
            this.b.startActivity(intent2);
            try {
                a31.a.a();
            } catch (Exception unused3) {
            }
            return false;
        } else {
            this.d.post(new b(this, 4001, "支付宝未安装或签名错误", null, null));
            return true;
        }
    }

    private String a(BizType bizType, Map<String, String> map) {
        if (bizType != null) {
            Uri.Builder appendQueryParameter = new Uri.Builder().scheme("alipays").authority("platformapi").path("startapp").appendQueryParameter("appId", bizType.appId);
            if (a.f3487a[bizType.ordinal()] == 1) {
                appendQueryParameter.appendQueryParameter("appClearTop", "false").appendQueryParameter("startMultApp", "YES");
            }
            for (Map.Entry<String, String> entry : map.entrySet()) {
                appendQueryParameter.appendQueryParameter(entry.getKey(), entry.getValue());
            }
            return appendQueryParameter.build().toString();
        }
        throw new RuntimeException("missing bizType");
    }

    private String a(long j, String str, BizType bizType, String str2) throws JSONException {
        JSONObject jSONObject = new JSONObject();
        jSONObject.put("startTime", String.valueOf(j));
        jSONObject.put("session", str);
        jSONObject.put("package", this.b.getPackageName());
        if (bizType != null) {
            jSONObject.put("appId", bizType.appId);
        }
        jSONObject.put("sdkVersion", "h.a.3.8.10");
        jSONObject.put("mqpURL", str2);
        return Base64.encodeToString(jSONObject.toString().getBytes(Charset.forName("UTF-8")), 2);
    }

    public static void a(String str, int i, String str2, Bundle bundle) {
        Callback remove = e.remove(str);
        if (remove != null) {
            try {
                remove.onResult(i, str2, bundle);
            } catch (Throwable th2) {
                e.a(th2);
            }
        }
    }
}