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.m.a; import com.alipay.sdk.m.s.a; import com.alipay.sdk.m.u.e; import com.alipay.sdk.m.u.n; import com.autonavi.amap.mapcore.AMapEngineUtils; import com.jd.push.common.constant.Constants; import io.dcloud.common.constant.AbsoluteConst; 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 int Duplex = 5000; public static final int NOT_INSTALLED = 4001; public static final int OK = 9000; public static final int SYS_ERR = 4000; /* renamed from: e reason: collision with root package name */ public static final Map<String, Callback> f2009e = new ConcurrentHashMap(); /* renamed from: f reason: collision with root package name */ public static long f2010f = -1; /* renamed from: g reason: collision with root package name */ public static final int f2011g = 122; /* renamed from: a reason: collision with root package name */ public volatile boolean f2012a = false; /* renamed from: b reason: collision with root package name */ public final Activity f2013b; /* renamed from: c reason: collision with root package name */ public Callback f2014c; /* renamed from: d reason: collision with root package name */ public final Handler f2015d = 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[] f2016a; /* 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]; f2016a = iArr; iArr[BizType.Deduct.ordinal()] = 1; f2016a[BizType.AccountAuth.ordinal()] = 2; try { f2016a[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 f2017a; /* renamed from: b reason: collision with root package name */ public final String f2018b; /* renamed from: c reason: collision with root package name */ public final Bundle f2019c; public /* synthetic */ b(OpenAuthTask openAuthTask, int i, String str, Bundle bundle, a aVar) { this(i, str, bundle); } public void run() { if (OpenAuthTask.this.f2014c != null) { OpenAuthTask.this.f2014c.onResult(this.f2017a, this.f2018b, this.f2019c); } } public b(int i, String str, Bundle bundle) { this.f2017a = i; this.f2018b = str; this.f2019c = bundle; } } public OpenAuthTask(Activity activity) { this.f2013b = activity; com.alipay.sdk.m.s.b.d().a(activity); } public void execute(String str, BizType bizType, Map<String, String> map, Callback callback, boolean z) { Activity activity = this.f2013b; String valueOf = String.valueOf(map); com.alipay.sdk.m.s.a aVar = new com.alipay.sdk.m.s.a(activity, valueOf, "oa-" + bizType); this.f2014c = callback; if (a(aVar, str, bizType, map, z)) { com.alipay.sdk.m.k.a.b(this.f2013b, aVar, "", aVar.f2399d); } } private boolean a(com.alipay.sdk.m.s.a aVar, String str, BizType bizType, Map<String, String> map, boolean z) { PackageInfo packageInfo; if (this.f2012a) { this.f2015d.post(new b(this, 4000, "该 OpenAuthTask 已在执行", null, null)); return true; } this.f2012a = true; long elapsedRealtime = SystemClock.elapsedRealtime(); if (elapsedRealtime - f2010f <= com.alipay.sdk.m.u.b.f2418a) { this.f2015d.post(new b(this, 5000, "3s 内重复支付", null, null)); return true; } f2010f = elapsedRealtime; com.alipay.sdk.m.j.a.a(""); String a2 = n.a(32); HashMap hashMap = new HashMap(map); hashMap.put("mqpPkgName", this.f2013b.getPackageName()); hashMap.put("mqpScene", "sdk"); List<a.b> l = com.alipay.sdk.m.m.a.D().l(); if (!com.alipay.sdk.m.m.a.D().h || l == null) { l = com.alipay.sdk.m.j.a.f2182d; } n.c a3 = n.a(aVar, this.f2013b, l); if (a3 != null && !a3.a(aVar) && !a3.a() && (packageInfo = a3.f2476a) != null && packageInfo.versionCode >= 122) { try { HashMap<String, String> a4 = com.alipay.sdk.m.s.a.a(aVar); a4.put("ts_scheme", String.valueOf(SystemClock.elapsedRealtime())); hashMap.put("mqpLoc", new JSONObject(a4).toString()); } catch (Throwable unused) { this.f2015d.post(new b(this, 4000, "业务参数错误", null, null)); return true; } String a5 = a(bizType, hashMap); f2009e.put(a2, this.f2014c); String str2 = null; try { str2 = a(elapsedRealtime, a2, bizType, a5); } catch (JSONException e2) { com.alipay.sdk.m.k.a.a(aVar, com.alipay.sdk.m.k.b.l, com.alipay.sdk.m.k.b.q0, e2); } if (TextUtils.isEmpty(str2)) { this.f2015d.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(Constants.JdPushMsg.JSON_KEY_PayLOad, str2).build()); intent.addFlags(AMapEngineUtils.MAX_P20_WIDTH); intent.setPackage(a3.f2476a.packageName); try { com.alipay.sdk.m.k.a.a(aVar, com.alipay.sdk.m.k.b.l, com.alipay.sdk.m.k.b.Y, "" + elapsedRealtime); a.C0044a.a(aVar, a2); this.f2013b.startActivity(intent); } catch (Throwable th) { com.alipay.sdk.m.k.a.a(aVar, com.alipay.sdk.m.k.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.f2013b, H5OpenAuthActivity.class); intent2.putExtra("url", String.format("https://render.alipay.com/p/s/i?scheme=%s", Uri.encode(a6))); a.C0044a.a(aVar, intent2); this.f2013b.startActivity(intent2); return false; } else { this.f2015d.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.f2016a[bizType.ordinal()] == 1) { appendQueryParameter.appendQueryParameter("appClearTop", AbsoluteConst.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.f2013b.getPackageName()); if (bizType != null) { jSONObject.put("appId", bizType.appId); } jSONObject.put("sdkVersion", "h.a.3.8.11"); 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 = f2009e.remove(str); if (remove != null) { try { remove.onResult(i, str2, bundle); } catch (Throwable th) { e.a(th); } } } }