package com.alipay.sdk.app; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.os.SystemClock; import android.text.TextUtils; import com.alipay.sdk.app.PayResultActivity; import com.alipay.sdk.data.a; import com.alipay.sdk.packet.impl.f; import com.alipay.sdk.sys.a; import com.alipay.sdk.sys.b; import com.alipay.sdk.util.H5PayResultModel; import com.alipay.sdk.util.c; import com.alipay.sdk.util.e; import com.alipay.sdk.util.i; import com.alipay.sdk.util.l; import com.alipay.sdk.util.n; import com.tencent.smtt.sdk.TbsVideoCacheTask; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; import org.json.JSONObject; public class PayTask { /* renamed from: a reason: collision with root package name */ static final Object f1317a = e.class; private static long h = 0; private static long i = -1; private Activity b; private com.alipay.sdk.widget.a c; private String d = "wappaygw.alipay.com/service/rest.htm"; private String e = "mclient.alipay.com/service/rest.htm"; private String f = "mclient.alipay.com/home/exterfaceAssign.htm"; private Map<String, a> g = new HashMap(); public String getVersion() { return "15.7.4"; } public PayTask(Activity activity) { this.b = activity; b.a().a(this.b); this.c = new com.alipay.sdk.widget.a(activity, "去支付宝付款"); } public synchronized String pay(String str, boolean z) { return a(new com.alipay.sdk.sys.a(this.b, str, "pay"), str, z); } /* JADX INFO: finally extract failed */ private synchronized String a(com.alipay.sdk.sys.a aVar, String str, boolean z) { String str2; if (b()) { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "RepPay", ""); return j.d(); } if (z) { showLoading(); } if (str.contains("payment_inst=")) { String substring = str.substring(str.indexOf("payment_inst=") + 13); int indexOf = substring.indexOf(38); if (indexOf > 0) { substring = substring.substring(0, indexOf); } i.a(substring.replaceAll("\"", "").toLowerCase(Locale.getDefault()).replaceAll("alipay", "")); } else { i.a(""); } if (str.contains("service=alipay.acquire.mr.ord.createandpay")) { com.alipay.sdk.cons.a.c = true; } if (com.alipay.sdk.cons.a.c) { if (str.startsWith("https://wappaygw.alipay.com/home/exterfaceAssign.htm?")) { str = str.substring(str.indexOf("https://wappaygw.alipay.com/home/exterfaceAssign.htm?") + "https://wappaygw.alipay.com/home/exterfaceAssign.htm?".length()); } else if (str.startsWith("https://mclient.alipay.com/home/exterfaceAssign.htm?")) { str = str.substring(str.indexOf("https://mclient.alipay.com/home/exterfaceAssign.htm?") + "https://mclient.alipay.com/home/exterfaceAssign.htm?".length()); } } try { c.b("mspl", "pay prepared: " + str); str2 = a(str, aVar); c.b("mspl", "pay raw result: " + str2); i.a(aVar, this.b.getApplicationContext(), str2); com.alipay.sdk.app.statistic.a.b(aVar, "biz", "PgReturn", "" + SystemClock.elapsedRealtime()); com.alipay.sdk.data.a.j().a(aVar, this.b.getApplicationContext()); dismissLoading(); com.alipay.sdk.app.statistic.a.b(this.b.getApplicationContext(), aVar, str, aVar.f1351a); } catch (Throwable th) { com.alipay.sdk.app.statistic.a.b(aVar, "biz", "PgReturn", "" + SystemClock.elapsedRealtime()); com.alipay.sdk.data.a.j().a(aVar, this.b.getApplicationContext()); dismissLoading(); com.alipay.sdk.app.statistic.a.b(this.b.getApplicationContext(), aVar, str, aVar.f1351a); throw th; } c.b("mspl", "pay returning: " + str2); return str2; } public synchronized Map<String, String> payV2(String str, boolean z) { com.alipay.sdk.sys.a aVar; aVar = new com.alipay.sdk.sys.a(this.b, str, "payV2"); return l.a(aVar, a(aVar, str, z)); } public synchronized String fetchTradeToken() { return i.a(new com.alipay.sdk.sys.a(this.b, "", "fetchTradeToken"), this.b.getApplicationContext()); } public synchronized boolean payInterceptorWithUrl(String str, boolean z, H5PayCallback h5PayCallback) { String fetchOrderInfoFromH5PayUrl; fetchOrderInfoFromH5PayUrl = fetchOrderInfoFromH5PayUrl(str); if (!TextUtils.isEmpty(fetchOrderInfoFromH5PayUrl)) { c.b("mspl", "intercepted: " + fetchOrderInfoFromH5PayUrl); new Thread(new g(this, fetchOrderInfoFromH5PayUrl, z, h5PayCallback)).start(); } return !TextUtils.isEmpty(fetchOrderInfoFromH5PayUrl); } /* JADX WARNING: Code restructure failed: missing block: B:17:0x00e0, code lost: if (r9.startsWith("http://" + r16.e) != false) goto L_0x00e2; */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x0181, code lost: if (r9.startsWith("http://" + r16.f) != false) goto L_0x0183; */ /* JADX WARNING: Code restructure failed: missing block: B:8:0x003f, code lost: if (r9.startsWith("http://" + r16.d) != false) goto L_0x0041; */ public synchronized String fetchOrderInfoFromH5PayUrl(String str) { try { if (!TextUtils.isEmpty(str)) { String trim = str.trim(); if (!trim.startsWith("https://" + this.d)) { } String trim2 = trim.replaceFirst("(http|https)://" + this.d + "\\?", "").trim(); if (!TextUtils.isEmpty(trim2)) { String a2 = n.a("<request_token>", "</request_token>", n.b(trim2).get("req_data")); com.alipay.sdk.sys.a aVar = new com.alipay.sdk.sys.a(this.b, "", ""); return "_input_charset=\"utf-8\"&ordertoken=\"" + a2 + "\"&pay_channel_id=\"alipay_sdk\"&bizcontext=\"" + aVar.a("sc", "h5tonative") + "\""; } if (!trim.startsWith("https://" + this.e)) { } String trim3 = trim.replaceFirst("(http|https)://" + this.e + "\\?", "").trim(); if (!TextUtils.isEmpty(trim3)) { String a3 = n.a("<request_token>", "</request_token>", n.b(trim3).get("req_data")); com.alipay.sdk.sys.a aVar2 = new com.alipay.sdk.sys.a(this.b, "", ""); return "_input_charset=\"utf-8\"&ordertoken=\"" + a3 + "\"&pay_channel_id=\"alipay_sdk\"&bizcontext=\"" + aVar2.a("sc", "h5tonative") + "\""; } if (!trim.startsWith("https://" + this.f)) { } if (trim.contains("alipay.wap.create.direct.pay.by.user") || trim.contains("create_forex_trade_wap")) { if (!TextUtils.isEmpty(trim.replaceFirst("(http|https)://" + this.f + "\\?", "").trim())) { com.alipay.sdk.sys.a aVar3 = new com.alipay.sdk.sys.a(this.b, "", ""); JSONObject jSONObject = new JSONObject(); jSONObject.put(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, str); jSONObject.put("bizcontext", aVar3.a("sc", "h5tonative")); return "new_external_info==" + jSONObject.toString(); } } if (Pattern.compile("^(http|https)://(maliprod\\.alipay\\.com/w/trade_pay\\.do.?|mali\\.alipay\\.com/w/trade_pay\\.do.?|mclient\\.alipay\\.com/w/trade_pay\\.do.?)").matcher(str).find()) { String a4 = n.a("?", "", str); if (!TextUtils.isEmpty(a4)) { Map<String, String> b2 = n.b(a4); StringBuilder sb = new StringBuilder(); if (a(false, true, "trade_no", sb, b2, "trade_no", "alipay_trade_no")) { a(true, false, "pay_phase_id", sb, b2, "payPhaseId", "pay_phase_id", "out_relation_id"); sb.append("&biz_sub_type=\"TRADE\""); sb.append("&biz_type=\"trade\""); String str2 = b2.get("app_name"); if (TextUtils.isEmpty(str2) && !TextUtils.isEmpty(b2.get("cid"))) { str2 = "ali1688"; } else if (TextUtils.isEmpty(str2) && (!TextUtils.isEmpty(b2.get("sid")) || !TextUtils.isEmpty(b2.get("s_id")))) { str2 = "tb"; } sb.append("&app_name=\"" + str2 + "\""); if (!a(true, true, "extern_token", sb, b2, "extern_token", "cid", "sid", "s_id")) { return ""; } a(true, false, "appenv", sb, b2, "appenv"); sb.append("&pay_channel_id=\"alipay_sdk\""); a aVar4 = new a(this, null); aVar4.a(b2.get("return_url")); aVar4.c(b2.get("show_url")); aVar4.b(b2.get("pay_order_id")); com.alipay.sdk.sys.a aVar5 = new com.alipay.sdk.sys.a(this.b, "", ""); String str3 = sb.toString() + "&bizcontext=\"" + aVar5.a("sc", "h5tonative") + "\""; this.g.put(str3, aVar4); return str3; } } } if (trim.contains("mclient.alipay.com/cashier/mobilepay.htm") || (EnvUtils.a() && trim.contains("mobileclientgw.alipaydev.com/cashier/mobilepay.htm"))) { String a5 = new com.alipay.sdk.sys.a(this.b, "", "").a("sc", "h5tonative"); JSONObject jSONObject2 = new JSONObject(); jSONObject2.put(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, trim); jSONObject2.put("bizcontext", a5); return String.format("new_external_info==%s", jSONObject2.toString()); } else if (com.alipay.sdk.data.a.j().d() && Pattern.compile("^https?://(maliprod\\.alipay\\.com|mali\\.alipay\\.com)/batch_payment\\.do\\?").matcher(trim).find()) { Uri parse = Uri.parse(trim); String queryParameter = parse.getQueryParameter("return_url"); String queryParameter2 = parse.getQueryParameter("show_url"); String queryParameter3 = parse.getQueryParameter("pay_order_id"); String a6 = a(parse.getQueryParameter("trade_nos"), parse.getQueryParameter("alipay_trade_no")); String a7 = a(parse.getQueryParameter("payPhaseId"), parse.getQueryParameter("pay_phase_id"), parse.getQueryParameter("out_relation_id")); String[] strArr = new String[4]; strArr[0] = parse.getQueryParameter("app_name"); strArr[1] = !TextUtils.isEmpty(parse.getQueryParameter("cid")) ? "ali1688" : ""; strArr[2] = !TextUtils.isEmpty(parse.getQueryParameter("sid")) ? "tb" : ""; strArr[3] = !TextUtils.isEmpty(parse.getQueryParameter("s_id")) ? "tb" : ""; String a8 = a(strArr); String a9 = a(parse.getQueryParameter("extern_token"), parse.getQueryParameter("cid"), parse.getQueryParameter("sid"), parse.getQueryParameter("s_id")); String a10 = a(parse.getQueryParameter("appenv")); if (!TextUtils.isEmpty(a6) && !TextUtils.isEmpty(a8) && !TextUtils.isEmpty(a9)) { String format = String.format("trade_no=\"%s\"&pay_phase_id=\"%s\"&biz_type=\"trade\"&biz_sub_type=\"TRADE\"&app_name=\"%s\"&extern_token=\"%s\"&appenv=\"%s\"&pay_channel_id=\"alipay_sdk\"&bizcontext=\"%s\"", a6, a7, a8, a9, a10, new com.alipay.sdk.sys.a(this.b, "", "").a("sc", "h5tonative")); a aVar6 = new a(this, null); aVar6.a(queryParameter); aVar6.c(queryParameter2); aVar6.b(queryParameter3); aVar6.d(a6); this.g.put(format, aVar6); return format; } } } } catch (Throwable th) { c.a(th); } return ""; } private static final String a(String... strArr) { if (strArr == null) { return ""; } for (String str : strArr) { if (!TextUtils.isEmpty(str)) { return str; } } return ""; } public static synchronized boolean fetchSdkConfig(Context context) { synchronized (PayTask.class) { try { b.a().a(context); long elapsedRealtime = SystemClock.elapsedRealtime() / 1000; if (elapsedRealtime - h < ((long) com.alipay.sdk.data.a.j().f())) { return false; } h = elapsedRealtime; com.alipay.sdk.data.a.j().a(com.alipay.sdk.sys.a.a(), context.getApplicationContext()); return true; } catch (Exception e2) { c.a(e2); return false; } } } /* access modifiers changed from: private */ public class a { private String b; private String c; private String d; private String e; private a() { this.b = ""; this.c = ""; this.d = ""; this.e = ""; } /* synthetic */ a(PayTask payTask, g gVar) { this(); } public String a() { return this.b; } public void a(String str) { this.b = str; } public String b() { return this.d; } public void b(String str) { this.d = str; } public String c() { return this.c; } public void c(String str) { this.c = str; } public String d() { return this.e; } public void d(String str) { this.e = str; } } private boolean a(boolean z, boolean z2, String str, StringBuilder sb, Map<String, String> map, String... strArr) { String str2 = ""; int length = strArr.length; int i2 = 0; while (true) { if (i2 >= length) { break; } String str3 = strArr[i2]; if (!TextUtils.isEmpty(map.get(str3))) { str2 = map.get(str3); break; } i2++; } if (TextUtils.isEmpty(str2)) { if (z2) { return false; } return true; } else if (z) { sb.append("&"); sb.append(str); sb.append("=\""); sb.append(str2); sb.append("\""); return true; } else { sb.append(str); sb.append("=\""); sb.append(str2); sb.append("\""); return true; } } public synchronized H5PayResultModel h5Pay(com.alipay.sdk.sys.a aVar, String str, boolean z) { H5PayResultModel h5PayResultModel; h5PayResultModel = new H5PayResultModel(); try { String[] split = a(aVar, str, z).split(";"); HashMap hashMap = new HashMap(); for (String str2 : split) { int indexOf = str2.indexOf("={"); if (indexOf >= 0) { String substring = str2.substring(0, indexOf); hashMap.put(substring, a(str2, substring)); } } if (hashMap.containsKey("resultStatus")) { h5PayResultModel.b(hashMap.get("resultStatus")); } h5PayResultModel.a(a(str, hashMap)); if (TextUtils.isEmpty(h5PayResultModel.a())) { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "H5CbUrlEmpty", ""); } } catch (Throwable th) { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "H5CbEx", th); c.a(th); } return h5PayResultModel; } private String a(String str, Map<String, String> map) throws UnsupportedEncodingException { boolean equals = "9000".equals(map.get("resultStatus")); String str2 = map.get("result"); a remove = this.g.remove(str); String[] strArr = new String[2]; strArr[0] = remove != null ? remove.b() : ""; strArr[1] = remove != null ? remove.d() : ""; a(strArr); if (map.containsKey("callBackUrl")) { return map.get("callBackUrl"); } if (str2.length() > 15) { String a2 = a(n.a("&callBackUrl=\"", "\"", str2), n.a("&call_back_url=\"", "\"", str2), n.a("&return_url=\"", "\"", str2), URLDecoder.decode(n.a("&return_url=", "&", str2), "utf-8"), URLDecoder.decode(n.a("&callBackUrl=", "&", str2), "utf-8"), n.a("call_back_url=\"", "\"", str2)); if (!TextUtils.isEmpty(a2)) { return a2; } } if (remove != null) { String a3 = equals ? remove.a() : remove.c(); if (!TextUtils.isEmpty(a3)) { return a3; } } return remove != null ? com.alipay.sdk.data.a.j().e() : ""; } private String a(String str, String str2) { String str3 = str2 + "={"; return str.substring(str.indexOf(str3) + str3.length(), str.lastIndexOf("}")); } private e.a a() { return new h(this); } public void showLoading() { if (this.c != null) { this.c.a(); } } public void dismissLoading() { if (this.c != null) { this.c.b(); this.c = null; } } private String a(String str, com.alipay.sdk.sys.a aVar) { String a2 = aVar.a(str); if (a2.contains("paymethod=\"expressGateway\"")) { return a(aVar, a2); } List<a.C0008a> i2 = com.alipay.sdk.data.a.j().i(); if (!com.alipay.sdk.data.a.j().f1334a || i2 == null) { i2 = i.f1327a; } if (n.b(aVar, this.b, i2)) { e eVar = new e(this.b, aVar, a()); c.b("mspl", "pay inner started: " + a2); String a3 = eVar.a(a2); c.b("mspl", "pay inner raw result: " + a3); eVar.a(); if (TextUtils.equals(a3, "failed") || TextUtils.equals(a3, "scheme_failed")) { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "LogBindCalledH5"); return a(aVar, a2); } else if (TextUtils.isEmpty(a3)) { return j.c(); } else { if (!a3.contains(PayResultActivity.f1315a)) { return a3; } com.alipay.sdk.app.statistic.a.a(aVar, "biz", "LogHkLoginByIntent"); return a(aVar, a2, i2, a3, this.b); } } else { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "LogCalledH5"); return a(aVar, a2); } } private static String a(com.alipay.sdk.sys.a aVar, String str, List<a.C0008a> list, String str2, Activity activity) { n.a a2 = n.a(aVar, activity, list); if (a2 == null || a2.a(aVar) || a2.a() || !TextUtils.equals(a2.f1366a.packageName, PayResultActivity.c)) { return str2; } c.a("mspl", "PayTask not_login"); String valueOf = String.valueOf(str.hashCode()); PayResultActivity.b.put(valueOf, new Object()); Intent intent = new Intent(activity, PayResultActivity.class); intent.putExtra(PayResultActivity.e, str); intent.putExtra(PayResultActivity.f, activity.getPackageName()); intent.putExtra(PayResultActivity.d, valueOf); a.C0010a.a(aVar, intent); activity.startActivity(intent); synchronized (PayResultActivity.b.get(valueOf)) { try { c.a("mspl", "PayTask wait"); PayResultActivity.b.get(valueOf).wait(); } catch (InterruptedException unused) { c.a("mspl", "PayTask interrupted"); return j.c(); } } String str3 = PayResultActivity.a.b; c.a("mspl", "PayTask ret: " + str3); return str3; } private String a(com.alipay.sdk.sys.a aVar, String str) { showLoading(); k kVar = null; try { JSONObject c2 = new f().a(aVar, this.b.getApplicationContext(), str).c(); String optString = c2.optString("end_code", null); List<com.alipay.sdk.protocol.b> a2 = com.alipay.sdk.protocol.b.a(c2.optJSONObject("form").optJSONObject("onload")); for (int i2 = 0; i2 < a2.size(); i2++) { if (a2.get(i2).a() == com.alipay.sdk.protocol.a.Update) { com.alipay.sdk.protocol.b.a(a2.get(i2)); } } a(aVar, c2); dismissLoading(); com.alipay.sdk.app.statistic.a.a(this.b, aVar, str, aVar.f1351a); for (int i3 = 0; i3 < a2.size(); i3++) { com.alipay.sdk.protocol.b bVar = a2.get(i3); if (bVar.a() == com.alipay.sdk.protocol.a.WapPay) { String a3 = a(aVar, bVar); dismissLoading(); com.alipay.sdk.app.statistic.a.a(this.b, aVar, str, aVar.f1351a); return a3; } else if (bVar.a() == com.alipay.sdk.protocol.a.OpenWeb) { String a4 = a(aVar, bVar, optString); dismissLoading(); com.alipay.sdk.app.statistic.a.a(this.b, aVar, str, aVar.f1351a); return a4; } } } catch (IOException e2) { k a5 = k.a(k.NETWORK_ERROR.a()); com.alipay.sdk.app.statistic.a.a(aVar, "net", e2); dismissLoading(); com.alipay.sdk.app.statistic.a.a(this.b, aVar, str, aVar.f1351a); kVar = a5; } catch (Throwable th) { dismissLoading(); com.alipay.sdk.app.statistic.a.a(this.b, aVar, str, aVar.f1351a); throw th; } dismissLoading(); com.alipay.sdk.app.statistic.a.a(this.b, aVar, str, aVar.f1351a); if (kVar == null) { kVar = k.a(k.FAILED.a()); } return j.a(kVar.a(), kVar.b(), ""); } private void a(com.alipay.sdk.sys.a aVar, JSONObject jSONObject) { try { String optString = jSONObject.optString("tid"); String optString2 = jSONObject.optString("client_key"); if (!TextUtils.isEmpty(optString) && !TextUtils.isEmpty(optString2)) { com.alipay.sdk.tid.b.a(b.a().b()).a(optString, optString2); } } catch (Throwable th) { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "ParserTidClientKeyEx", th); } } private String a(com.alipay.sdk.sys.a aVar, com.alipay.sdk.protocol.b bVar, String str) { boolean b2; String a2; String[] b3 = bVar.b(); Intent intent = new Intent(this.b, H5PayActivity.class); try { JSONObject c2 = n.c(new String(com.alipay.sdk.encrypt.a.a(b3[2]))); intent.putExtra(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, b3[0]); intent.putExtra("title", b3[1]); intent.putExtra("version", "v2"); intent.putExtra("method", c2.optString("method", "POST")); j.a(false); j.a((String) null); a.C0010a.a(aVar, intent); this.b.startActivity(intent); synchronized (f1317a) { try { f1317a.wait(); b2 = j.b(); a2 = j.a(); j.a(false); j.a((String) null); } catch (InterruptedException e2) { c.a(e2); return j.c(); } } String str2 = ""; if (b2) { try { List<com.alipay.sdk.protocol.b> a3 = com.alipay.sdk.protocol.b.a(n.c(new String(com.alipay.sdk.encrypt.a.a(a2)))); int i2 = 0; while (true) { if (i2 >= a3.size()) { break; } com.alipay.sdk.protocol.b bVar2 = a3.get(i2); if (bVar2.a() == com.alipay.sdk.protocol.a.SetResult) { String[] b4 = bVar2.b(); str2 = j.a(Integer.valueOf(b4[1]).intValue(), b4[0], n.b(aVar, b4[2])); break; } i2++; } } catch (Throwable th) { c.a(th); com.alipay.sdk.app.statistic.a.a(aVar, "biz", "H5PayDataAnalysisError", th, a2); } } if (!TextUtils.isEmpty(str2)) { return str2; } try { return j.a(Integer.valueOf(str).intValue(), "", ""); } catch (Throwable th2) { com.alipay.sdk.app.statistic.a.a(aVar, "biz", "H5PayDataAnalysisError", th2, "endCode: " + str); return j.a(8000, "", ""); } } catch (Throwable th3) { c.a(th3); com.alipay.sdk.app.statistic.a.a(aVar, "biz", "H5PayDataAnalysisError", th3, Arrays.toString(b3)); return j.c(); } } private String a(com.alipay.sdk.sys.a aVar, com.alipay.sdk.protocol.b bVar) { String[] b2 = bVar.b(); Intent intent = new Intent(this.b, H5PayActivity.class); Bundle bundle = new Bundle(); bundle.putString(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL, b2[0]); if (b2.length == 2) { bundle.putString("cookie", b2[1]); } intent.putExtras(bundle); a.C0010a.a(aVar, intent); this.b.startActivity(intent); synchronized (f1317a) { try { f1317a.wait(); } catch (InterruptedException e2) { c.a(e2); return j.c(); } } String a2 = j.a(); if (TextUtils.isEmpty(a2)) { return j.c(); } return a2; } private static boolean b() { long elapsedRealtime = SystemClock.elapsedRealtime(); if (elapsedRealtime - i < 3000) { return true; } i = elapsedRealtime; return false; } }