TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c

以下内容为反编译后的 DingdongJsApiPlugin.java 源代码,内容仅作参考


package cooperation.dingdong;

import android.app.Activity;
import android.content.Intent;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.v4.util.ArrayMap;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.view.View;
import com.tencent.av.camera.config.CameraConfigParser;
import com.tencent.biz.troop.TroopMemberApiClient;
import com.tencent.biz.webviewbase.AbsBaseWebViewActivity;
import com.tencent.mobileqq.activity.ForwardRecentActivity;
import com.tencent.mobileqq.activity.contact.troop.TroopActivity;
import com.tencent.mobileqq.activity.selectmember.SelectMemberActivity;
import com.tencent.mobileqq.app.AppConstants;
import com.tencent.mobileqq.forward.ForwardConstants;
import com.tencent.mobileqq.forward.ForwardPluginShareStructMsgOption;
import com.tencent.mobileqq.msf.sdk.AppNetConnInfo;
import com.tencent.mobileqq.statistics.ReportController;
import com.tencent.mobileqq.structmsg.StructMsgFactory;
import com.tencent.mobileqq.utils.StringUtil;
import com.tencent.mobileqq.webview.swift.JsBridgeListener;
import com.tencent.mobileqq.webview.swift.WebViewPlugin;
import com.tencent.mobileqq.widget.QQToast;
import com.tencent.qphone.base.util.QLog;
import com.tencent.tim.R;
import com.tencent.widget.ActionSheet;
import cooperation.dingdong.DingdongPluginConstants;
import cooperation.dingdong.data.DingdongOfficeOpenService;
import cooperation.dingdong.data.OfficeCenterSharedPref;
import demo.moai_view.BuildConfig;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class DingdongJsApiPlugin extends WebViewPlugin {
    private static final byte f97792a = 1;
    private static final int f69229a = 10;
    public static final String f69231a = "param_dingdong_appId";
    private static final byte f97793b = 2;
    public static final String f69233b = "param_from_dingdong_office";
    private static final byte f97794c = 3;
    public static final String f69234c = "dingdong_param_open_id_result";
    private static final String e = "DingdongJsApiPlugin";
    private static final String f = "callback";
    private static final String g = "appId";
    private TroopMemberApiClient f69235a;
    public String d;
    private String h;
    private static final HashMap f69232a = new HashMap();
    private static final ArrayMap f69230a = new ArrayMap();

    static {
        f69232a.put(DingdongJsApiConstants.f69224c, 0);
        f69232a.put(DingdongJsApiConstants.f69223b, 1);
        f69232a.put(DingdongJsApiConstants.f69225d, 2);
        f69232a.put(DingdongJsApiConstants.f69226e, 3);
        f69232a.put("getVersion", 4);
        f69232a.put(DingdongJsApiConstants.f69228g, 5);
        f69232a.put(DingdongJsApiConstants.h, 6);
    }

    public DingdongJsApiPlugin() {
        this.d = DingdongJsApiConstants.f69222a;
        this.d = DingdongJsApiConstants.f69222a;
    }

    public class OpenIdData implements Parcelable {
        public static final Parcelable.Creator CREATOR = new xru();
        public int f97795a;
        public long f69236a;
        public String f69237a;
        public long f97796b;
        public String f69238b;
        public String f97797c;
        public String d;

        public OpenIdData() {
        }

        public OpenIdData(Parcel parcel) {
            this.f97795a = parcel.readInt();
            this.f69236a = parcel.readLong();
            this.f97796b = parcel.readLong();
            this.f69237a = parcel.readString();
            this.f69238b = parcel.readString();
            this.f97797c = parcel.readString();
            this.d = parcel.readString();
        }

        @Override
        public int describeContents() {
            return 0;
        }

        @Override
        public void writeToParcel(Parcel parcel, int i) {
            parcel.writeInt(this.f97795a);
            parcel.writeLong(this.f69236a);
            parcel.writeLong(this.f97796b);
            parcel.writeString(this.f69237a);
            parcel.writeString(this.f69238b);
            parcel.writeString(this.f97797c);
            parcel.writeString(this.d);
        }
    }

    private TroopMemberApiClient a() {
        if (this.f69235a == null) {
            this.f69235a = TroopMemberApiClient.a();
            this.f69235a.m1748a();
        }
        return this.f69235a;
    }

    @Override
    public void onDestroy() {
        if (this.f69235a != null) {
            this.f69235a.a(47, new Bundle(0));
            this.f69235a.b();
            this.f69235a = null;
        }
        super.onDestroy();
    }

    @Override
    public boolean handleJsRequest(JsBridgeListener jsBridgeListener, String str, String str2, String str3, String... strArr) {
        return DingdongJsApiConstants.f69222a.equals(str2) ? a(str, str3, strArr) : super.handleJsRequest(jsBridgeListener, str, str2, str3, strArr);
    }

    protected boolean a(String str, String str2, String... strArr) {
        if (strArr == null || 1 > strArr.length) {
            return false;
        }
        try {
            JSONObject jSONObject = new JSONObject(strArr[0]);
            return a(str, str2, jSONObject, jSONObject.optString("callback", null));
        } catch (JSONException e2) {
            QLog.e(e, 1, "dispatchJsRequest url[" + str + "],method[" + str2 + "] error -> " + e2.toString());
            return false;
        }
    }

    private boolean a(String str, String str2, JSONObject jSONObject, String str3) {
        if (f69232a.containsKey(str2)) {
            int intValue = ((Integer) f69232a.get(str2)).intValue();
            long optLong = jSONObject.optLong("appId", -1L);
            if (str3 != null) {
                f69230a.put(Integer.valueOf(intValue), str3);
            }
            switch (intValue) {
                case 0:
                    c(optLong);
                    return true;
                case 1:
                    b(optLong);
                    return true;
                case 2:
                    b(optLong, jSONObject);
                    return true;
                case 3:
                    b();
                    return true;
                case 4:
                    m10649a();
                    return true;
                case 5:
                    return true;
                case 6:
                    a(optLong, jSONObject);
                    return true;
                default:
                    return false;
            }
        }
        return false;
    }

    private void a(long j, JSONObject jSONObject) {
        if (jSONObject != null) {
            String optString = jSONObject.optString("openId", null);
            if (!TextUtils.isEmpty(optString)) {
                Bundle bundle = new Bundle(4);
                bundle.putInt(DingdongOfficeOpenService.f69304a, 1);
                bundle.putString(DingdongOfficeOpenService.f97883c, optString);
                bundle.putLong(DingdongOfficeOpenService.d, j);
                bundle.putInt(DingdongOfficeOpenService.f69305b, a().a((TroopMemberApiClient.Callback) new xro(this)));
                a().a(46, bundle);
                return;
            }
            JSONObject jSONObject2 = new JSONObject();
            try {
                jSONObject2.put("result", 0);
            } catch (JSONException e2) {
                e2.printStackTrace();
            }
            a(jSONObject2, 6);
        }
    }

    private void m10649a() {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("version", BuildConfig.VERSION_NAME);
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        a(jSONObject, 4);
    }

    private void a(boolean z, String str, int i, View.OnClickListener onClickListener, String str2) {
        Activity a2 = this.mRuntime.a();
        if (a2 != null) {
            if (a2 instanceof AbsBaseWebViewActivity) {
                AbsBaseWebViewActivity absBaseWebViewActivity = (AbsBaseWebViewActivity) a2;
                absBaseWebViewActivity.a(str2, str, null, z, i, 0, null, onClickListener);
                if (onClickListener != null && i == 0) {
                    absBaseWebViewActivity.rightViewText.setOnClickListener(onClickListener);
                }
            } else if (this.mRuntime.m9633a() != null) {
                this.mRuntime.m9633a().a(str2, str, (String) null, z, i, 0, (JsBridgeListener) null, onClickListener);
                if (onClickListener != null && i == 0) {
                    this.mRuntime.m9633a().f34648a.f34615c.setOnClickListener(onClickListener);
                }
            }
        }
    }

    private void a(long j, int i, String str, String str2) {
        String str3;
        int i2;
        xrp xrpVar = null;
        switch (i) {
            case 1:
                str3 = "分享";
                i2 = 4;
                xrpVar = new xrp(this, str2, j);
                break;
            default:
                i2 = 0;
                str3 = str;
                break;
        }
        a(false, str3, i2, xrpVar, str2);
    }

    public void a(long j, JSONArray jSONArray, String str) {
        String str2;
        ActionSheet a2 = ActionSheet.a(this.mRuntime.a());
        for (int i = 0; i < jSONArray.length(); i++) {
            JSONObject optJSONObject = jSONArray.optJSONObject(i);
            if (optJSONObject != null) {
                switch (optJSONObject.optInt("id")) {
                    case 1:
                        str2 = "分享";
                        break;
                    default:
                        str2 = optJSONObject.optString("title", "");
                        break;
                }
                a2.c(str2);
            }
        }
        a2.d("取消");
        if (str != null) {
            a2.a(new xrq(this, a2, str));
        }
        a2.a(new xrr(this, a2, jSONArray, j));
        a2.show();
    }

    private void b(long j, JSONObject jSONObject) {
        JSONArray optJSONArray = jSONObject.optJSONArray("action");
        if (optJSONArray != null) {
            if (optJSONArray.length() > 0) {
                JSONArray a2 = a(optJSONArray);
                int length = a2.length();
                if (length == 1) {
                    JSONObject optJSONObject = a2.optJSONObject(0);
                    switch (optJSONObject.optInt("id", -1)) {
                        case 1:
                            a(j, 1, (String) null, optJSONObject.optString("callback", null));
                            return;
                        default:
                            a(j, -1, optJSONObject.optString("title", ""), optJSONObject.optString("callback", null));
                            return;
                    }
                } else if (length > 1) {
                    a(false, "更多", 0, new xrs(this, j, a2, jSONObject), null);
                    return;
                } else {
                    return;
                }
            }
            a(true, null, 0, null, null);
        }
    }

    private JSONArray a(JSONArray jSONArray) {
        if (jSONArray != null) {
            JSONArray jSONArray2 = new JSONArray();
            ArrayList arrayList = new ArrayList(jSONArray.length());
            ArrayList arrayList2 = new ArrayList(jSONArray.length());
            for (int i = 0; i < jSONArray.length(); i++) {
                JSONObject optJSONObject = jSONArray.optJSONObject(i);
                if (optJSONObject != null) {
                    switch (optJSONObject.optInt("id", -1)) {
                        case 1:
                            if (!arrayList.contains(1)) {
                                jSONArray2.put(optJSONObject);
                                arrayList.add(1);
                                break;
                            } else {
                                continue;
                            }
                        default:
                            String optString = optJSONObject.optString("title", null);
                            if (optString != null && optString.length() <= 10 && !arrayList2.contains(optString)) {
                                jSONArray2.put(optJSONObject);
                                arrayList2.add(optString);
                                continue;
                            }
                            break;
                    }
                }
            }
            return jSONArray2;
        }
        return null;
    }

    private void b() {
        int i = 1;
        NetworkInfo recentNetworkInfo = AppNetConnInfo.getRecentNetworkInfo();
        JSONObject jSONObject = new JSONObject();
        if (recentNetworkInfo != null) {
            try {
            } catch (JSONException e2) {
                e2.printStackTrace();
            }
            if (recentNetworkInfo.isAvailable() && recentNetworkInfo.isConnected()) {
                jSONObject.put(CameraConfigParser.f81283c, 1);
                switch (recentNetworkInfo.getType()) {
                    case 0:
                    case 2:
                    case 3:
                    case 4:
                    case 5:
                        switch (((TelephonyManager) this.mRuntime.a().getSystemService("phone")).getNetworkType()) {
                            case 3:
                            case 5:
                            case 6:
                            case 8:
                            case 9:
                            case 10:
                            case 12:
                            case 14:
                            case 15:
                                i = 3;
                                break;
                            case 4:
                            case 7:
                            case 11:
                            default:
                                i = 2;
                                break;
                            case 13:
                                i = 4;
                                break;
                        }
                    case 1:
                    case 6:
                        break;
                    default:
                        i = 5;
                        break;
                }
                jSONObject.put("type", i);
                a(jSONObject, 3);
            }
        }
        jSONObject.put(CameraConfigParser.f81283c, 0);
        jSONObject.put("type", 5);
        a(jSONObject, 3);
    }

    private xrt a(long j) {
        String a2 = OfficeCenterSharedPref.a().a(AppConstants.Preferences.eo, "");
        if (a2.length() == 0) {
            QLog.e(e, 1, "failed to get apps list.");
            return null;
        }
        try {
            JSONObject jSONObject = new JSONObject(a2);
            Iterator<String> keys = jSONObject.keys();
            while (keys.hasNext()) {
                String obj = keys.next().toString();
                if ("appInfo".equals(obj)) {
                    JSONArray jSONArray = jSONObject.getJSONArray(obj);
                    int length = jSONArray.length();
                    for (int i = 0; i < length; i++) {
                        JSONObject jSONObject2 = jSONArray.getJSONObject(i);
                        if (j == jSONObject2.optLong("id")) {
                            xrt xrtVar = new xrt(null);
                            xrtVar.f112033a = jSONObject2.optString("name");
                            String optString = jSONObject2.optString("icon");
                            String a3 = OfficeCenterSharedPref.a().a(AppConstants.Preferences.em, "");
                            if (a3.length() > 0 && optString.length() > 0) {
                                xrtVar.f112034b = a3 + optString;
                            }
                            xrtVar.f112035c = jSONObject2.optString("home_url");
                            xrtVar.d = jSONObject2.optString("summary");
                            return xrtVar;
                        }
                    }
                    continue;
                }
            }
            return null;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public void m10650a(long j) {
        String url;
        if (this.mRuntime.m9631a().getUrl() != null) {
            xrt a2 = a(j);
            if (a2 != null) {
                Intent intent = new Intent(this.mRuntime.a(), ForwardRecentActivity.class);
                intent.putExtra(ForwardConstants.p, true);
                intent.putExtra(ForwardConstants.W_, ForwardConstants.Y_);
                intent.putExtra(AppConstants.Key.G, 1001);
                intent.putExtra(AppConstants.Key.bR, "web");
                intent.putExtra("req_type", 1);
                intent.putExtra(ForwardPluginShareStructMsgOption.g, true);
                intent.putExtra("desc", a2.d);
                intent.putExtra(AppConstants.Key.bf, ((("http://office.connect.qq.com/myoffice/static/pages/check_url.html?appid=" + j) + "&_url=" + StringUtil.g(url)) + "&_wv=1027") + "&_webviewtype=2");
                intent.putExtra(AppConstants.Key.bh, a2.f112034b);
                intent.putExtra(AppConstants.Key.ci, StructMsgFactory.a(intent.getExtras()).getBytes());
                startActivityForResult(intent, (byte) 3);
                ReportController.b(null, "dc01331", "", "", DingdongPluginConstants.Report.f97856a, "0X800653B", 0, 1, 0, "", "", "" + j, "");
                return;
            }
            QQToast.a(this.mRuntime.a(), 2, "分享失败", 2000).b(this.mRuntime.a().getResources().getDimensionPixelSize(R.dimen.f39450title_bar_height));
        }
    }

    private void b(long j) {
        Intent intent = new Intent(this.mRuntime.a(), TroopActivity.class);
        intent.putExtra(TroopActivity.f14098h, 1);
        intent.putExtra(f69231a, j);
        intent.putExtra(f69233b, true);
        startActivityForResult(intent, (byte) 2);
        ReportController.b(null, "dc01331", "", "", DingdongPluginConstants.Report.f97856a, "0X800653D", 0, 1, 0, "", "", "" + j, "");
    }

    private void c(long j) {
        Intent intent = new Intent(this.mRuntime.a(), SelectMemberActivity.class);
        intent.putExtra("param_type", AppConstants.VALUE.aw);
        intent.putExtra("param_subtype", 0);
        intent.putExtra(SelectMemberActivity.T, true);
        intent.putExtra(SelectMemberActivity.V, true);
        intent.putExtra(SelectMemberActivity.f16463A, 10);
        intent.putExtra(SelectMemberActivity.f16469G, true);
        intent.putExtra(f69231a, j);
        startActivityForResult(intent, (byte) 1);
        ReportController.b(null, "dc01331", "", "", DingdongPluginConstants.Report.f97856a, "0X800653C", 0, 1, 0, "", "", "" + j, "");
    }

    public void a(JSONObject jSONObject, int i) {
        String str = (String) f69230a.remove(Integer.valueOf(i));
        if (!TextUtils.isEmpty(str)) {
            callJs(str, jSONObject.toString());
        }
    }

    private void a(Intent intent, int i) {
        int i2;
        JSONArray jSONArray;
        Object obj = null;
        if (i == -1) {
            ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra(f69234c);
            JSONObject jSONObject = new JSONObject();
            if (parcelableArrayListExtra == null || parcelableArrayListExtra.isEmpty()) {
                i2 = -1;
                jSONArray = null;
            } else {
                jSONArray = new JSONArray();
                Iterator it = parcelableArrayListExtra.iterator();
                while (it.hasNext()) {
                    OpenIdData openIdData = (OpenIdData) it.next();
                    jSONArray.put(openIdData.f69237a);
                    obj = openIdData.d;
                }
                i2 = 1;
            }
            try {
                jSONObject.put("result", i2);
                if (obj != null) {
                    jSONObject.put("secret", obj);
                }
                if (jSONArray != null) {
                    jSONObject.put("contacts", jSONArray);
                }
            } catch (JSONException e2) {
                QLog.e(e, 1, "DingdongJsApiPlugin parse json error:" + e2.toString());
            }
            a(jSONObject, 0);
        }
    }

    private void b(Intent intent, int i) {
        int i2;
        String str;
        String str2;
        int i3;
        String str3;
        String str4;
        String str5;
        int i4;
        String str6 = null;
        if (i == -1) {
            ArrayList parcelableArrayListExtra = intent.getParcelableArrayListExtra(f69234c);
            JSONObject jSONObject = new JSONObject();
            if (parcelableArrayListExtra == null || parcelableArrayListExtra.isEmpty()) {
                i2 = -1;
                str = null;
                str2 = null;
                i3 = -1;
            } else {
                Iterator it = parcelableArrayListExtra.iterator();
                i2 = -1;
                str = null;
                str2 = null;
                while (it.hasNext()) {
                    OpenIdData openIdData = (OpenIdData) it.next();
                    switch (openIdData.f97795a) {
                        case 2:
                            str3 = openIdData.f69238b;
                            str4 = openIdData.f69237a;
                            str5 = openIdData.d;
                            i4 = 2;
                            break;
                        case 3:
                            str3 = openIdData.f97797c;
                            str4 = openIdData.f69237a;
                            str5 = openIdData.d;
                            i4 = 3;
                            break;
                        default:
                            i4 = i2;
                            str5 = str6;
                            str4 = str;
                            str3 = str2;
                            break;
                    }
                    str2 = str3;
                    str = str4;
                    str6 = str5;
                    i2 = i4;
                }
                i3 = 1;
            }
            try {
                jSONObject.put("result", i3);
                if (str6 != null) {
                    jSONObject.put("secret", str6);
                }
                if (-1 != i2) {
                    jSONObject.put("flag", i2);
                }
                if (str2 != null) {
                    jSONObject.put("groupDiscussCode", str2);
                }
                if (str != null) {
                    jSONObject.put("openId", str);
                }
            } catch (JSONException e2) {
                QLog.e(e, 1, "DingdongJsApiPlugin parse json error:" + e2.toString());
            }
            a(jSONObject, 1);
        }
    }

    private void c(Intent intent, int i) {
        if (i == -1) {
            QQToast.a(this.mRuntime.a(), 3, "已分享", 2000).b(this.mRuntime.a().getResources().getDimensionPixelSize(R.dimen.f39450title_bar_height));
        }
        if (this.h != null) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("retCode", i == -1 ? 0 : 1);
            } catch (JSONException e2) {
                e2.printStackTrace();
            }
            callJs(this.h, jSONObject.toString());
            this.h = null;
        }
    }

    @Override
    public void onActivityResult(Intent intent, byte b2, int i) {
        switch (b2) {
            case 1:
                a(intent, i);
                return;
            case 2:
                b(intent, i);
                return;
            case 3:
                c(intent, i);
                return;
            default:
                super.onActivityResult(intent, b2, i);
                return;
        }
    }
}