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.util.e; import com.alipay.sdk.util.l; import e.a.b.d.a; import e.a.b.i.a; 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 { /* renamed from: e reason: collision with root package name */ private static final Map<String, b> f503e = new ConcurrentHashMap(); /* renamed from: f reason: collision with root package name */ private static long f504f = -1; public static final int g = 9000; public static final int h = 5000; public static final int i = 4001; public static final int j = 4000; private static final int k = 122; private volatile boolean a = false; /* renamed from: b reason: collision with root package name */ private final Activity f505b; /* renamed from: c reason: collision with root package name */ private b f506c; /* renamed from: d reason: collision with root package name */ private final Handler f507d = new Handler(Looper.getMainLooper()); public enum BizType { Invoice("20000920"), AccountAuth("20000067"), Deduct("60000157"); private String appId; private BizType(String str) { this.appId = str; } } /* access modifiers changed from: package-private */ public static /* synthetic */ class a { static final /* synthetic */ int[] a = new int[BizType.values().length]; /* JADX WARNING: Can't wrap try/catch for region: R(8:0|1|2|3|4|5|6|8) */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:3:0x0014 */ /* JADX WARNING: Missing exception handler attribute for start block: B:5:0x001f */ static { a[BizType.Deduct.ordinal()] = 1; a[BizType.AccountAuth.ordinal()] = 2; try { a[BizType.Invoice.ordinal()] = 3; } catch (NoSuchFieldError unused) { } } } public interface b { void a(int i, String str, Bundle bundle); } /* access modifiers changed from: private */ public final class c implements Runnable { final Bundle B0; final int t; final String u; /* synthetic */ c(OpenAuthTask openAuthTask, int i, String str, Bundle bundle, a aVar) { this(i, str, bundle); } public void run() { if (OpenAuthTask.this.f506c != null) { OpenAuthTask.this.f506c.a(this.t, this.u, this.B0); } } private c(int i, String str, Bundle bundle) { this.t = i; this.u = str; this.B0 = bundle; } } public OpenAuthTask(Activity activity) { this.f505b = activity; e.a.b.i.b.d().a(activity); } public void a(String str, BizType bizType, Map<String, String> map, b bVar, boolean z) { Activity activity = this.f505b; String valueOf = String.valueOf(map); e.a.b.i.a aVar = new e.a.b.i.a(activity, valueOf, "oa-" + bizType); this.f506c = bVar; if (a(aVar, str, bizType, map, z)) { com.alipay.sdk.app.c.a.b(this.f505b, aVar, "", aVar.f7242d); } } private boolean a(e.a.b.i.a aVar, String str, BizType bizType, Map<String, String> map, boolean z) { PackageInfo packageInfo; if (this.a) { this.f507d.post(new c(this, j, "该 OpenAuthTask 已在执行", null, null)); return true; } this.a = true; long elapsedRealtime = SystemClock.elapsedRealtime(); if (elapsedRealtime - f504f <= 3000) { this.f507d.post(new c(this, 5000, "3s 内重复支付", null, null)); return true; } f504f = elapsedRealtime; a.a(""); String a2 = l.a(32); HashMap hashMap = new HashMap(map); hashMap.put("mqpPkgName", this.f505b.getPackageName()); hashMap.put("mqpScene", "sdk"); List<a.b> o = e.a.b.d.a.p().o(); if (!e.a.b.d.a.p().g || o == null) { o = a.f520d; } l.b a3 = l.a(aVar, this.f505b, o); if (a3 != null && !a3.a(aVar) && !a3.a() && (packageInfo = a3.a) != null && packageInfo.versionCode >= 122) { try { HashMap<String, String> a4 = e.a.b.i.a.a(aVar); a4.put("ts_scheme", String.valueOf(SystemClock.elapsedRealtime())); hashMap.put("mqpLoc", new JSONObject(a4).toString()); } catch (Throwable unused) { this.f507d.post(new c(this, j, "业务参数错误", null, null)); return true; } String a5 = a(bizType, hashMap); f503e.put(a2, this.f506c); String str2 = null; try { str2 = a(elapsedRealtime, a2, bizType, a5); } catch (JSONException e2) { com.alipay.sdk.app.c.a.a(aVar, com.alipay.sdk.app.c.b.l, com.alipay.sdk.app.c.b.v0, e2); } if (TextUtils.isEmpty(str2)) { this.f507d.post(new c(this, j, "参数错误", 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(a3.a.packageName); try { com.alipay.sdk.app.c.a.b(aVar, com.alipay.sdk.app.c.b.l, com.alipay.sdk.app.c.b.c0, "" + elapsedRealtime); a.C0251a.a(aVar, a2); this.f505b.startActivity(intent); } catch (Throwable th) { com.alipay.sdk.app.c.a.a(aVar, com.alipay.sdk.app.c.b.l, "StartWalletEx", th); } return false; } else if (z) { hashMap.put("mqpScheme", String.valueOf(str)); hashMap.put("mqpNotifyName", a2); hashMap.put("mqpScene", "landing"); String a6 = a(bizType, hashMap); Intent intent2 = new Intent(this.f505b, H5OpenAuthActivity.class); intent2.putExtra("url", String.format("https://render.alipay.com/p/s/i?scheme=%s", Uri.encode(a6))); a.C0251a.a(aVar, intent2); this.f505b.startActivity(intent2); return false; } else { this.f507d.post(new c(this, i, "支付宝未安装或签名错误", 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.a[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 j2, String str, BizType bizType, String str2) throws JSONException { JSONObject jSONObject = new JSONObject(); jSONObject.put("startTime", String.valueOf(j2)); jSONObject.put("session", str); jSONObject.put("package", this.f505b.getPackageName()); if (bizType != null) { jSONObject.put("appId", bizType.appId); } jSONObject.put("sdkVersion", "h.a.3.7.7"); jSONObject.put("mqpURL", str2); return Base64.encodeToString(jSONObject.toString().getBytes(Charset.forName("UTF-8")), 2); } static void a(String str, int i2, String str2, Bundle bundle) { b remove = f503e.remove(str); if (remove != null) { try { remove.a(i2, str2, bundle); } catch (Throwable th) { e.a(th); } } } }