package com.tencent.mm.plugin.wallet_index.c;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import com.tencent.mars.smc.IDKey;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.bp.d;
import com.tencent.mm.g.a.he;
import com.tencent.mm.g.a.mf;
import com.tencent.mm.g.a.uv;
import com.tencent.mm.kernel.g;
import com.tencent.mm.modelsimple.h;
import com.tencent.mm.pluginsdk.wallet.PayInfo;
import com.tencent.mm.protocal.protobuf.csj;
import com.tencent.mm.sdk.b.a;
import com.tencent.mm.sdk.b.b;
import com.tencent.mm.sdk.b.c;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ah;
import com.tencent.mm.sdk.platformtools.at;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.wallet_core.c.ad;
import com.tencent.mm.wallet_core.c.z;
import com.tencent.mm.wallet_core.tenpay.model.o;
import com.tencent.mm.wallet_core.tenpay.model.r;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.regex.Pattern;

public final class m extends c<uv> implements f {
    int tRg;
    int tRh;
    he tRi;
    mf tRj;
    long tRk;
    public c tRl;
    public c<mf> tRm;

    public m() {
        AppMethodBeat.i(48205);
        this.tRh = 0;
        this.tRl = new 1(this);
        this.tRm = new 2(this);
        this.xxI = uv.class.getName().hashCode();
        AppMethodBeat.o(48205);
    }

    static /* synthetic */ void a(m mVar, String str, int i) {
        AppMethodBeat.i(48211);
        mVar.du(str, i);
        AppMethodBeat.o(48211);
    }

