导航菜单

页面标题

页面副标题

Clash Legends v0.0.1 - WebActivity.java 源代码

正在查看: Clash Legends v0.0.1 应用的 WebActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.clash.legends.ui.activities;

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.webkit.JavascriptInterface;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.TimeoutError;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import com.clash.legends.models.CurrentUser;
import com.clash.legends.utils.LocaleHelper;
import com.clash.legends.utils.UserLocalStore;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

public class WebActivity extends AppCompatActivity {
    private String amount;
    private ImageView backFromWebView;
    private Context context;
    private JsonObjectRequest googlePayResponseRequest;
    private String orderId;
    private String paymentUrl;
    private RequestQueue requestQueue;
    private Resources resources;
    private String transactionId;
    private CurrentUser user;
    private UserLocalStore userLocalStore;
    private WebView webView;
    private boolean isTransactionHandled = false;
    private String customerId = "";

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(2131558492);
        Context locale = LocaleHelper.setLocale(this);
        this.context = locale;
        this.resources = locale.getResources();
        Intent intent = getIntent();
        this.paymentUrl = intent.getStringExtra("P_URL");
        this.amount = intent.getStringExtra("amount");
        this.transactionId = intent.getStringExtra("tid");
        this.orderId = intent.getStringExtra("oid");
        UserLocalStore userLocalStore = new UserLocalStore(getApplicationContext());
        this.userLocalStore = userLocalStore;
        CurrentUser loggedInUser = userLocalStore.getLoggedInUser();
        this.user = loggedInUser;
        this.customerId = loggedInUser.getMemberid();
        this.backFromWebView = (ImageView) findViewById(2131361994);
        WebView webView = (WebView) findViewById(2131363786);
        this.webView = webView;
        webView.setWebViewClient(new WebViewClient());
        this.webView.getSettings();
        this.webView.getSettings().setJavaScriptEnabled(true);
        this.webView.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 11; Pixel 4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Mobile Safari/537.36");
        this.webView.getSettings().setDomStorageEnabled(true);
        this.webView.setWebChromeClient(new WebChromeClient());
        this.webView.addJavascriptInterface(new WebAppInterface(this), "Android");
        String str = this.paymentUrl;
        if (str != null && !str.isEmpty()) {
            this.webView.loadUrl(this.paymentUrl);
        } else {
            this.webView.loadUrl("about:blank");
        }
        this.webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                if (url != null && (url.startsWith("upi://") || url.startsWith("intent://"))) {
                    try {
                        Intent intent2 = Intent.parseUri(url, 1);
                        WebActivity.this.startActivity(intent2);
                        return true;
                    } catch (URISyntaxException e) {
                    }
                }
                return super.shouldOverrideUrlLoading(view, url);
            }
        });
        this.backFromWebView.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                WebActivity.this.m227lambda$onCreate$0$comclashlegendsuiactivitiesWebActivity(view);
            }
        });
    }

    void m227lambda$onCreate$0$comclashlegendsuiactivitiesWebActivity(View view) {
        finish();
    }

    public class WebAppInterface {
        private Context mContext;

        WebAppInterface(Context c) {
            this.mContext = c;
        }

        @JavascriptInterface
        public void transactionSuccess() {
            if (!WebActivity.this.isTransactionHandled) {
                WebActivity.this.isTransactionHandled = true;
                WebActivity webActivity = WebActivity.this;
                webActivity.googlePayResponse("true", webActivity.amount, WebActivity.this.transactionId, WebActivity.this.orderId);
            }
        }

        @JavascriptInterface
        public void transactionFailed() {
            if (!WebActivity.this.isTransactionHandled) {
                WebActivity.this.isTransactionHandled = true;
                WebActivity webActivity = WebActivity.this;
                webActivity.googlePayResponse("false", webActivity.amount, WebActivity.this.transactionId, WebActivity.this.orderId);
            }
        }
    }

    public void googlePayResponse(String status, final String amount, final String transactionId, String orderId) {
        RequestQueue newRequestQueue = Volley.newRequestQueue(getApplicationContext());
        this.requestQueue = newRequestQueue;
        newRequestQueue.getCache().clear();
        String url = this.resources.getString(2131886167) + "googlepay_response";
        HashMap<String, String> params = new HashMap<>();
        params.put("status", status);
        params.put("amount", amount);
        params.put("member_id", this.customerId);
        params.put("transaction_id", transactionId);
        params.put("order_id", orderId);
        Log.d("GooglePayResponseURL", new JSONObject(params).toString());
        JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(url, new JSONObject(params), new Response.Listener() {
            public final void onResponse(Object obj) {
                WebActivity.this.m225x2566ecc5(transactionId, amount, (JSONObject) obj);
            }
        }, new Response.ErrorListener() {
            public final void onErrorResponse(VolleyError volleyError) {
                WebActivity.this.m226xc007af46(volleyError);
            }
        }) {
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> headers = new HashMap<>();
                CurrentUser user = WebActivity.this.userLocalStore.getLoggedInUser();
                String credentials = user.getUsername() + ":" + user.getPassword();
                String auth = "Basic " + Base64.encodeToString(credentials.getBytes(), 2);
                headers.put("Content-Type", "application/json");
                headers.put("Authorization", auth);
                headers.put("x-localization", LocaleHelper.getPersist(WebActivity.this.context));
                return headers;
            }
        };
        this.googlePayResponseRequest = jsonObjectRequest;
        jsonObjectRequest.setShouldCache(false);
        this.requestQueue.add(this.googlePayResponseRequest);
    }

    void m225x2566ecc5(String transactionId, String amount, JSONObject response) {
        Log.d("GooglePayResponse", response.toString());
        try {
            if (TextUtils.equals(response.getString("status"), "true")) {
                Intent intent = new Intent(getApplicationContext(), (Class<?>) TansactionSuccessActivity.class);
                intent.putExtra("selected", "₹");
                intent.putExtra("TID", transactionId);
                intent.putExtra("TAMOUNT", amount);
                startActivity(intent);
            } else {
                Intent intent2 = new Intent(getApplicationContext(), (Class<?>) TransactionFailActivity.class);
                intent2.putExtra("TID", transactionId);
                intent2.putExtra("selected", "₹");
                intent2.putExtra("TAMOUNT", amount);
                startActivity(intent2);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

    void m226xc007af46(VolleyError error) {
        NetworkResponse response = error.networkResponse;
        String errorString = new String(response.data);
        Log.e("VolleyError", "error: " + errorString);
        if (error instanceof TimeoutError) {
            this.googlePayResponseRequest.setShouldCache(false);
            this.requestQueue.add(this.googlePayResponseRequest);
        }
    }

    public void onBackPressed() {
        if (this.webView.canGoBack()) {
            this.webView.goBack();
        } else {
            super.onBackPressed();
        }
    }
}