    public final /* synthetic */ boolean a(b bVar) {
        AppMethodBeat.i(48209);
        uv uvVar = (uv) bVar;
        z.dNW();
        if (uvVar instanceof uv) {
            ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "onPayEnd, isOk = " + (uvVar.cRF.result == -1));
            a.xxA.d(this);
            if (uvVar.cRF.result == -1) {
                Intent intent = new Intent();
                intent.addFlags(67108864);
                if (uvVar.cRF.intent == null || uvVar.cRF.intent.getIntExtra("pay_channel", 0) != 13) {
                    d.f(ah.getContext(), ".ui.LauncherUI", intent);
                } else {
                    ab.i("MicroMsg.WalletGetA8KeyRedirectListener", "channel is MMPAY_CHANNEL_SCAN_QRCODE_IMAGE_CHANNEL ，return org page");
                }
            }
            AppMethodBeat.o(48209);
            return true;
        }
        ab.f("MicroMsg.WalletGetA8KeyRedirectListener", "mismatched event");
        AppMethodBeat.o(48209);
        return false;
    }

    public final void onSceneEnd(int i, int i2, String str, com.tencent.mm.ai.m mVar) {
        AppMethodBeat.i(48206);
        if (mVar instanceof h) {
            long currentTimeMillis = System.currentTimeMillis() - this.tRk;
            com.tencent.mm.plugin.report.service.h.pYm.e(11170, new Object[]{Integer.valueOf(233), Integer.valueOf(0), Long.valueOf(currentTimeMillis), Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(at.getNetType(ah.getContext())), BuildConfig.FLAVOR});
            i(i, i2, currentTimeMillis);
            ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "onSceneEnd errType = " + i + ", errCode = " + i2 + ",errMsg = " + str);
            g.RQ();
            g.RO().eJo.b(233, this);
            if (i == 0 && i2 == 0) {
                du(((h) mVar).aiT(), this.tRh);
                AppMethodBeat.o(48206);
                return;
            }
            if (bo.isNullOrNil(str)) {
                str = this.tRi.cBW.context.getString(2131305389);
            }
            com.tencent.mm.ui.base.h.a(this.tRi.cBW.context, str, BuildConfig.FLAVOR, new 3(this));
            AppMethodBeat.o(48206);
        } else if (mVar instanceof o) {
            ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "native auth, errType: %d, errCode: %d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
            g.RQ();
            g.RO().eJo.b(385, this);
            if (i == 0 && i2 == 0 && "0".equals(((o) mVar).AgN)) {
                if (this.tRj.callback != null) {
                    this.tRj.cIa.ret = 2;
                    this.tRj.callback.run();
                }
                ad.o(this.tRg, ((o) mVar).czZ, i2);
                csj csj = ((o) mVar).tRc;
                o oVar;
                if (csj == null || bo.isNullOrNil(csj.xpI)) {
                    oVar = (o) mVar;
                    PayInfo payInfo = new PayInfo();
                    payInfo.cIf = this.tRg;
                    payInfo.czZ = oVar.czZ;
                    payInfo.appId = oVar.appId;
                    payInfo.tRb = oVar.tRb;
                    payInfo.cwg = oVar.cwg;
                    payInfo.cIb = oVar.cIb;
                    ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "startPay native, payInfo: %s", new Object[]{payInfo.toString()});
                    com.tencent.mm.pluginsdk.wallet.h.a(this.tRj.cHZ.context, payInfo, 0);
                    if (this.tRj.callback != null) {
                        this.tRj.cIa.ret = 2;
                        this.tRj.callback.run();
                    }
                    AppMethodBeat.o(48206);
                    return;
                }
                oVar = (o) mVar;
                Intent intent = new Intent();
                intent.putExtra("prepayId", oVar.czZ);
                intent.putExtra("is_jsapi_offline_pay", false);
                csj = oVar.tRc;
                intent.putExtra("pay_gate_url", csj.xpI);
                intent.putExtra("need_dialog", csj.xpK);
                intent.putExtra("dialog_text", csj.xpL);
                intent.putExtra("max_count", csj.xpJ.vRG);
                intent.putExtra("inteval_time", csj.xpJ.vRF);
                intent.putExtra("default_wording", csj.xpJ.vRH);
                d.c((Activity) this.tRj.cHZ.context, "wallet_core", ".ui.WalletMixOrderInfoUI", intent);
                if (this.tRj.callback != null) {
                    this.tRj.cIa.ret = 2;
                    this.tRj.callback.run();
                }
                ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "mAuthNativeEvent.data.context: %s", new Object[]{this.tRj.cHZ.context});
                AppMethodBeat.o(48206);
                return;
            }
            if (this.tRj.callback != null) {
                this.tRj.cIa.ret = 1;
            }
            if (bo.isNullOrNil(str)) {
                if (bo.isNullOrNil(((o) mVar).hwA)) {
                    str = this.tRj.cHZ.context.getString(2131305389);
                } else {
                    str = ((o) mVar).hwA;
                }
            }
            ad.o(this.tRg, BuildConfig.FLAVOR, i2);
            com.tencent.mm.ui.base.h.a(this.tRj.cHZ.context, str, BuildConfig.FLAVOR, new 4(this));
            AppMethodBeat.o(48206);
        } else {
            ab.i("MicroMsg.WalletGetA8KeyRedirectListener", "other scene");
            AppMethodBeat.o(48206);
        }
    }

    private void du(String str, int i) {
        AppMethodBeat.i(48207);
        ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "startPay reqKey = ".concat(String.valueOf(str)));
        PayInfo payInfo = new PayInfo();
        payInfo.cIf = this.tRg;
        String str2 = null;
        Object obj = null;
        for (String str3 : str.replace("http://p.qq.com?", BuildConfig.FLAVOR).split("&")) {
            if (str3.startsWith("errcode=")) {
                obj = str3.replace("errcode=", BuildConfig.FLAVOR);
            } else if (str3.startsWith("errmsg=")) {
                str2 = str3.replace("errmsg=", BuildConfig.FLAVOR);
            } else if (str3.startsWith("reqkey=")) {
                payInfo.czZ = str3.replace("reqkey=", BuildConfig.FLAVOR);
            } else if (str3.startsWith("uuid=")) {
                payInfo.eCq = str3.replace("uuid=", BuildConfig.FLAVOR);
            } else if (str3.startsWith("appid=")) {
                payInfo.appId = str3.replace("appid=", BuildConfig.FLAVOR);
            } else if (str3.startsWith("appsource=")) {
                payInfo.tRb = str3.replace("appsource=", BuildConfig.FLAVOR);
            } else if (str3.startsWith("productid=")) {
                payInfo.cwg = str3.replace("productid=", BuildConfig.FLAVOR);
            }
        }
        payInfo.cIb = i;
        if ("0".equals(obj)) {
            com.tencent.mm.pluginsdk.wallet.h.a(this.tRi.cBW.context, payInfo, 0);
            if (this.tRi.callback != null) {
                this.tRi.cBX.ret = 1;
                this.tRi.callback.run();
            }
        } else {
            if (bo.isNullOrNil(str2)) {
                str2 = this.tRi.cBW.context.getString(2131305389);
            }
            com.tencent.mm.ui.base.h.a(this.tRi.cBW.context, str2, BuildConfig.FLAVOR, new 5(this));
        }
        if (!TextUtils.isEmpty(obj) && Pattern.compile("[0-9]*").matcher(obj).matches()) {
            i(0, Integer.valueOf(obj).intValue(), 0);
        }
        AppMethodBeat.o(48207);
    }

    private void i(int i, int i2, long j) {
        IDKey iDKey;
        AppMethodBeat.i(48208);
        int i3 = 132;
        if (this.tRg == 1) {
            i3 = 163;
        }
        ArrayList arrayList = new ArrayList();
        IDKey iDKey2 = new IDKey();
        iDKey2.SetID(i3);
        iDKey2.SetValue(1);
        iDKey2.SetKey(26);
        arrayList.add(iDKey2);
        if (!(i == 0 && i2 == 0)) {
            iDKey2 = new IDKey();
            iDKey2.SetID(i3);
            iDKey2.SetValue(1);
            iDKey = new IDKey();
            iDKey.SetID(i3);
            iDKey.SetValue(1);
            iDKey2.SetKey(8);
            if (i2 < 0) {
                iDKey.SetKey(9);
            } else if (i2 > 0) {
                iDKey.SetKey(10);
            }
        }
        if (this.tRg == 4 && j > 0) {
            iDKey2 = new IDKey();
            iDKey2.SetID(i3);
            iDKey2.SetValue(1);
            iDKey = new IDKey();
            iDKey.SetID(i3);
            iDKey.SetValue(1);
            IDKey iDKey3 = new IDKey();
            iDKey3.SetID(i3);
            iDKey3.SetValue((long) ((int) j));
            iDKey2.SetKey(0);
            if (j <= 1000) {
                iDKey.SetKey(1);
                iDKey3.SetKey(4);
            } else if (j > 1000 && j <= 3000) {
                iDKey.SetKey(2);
                iDKey3.SetKey(5);
            } else if (j > 3000) {
                iDKey.SetKey(3);
                iDKey3.SetKey(6);
            }
            arrayList.add(iDKey2);
            arrayList.add(iDKey);
            arrayList.add(iDKey3);
        }
        com.tencent.mm.plugin.report.service.h.pYm.b(arrayList, true);
        AppMethodBeat.o(48208);
    }

    static /* synthetic */ void a(m mVar, mf mfVar) {
        String str;
        com.tencent.mm.ai.m oVar;
        AppMethodBeat.i(48210);
        mVar.tRj = mfVar;
        String str2 = mfVar.cHZ.url;
        int i = mfVar.cHZ.scene;
        int i2 = mfVar.cHZ.cIb;
        int i3 = mfVar.cHZ.cvp;
        if (mfVar.cHZ.source == null) {
            str = BuildConfig.FLAVOR;
        } else {
            str = mfVar.cHZ.source;
        }
        mVar.tRg = 1;
        ab.d("MicroMsg.WalletGetA8KeyRedirectListener", "auth native, url: %s, a8key_scene: %d, channel: %d, sourceType: %d, source: %s", new Object[]{str2, Integer.valueOf(i), Integer.valueOf(i2), Integer.valueOf(i3), str});
        int i4 = mVar.tRg;
        if (bo.isNullOrNil(str2)) {
            oVar = new o(str2, i, i4, i2, i3, str);
        } else {
            int indexOf = str2.indexOf("/bizpayurl");
            int indexOf2 = str2.indexOf("?");
            if (indexOf < 0 || indexOf2 < 0 || indexOf >= indexOf2) {
                oVar = new o(str2, i, i4, i2, i3, str);
            } else if (str2.substring(indexOf, indexOf2).equals("/bizpayurl/up")) {
                oVar = new r(str2, i, i4, i2, i3, str);
            } else {
                oVar = new o(str2, i, i4, i2, i3, str);
            }
        }
        g.RQ();
        g.RO().eJo.a(385, mVar);
        g.RQ();
        g.RO().eJo.a(oVar, 0);
        AppMethodBeat.o(48210);
    }
}
