Trip On v2.1.2版本的 MD5 值为:55953a6deb5e434bd7a356ea51d31456

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


package com.meiqia.core;

import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import androidtranscoder.format.MediaFormatExtraConstants;
import androidx.core.app.NotificationCompat;
import com.alibaba.android.bindingx.core.internal.BindingXConstants;
import com.meiqia.core.bean.MQAgent;
import com.meiqia.core.bean.MQConversation;
import com.meiqia.core.bean.MQEnterpriseConfig;
import com.meiqia.core.bean.MQInquireForm;
import com.meiqia.core.bean.MQMessage;
import com.meiqia.core.bean.MQNotificationMessage;
import com.meiqia.core.callback.OnClientInfoCallback;
import com.meiqia.core.callback.OnEvaluateRobotAnswerCallback;
import com.meiqia.core.callback.OnFailureCallBack;
import com.meiqia.core.callback.OnGetClientCallback;
import com.meiqia.core.callback.OnGetMessageListCallback;
import com.meiqia.core.callback.OnProgressCallback;
import com.meiqia.core.callback.OnRegisterDeviceTokenCallback;
import com.meiqia.core.callback.OnValueCallback;
import com.meiqia.core.callback.SimpleCallback;
import com.meiqia.core.callback.SuccessCallback;
import com.meiqia.meiqiasdk.activity.MQCollectInfoActivity;
import com.meiqia.meiqiasdk.util.ErrorCode;
import com.taobao.weex.common.Constants;
import com.taobao.weex.el.parse.Operators;
import com.taobao.weex.ui.component.WXImage;
import io.dcloud.common.DHInterface.IWebview;
import io.dcloud.common.constant.AbsoluteConst;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okio.BufferedSink;
import okio.Okio;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class h {
    public static boolean a = false;
    public static final MediaType b = MediaType.parse("application/json; charset=utf-8");
    private static String c = "sdk";
    private static h d;
    private static OkHttpClient e;
    private Handler f = new Handler(Looper.getMainLooper());

    public interface a extends OnFailureCallBack {
        void a(boolean z, MQAgent mQAgent, MQConversation mQConversation, List<MQMessage> list);
    }

    public interface b {
        void a(JSONObject jSONObject, Response response);
    }

    public class c implements b {
        private c() {
        }

        @Override
        public void a(JSONObject jSONObject, Response response) {
        }
    }

    public interface d extends OnFailureCallBack {
        void a(int i);
    }

    public interface e extends OnFailureCallBack {
        void a(JSONObject jSONObject);
    }

    public interface f extends OnFailureCallBack {
        void a(String str, long j);
    }

    public interface g extends OnFailureCallBack {
        void a(JSONArray jSONArray);
    }

    public interface InterfaceC0024h extends OnFailureCallBack {
        void a(String str, long j, String str2);
    }

    public interface i extends OnFailureCallBack {
        void a();

        void b();
    }

    public interface j extends OnFailureCallBack {
        void a(String str, String str2);
    }

    private h() {
        e = new OkHttpClient.Builder().connectTimeout(30L, TimeUnit.SECONDS).build();
    }

    public static h a() {
        if (d == null) {
            synchronized (h.class) {
                if (d == null) {
                    d = new h();
                }
            }
        }
        return d;
    }

    private String a(Map<String, Object> map) {
        return com.meiqia.core.a.a.a(com.meiqia.core.d.a != null ? com.meiqia.core.d.a.getAESKey() : "", com.meiqia.core.a.c.a((Map<?, ?>) map).toString());
    }

    public void a(File file, Response response, OnProgressCallback onProgressCallback) {
        FileOutputStream fileOutputStream;
        byte[] bArr = new byte[2048];
        InputStream inputStream = null;
        try {
            InputStream byteStream = response.body().byteStream();
            try {
                long contentLength = response.body().contentLength();
                long j2 = 0;
                fileOutputStream = new FileOutputStream(file);
                while (true) {
                    try {
                        int read = byteStream.read(bArr);
                        if (read == -1) {
                            break;
                        }
                        j2 += read;
                        fileOutputStream.write(bArr, 0, read);
                        if (onProgressCallback != null) {
                            int i2 = (int) (((((float) j2) * 1.0f) / ((float) contentLength)) * 100.0f);
                            onProgressCallback.onProgress(i2);
                            if (i2 == 100) {
                                onProgressCallback.onSuccess();
                            }
                        }
                    } catch (IOException e2) {
                        e = e2;
                        inputStream = byteStream;
                        if (onProgressCallback != null) {
                            try {
                                if (TextUtils.isEmpty(e.getMessage()) || !e.getMessage().toLowerCase().contains(BindingXConstants.STATE_CANCEL)) {
                                    onProgressCallback.onFailure(20000, "download file failed");
                                } else {
                                    onProgressCallback.onFailure(ErrorCode.DOWNLOAD_IS_CANCEL, "download is cancel");
                                }
                            } catch (Throwable th) {
                                th = th;
                                if (inputStream != null) {
                                    try {
                                        inputStream.close();
                                    } catch (IOException unused) {
                                        if (onProgressCallback != null) {
                                            onProgressCallback.onFailure(20000, "download file failed");
                                        }
                                    }
                                }
                                if (fileOutputStream != null) {
                                    try {
                                        fileOutputStream.close();
                                    } catch (IOException unused2) {
                                        if (onProgressCallback != null) {
                                            onProgressCallback.onFailure(20000, "download file failed");
                                        }
                                    }
                                }
                                throw th;
                            }
                        }
                        if (inputStream != null) {
                            try {
                                inputStream.close();
                            } catch (IOException unused3) {
                                if (onProgressCallback != null) {
                                    onProgressCallback.onFailure(20000, "download file failed");
                                }
                            }
                        }
                        if (fileOutputStream != null) {
                            try {
                                fileOutputStream.close();
                                return;
                            } catch (IOException unused4) {
                                if (onProgressCallback == null) {
                                    return;
                                }
                                onProgressCallback.onFailure(20000, "download file failed");
                            }
                        }
                        return;
                    } catch (Throwable th2) {
                        th = th2;
                        inputStream = byteStream;
                        if (inputStream != null) {
                        }
                        if (fileOutputStream != null) {
                        }
                        throw th;
                    }
                }
                fileOutputStream.flush();
                if (byteStream != null) {
                    try {
                        byteStream.close();
                    } catch (IOException unused5) {
                        if (onProgressCallback != null) {
                            onProgressCallback.onFailure(20000, "download file failed");
                        }
                    }
                }
                try {
                    fileOutputStream.close();
                } catch (IOException unused6) {
                    if (onProgressCallback == null) {
                        return;
                    }
                    onProgressCallback.onFailure(20000, "download file failed");
                }
            } catch (IOException e3) {
                e = e3;
                fileOutputStream = null;
            } catch (Throwable th3) {
                th = th3;
                fileOutputStream = null;
            }
        } catch (IOException e4) {
            e = e4;
            fileOutputStream = null;
        } catch (Throwable th4) {
            th = th4;
            fileOutputStream = null;
        }
    }

    private void a(String str, Map<String, Object> map, b bVar, OnFailureCallBack onFailureCallBack) {
        a(true, str, map, bVar, onFailureCallBack);
    }

    public void a(final Request request, final b bVar, final OnFailureCallBack onFailureCallBack) {
        com.meiqia.core.a.f.a(request);
        e.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(final Call call, final IOException iOException) {
                if (iOException instanceof SSLHandshakeException) {
                    h.this.d();
                }
                h.this.f.post(new Runnable() {
                    @Override
                    public void run() {
                        OnFailureCallBack onFailureCallBack2;
                        int i2;
                        IOException iOException2 = iOException;
                        String message = iOException2 != null ? iOException2.getMessage() : "IOException";
                        if (onFailureCallBack != null) {
                            if (call.isCanceled()) {
                                onFailureCallBack2 = onFailureCallBack;
                                i2 = ErrorCode.CANCEL;
                            } else {
                                onFailureCallBack2 = onFailureCallBack;
                                i2 = ErrorCode.NET_NOT_WORK;
                            }
                            onFailureCallBack2.onFailure(i2, message);
                        }
                    }
                });
            }

            @Override
            public void onResponse(Call call, final Response response) {
                Handler handler;
                Runnable runnable;
                final int i2;
                b bVar2 = bVar;
                if (bVar2 == null) {
                    return;
                }
                if (bVar2 instanceof c) {
                    bVar2.a(null, response);
                    return;
                }
                final JSONObject a2 = com.meiqia.core.a.c.a(response);
                String optString = a2.optString("ret");
                if (!TextUtils.isEmpty(optString)) {
                    try {
                        a2 = new JSONObject(com.meiqia.core.a.a.b(com.meiqia.core.d.a.getAESKey(), optString));
                    } catch (Exception unused) {
                        h.this.f.post(new Runnable() {
                            @Override
                            public void run() {
                                if (onFailureCallBack != null) {
                                    onFailureCallBack.onFailure(-1, "GeneralSecurityException");
                                }
                            }
                        });
                        return;
                    }
                }
                if (!response.isSuccessful()) {
                    handler = h.this.f;
                    runnable = new Runnable() {
                        @Override
                        public void run() {
                            String jSONObject = a2.toString();
                            if (onFailureCallBack != null) {
                                OnFailureCallBack onFailureCallBack2 = onFailureCallBack;
                                int code = response.code();
                                onFailureCallBack2.onFailure(code, "code = " + response.code() + " msg = " + response.message() + " details = " + jSONObject);
                            }
                        }
                    };
                } else if (a2.has(NotificationCompat.CATEGORY_MESSAGE) && "conversation not found".equals(a2.optString(NotificationCompat.CATEGORY_MESSAGE))) {
                    h.this.f.post(new Runnable() {
                        @Override
                        public void run() {
                            if (onFailureCallBack != null) {
                                onFailureCallBack.onFailure(ErrorCode.CONV_END, "conversation not found");
                            }
                        }
                    });
                    return;
                } else if (!a2.has(WXImage.SUCCEED) || a2.optBoolean(WXImage.SUCCEED) || TextUtils.equals(a2.optString("result"), "queueing")) {
                    bVar.a(a2, response);
                    return;
                } else {
                    response.code();
                    a2.optString(NotificationCompat.CATEGORY_MESSAGE);
                    final String str = "no agent online";
                    if (a2.optBoolean("black")) {
                        i2 = ErrorCode.BLACKLIST;
                        str = "blacklist state";
                    } else {
                        i2 = ErrorCode.NO_AGENT_ONLINE;
                        if (request.url().toString().contains("https://new-api.meiqia.com/client/send_msg")) {
                            i2 = 20009;
                        }
                    }
                    handler = h.this.f;
                    runnable = new Runnable() {
                        @Override
                        public void run() {
                            if (onFailureCallBack != null) {
                                onFailureCallBack.onFailure(i2, str);
                            }
                        }
                    };
                }
                handler.post(runnable);
            }
        });
    }

    private void a(boolean z, String str, String str2, Map<String, Object> map, Map<String, String> map2, b bVar, final OnFailureCallBack onFailureCallBack) {
        RequestBody create;
        try {
            Request.Builder c2 = c(str);
            if (map2 != null) {
                for (Map.Entry<String, String> entry : map2.entrySet()) {
                    c2.addHeader(entry.getKey(), entry.getValue());
                }
            }
            if (z) {
                create = RequestBody.create(b, a(map));
            } else {
                create = RequestBody.create(b, com.meiqia.core.a.c.a((Map<?, ?>) map).toString());
                c2.removeHeader("Authorization");
            }
            HashMap hashMap = new HashMap();
            if (com.meiqia.core.d.a != null) {
                hashMap.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
            }
            hashMap.put("src", "android_sdk");
            c2.url(str2 + com.meiqia.core.a.c.a(str2, hashMap)).post(create);
            a(c2.build(), bVar, onFailureCallBack);
        } catch (Exception unused) {
            if (onFailureCallBack != null) {
                this.f.post(new Runnable() {
                    @Override
                    public void run() {
                        onFailureCallBack.onFailure(-1, "GeneralSecurityException");
                    }
                });
            }
        }
    }

    private void a(boolean z, String str, Map<String, Object> map, b bVar, OnFailureCallBack onFailureCallBack) {
        a(z, f(), str, map, (Map<String, String>) null, bVar, onFailureCallBack);
    }

    public static String b() {
        return c;
    }

    private void b(String str, Map<String, String> map, b bVar, final OnFailureCallBack onFailureCallBack) {
        try {
            if (com.meiqia.core.d.a != null && map != null) {
                map.put("src", "android_sdk");
                map.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
            }
            String a2 = com.meiqia.core.a.c.a(str, map);
            Request.Builder g2 = g();
            if (bVar != null && (bVar instanceof c)) {
                g2.removeHeader("Authorization");
            }
            g2.tag(str);
            a(g2.url(str + a2).get().build(), bVar, onFailureCallBack);
        } catch (Exception unused) {
            this.f.post(new Runnable() {
                @Override
                public void run() {
                    onFailureCallBack.onFailure(-1, "GeneralSecurityException");
                }
            });
        }
    }

    private Request.Builder c(String str) {
        Request.Builder builder = new Request.Builder();
        String str2 = MQManager.a + ":" + str + ":" + (((System.currentTimeMillis() / 1000) + 60) + "");
        String replaceAll = ("Mozilla/5.0 (Linux; Android " + Build.VERSION.RELEASE + "; " + Build.MODEL + Operators.SPACE_STR + Build.DEVICE + ") MeiqiaSDK/ Source/SDK " + MQManager.getMeiqiaSDKVersion() + " Language/" + Locale.getDefault().getLanguage()).replaceAll("[^\\x00-\\x7F]", "");
        builder.addHeader("Authorization", str2);
        builder.addHeader(IWebview.USER_AGENT, replaceAll);
        builder.addHeader("app_version", MQManager.getMeiqiaSDKVersion());
        builder.addHeader("app_platform", "android_sdk");
        builder.addHeader("app_channel", b());
        if (a) {
            builder.addHeader("alpha", AbsoluteConst.TRUE);
        }
        return builder;
    }

    private void c(String str, Map<String, Object> map, b bVar, final OnFailureCallBack onFailureCallBack) {
        try {
            a(g().url(str).put(RequestBody.create(b, a(map))).build(), bVar, onFailureCallBack);
        } catch (Exception unused) {
            this.f.post(new Runnable() {
                @Override
                public void run() {
                    onFailureCallBack.onFailure(-1, "GeneralSecurityException");
                }
            });
        }
    }

    public void d() {
        SSLContext sSLContext;
        X509TrustManager x509TrustManager = new X509TrustManager() {
            @Override
            public void checkClientTrusted(X509Certificate[] x509CertificateArr, String str) {
            }

            @Override
            public void checkServerTrusted(X509Certificate[] x509CertificateArr, String str) {
            }

            @Override
            public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
            }
        };
        TrustManager[] trustManagerArr = {x509TrustManager};
        SSLContext sSLContext2 = null;
        try {
            sSLContext = SSLContext.getInstance("SSL");
        } catch (KeyManagementException e2) {
            e = e2;
        } catch (NoSuchAlgorithmException e3) {
            e = e3;
        }
        try {
            sSLContext.init(null, trustManagerArr, new SecureRandom());
        } catch (KeyManagementException e4) {
            e = e4;
            sSLContext2 = sSLContext;
            e.printStackTrace();
            sSLContext = sSLContext2;
            OkHttpClient.Builder builder = new OkHttpClient.Builder();
            if (sSLContext != null) {
            }
        } catch (NoSuchAlgorithmException e5) {
            e = e5;
            sSLContext2 = sSLContext;
            e.printStackTrace();
            sSLContext = sSLContext2;
            OkHttpClient.Builder builder2 = new OkHttpClient.Builder();
            if (sSLContext != null) {
            }
        }
        OkHttpClient.Builder builder22 = new OkHttpClient.Builder();
        if (sSLContext != null) {
            e = builder22.sslSocketFactory(sSLContext.getSocketFactory(), x509TrustManager).hostnameVerifier(new HostnameVerifier() {
                @Override
                public boolean verify(String str, SSLSession sSLSession) {
                    return true;
                }
            }).build();
        }
    }

    public MQEnterpriseConfig e() {
        try {
            if (com.meiqia.core.d.c != null) {
                MQEnterpriseConfig mQEnterpriseConfig = new MQEnterpriseConfig();
                String q = com.meiqia.core.d.c.q(com.meiqia.core.d.a);
                if (TextUtils.isEmpty(q)) {
                    return null;
                }
                com.meiqia.core.a.c.a(mQEnterpriseConfig, new JSONObject(q), com.meiqia.core.d.c, com.meiqia.core.d.a);
                return mQEnterpriseConfig;
            }
            return null;
        } catch (Exception unused) {
            return null;
        }
    }

    private String f() {
        return com.meiqia.core.d.a != null ? com.meiqia.core.d.a.getTrackId() : "0";
    }

    private Request.Builder g() {
        return c(f());
    }

    public void a(long j2, int i2, String str, long j3, long j4, int i3, final OnEvaluateRobotAnswerCallback onEvaluateRobotAnswerCallback) {
        String str2 = "https://new-api.meiqia.com/knowledge/questions/" + j4 + "/evaluate";
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", com.meiqia.core.d.a.getTrackId());
        hashMap.put("ent_id", Integer.valueOf(Integer.parseInt(com.meiqia.core.d.a.getEnterpriseId())));
        hashMap.put("useful", Integer.valueOf(i3));
        if (i2 != -1) {
            hashMap.put("robot_id", Integer.valueOf(i2));
        }
        hashMap.put("client_question_text", str);
        if (j3 != -1) {
            hashMap.put("conv_id", Long.valueOf(j3));
        }
        hashMap.put("message_id", Long.valueOf(j2));
        hashMap.put("question_id", Long.valueOf(j4));
        a(false, str2, (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                onEvaluateRobotAnswerCallback.onSuccess(jSONObject.optString("message"));
            }
        }, (OnFailureCallBack) onEvaluateRobotAnswerCallback);
    }

    public void a(long j2, long j3, String str, long j4, final SimpleCallback simpleCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("conversation_id", Long.valueOf(j2));
        hashMap.put("msg_id", Long.valueOf(j3));
        hashMap.put("track_id", str);
        hashMap.put("ent_id", Long.valueOf(j4));
        a(false, "https://new-api.meiqia.com/client/file_downloaded", (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                SimpleCallback simpleCallback2 = simpleCallback;
                if (simpleCallback2 != null) {
                    simpleCallback2.onSuccess();
                }
            }
        }, (OnFailureCallBack) simpleCallback);
    }

    public void a(long j2, final e eVar) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", com.meiqia.core.d.a.getTrackId());
        b("https://new-api.meiqia.com/client/tickets_v2/" + j2, hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                eVar.a(jSONObject);
            }
        }, eVar);
    }

    public void a(long j2, String str, long j3, JSONArray jSONArray, b bVar) {
        HashMap hashMap = new HashMap();
        hashMap.put("ent_id", Long.valueOf(j2));
        hashMap.put("track_id", str);
        hashMap.put("conv_id", Long.valueOf(j3));
        hashMap.put("msg_ids", jSONArray);
        a(false, "https://new-api.meiqia.com/client/msg_delivered", (Map<String, Object>) hashMap, bVar, (OnFailureCallBack) null);
    }

    public void a(MQMessage mQMessage, final File file, final OnProgressCallback onProgressCallback) {
        b(mQMessage.getMedia_url(), null, new c() {
            {
                super();
            }

            @Override
            public void a(JSONObject jSONObject, Response response) {
                h.this.a(file, response, onProgressCallback);
            }
        }, onProgressCallback);
    }

    public void a(MQNotificationMessage mQNotificationMessage, final OnFailureCallBack onFailureCallBack) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", mQNotificationMessage.getTrackId());
        hashMap.put("ent_id", Long.valueOf(mQNotificationMessage.getEntId()));
        hashMap.put("mass_message_id", Long.valueOf(mQNotificationMessage.getMessageId()));
        hashMap.put("mass_message_push_id", Long.valueOf(mQNotificationMessage.getPushId()));
        a(true, "https://new-api.meiqia.com/unified-api/conversations/v1/client/sdk/mass_message_receipts", (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
            }
        }, new OnFailureCallBack() {
            @Override
            public void onFailure(int i2, String str) {
                onFailureCallBack.onFailure(i2, str);
            }
        });
    }

    public void a(OnGetClientCallback onGetClientCallback) {
        a((String) null, onGetClientCallback);
    }

    public void a(final SimpleCallback simpleCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", com.meiqia.core.d.a.getTrackId());
        hashMap.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
        a("https://new-api.meiqia.com/client/end_conversation", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                simpleCallback.onSuccess();
            }
        }, simpleCallback);
    }

    public void a(final d dVar) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", com.meiqia.core.d.a.getTrackId());
        hashMap.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
        b("https://new-api.meiqia.com/client/queue/position", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                dVar.a(jSONObject.optInt("position", -1));
            }
        }, dVar);
    }

    public void a(final e eVar) {
        HashMap hashMap = new HashMap();
        hashMap.put("enterprise_id", com.meiqia.core.d.a.getEnterpriseId());
        b("https://new-api.meiqia.com/client/tickets_v2/categories", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                eVar.a(jSONObject);
            }
        }, eVar);
    }

    public void a(File file, final b bVar, OnFailureCallBack onFailureCallBack) {
        String enterpriseId = com.meiqia.core.d.a != null ? com.meiqia.core.d.a.getEnterpriseId() : "";
        a(new Request.Builder().url("https://new-api.meiqia.com/upload?user_id=" + f() + "&ent_id=" + enterpriseId).post(new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("file", "file.jpeg", RequestBody.create(MediaType.parse("image/jpeg"), file)).build()).build(), new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                bVar.a(jSONObject, response);
            }
        }, onFailureCallBack);
    }

    public void a(final File file, final Map<String, String> map, final OnProgressCallback onProgressCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
        hashMap.put("content_type", "video");
        hashMap.put(AbsoluteConst.JSON_KEY_FILENAME, file.getName());
        a(false, "https://new-api.meiqia.com/upload/oss/policies", (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                String optString = jSONObject.optString("file_url");
                map.put("file_url", optString);
                map.put("thumb_url", optString + "?x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,ar_auto");
                JSONObject optJSONObject = jSONObject.optJSONObject("policy");
                JSONObject optJSONObject2 = optJSONObject.optJSONObject(MQInquireForm.KEY_INPUTS_FIELDS);
                map.put("key", optJSONObject2.optString("key"));
                String optString2 = optJSONObject.optString("url");
                RequestBody create = RequestBody.create(MediaType.parse("video/*"), file);
                MultipartBody.Builder type = new MultipartBody.Builder().setType(MultipartBody.FORM);
                Iterator<String> keys = optJSONObject2.keys();
                while (keys.hasNext()) {
                    String next = keys.next();
                    type.addFormDataPart(next, optJSONObject2.optString(next));
                }
                type.addFormDataPart("file", file.getName(), create);
                h.this.a(new Request.Builder().url(optString2).post(type.build()).build(), new b() {
                    @Override
                    public void a(JSONObject jSONObject2, Response response2) {
                        onProgressCallback.onSuccess();
                    }
                }, onProgressCallback);
            }
        }, (OnFailureCallBack) onProgressCallback);
    }

    public void a(String str) {
        for (Call call : e.dispatcher().queuedCalls()) {
            if (call.request().tag().equals(str)) {
                call.cancel();
            }
        }
    }

    public void a(String str, int i2) {
        String trackId = com.meiqia.core.d.a.getTrackId();
        String enterpriseId = com.meiqia.core.d.a.getEnterpriseId();
        HashMap hashMap = new HashMap();
        if (i2 != -1) {
            hashMap.put(MQCollectInfoActivity.AGENT_ID, Integer.valueOf(i2));
        }
        hashMap.put("track_id", trackId);
        hashMap.put("ent_id", enterpriseId);
        hashMap.put("type", "text");
        hashMap.put("content", str);
        a("https://new-api.meiqia.com/client/inputting", hashMap, (b) null, (OnFailureCallBack) null);
    }

    public void a(String str, int i2, int i3, int i4, String str2, int i5, final OnGetMessageListCallback onGetMessageListCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("limit", i2 + "");
        hashMap.put("ent_id", i4 + "");
        hashMap.put("last_message_created_on", str2);
        hashMap.put("ascending", i5 + "");
        hashMap.put("_time", String.valueOf(System.currentTimeMillis()));
        b("https://new-api.meiqia.com/conversation/" + str + "/messages_streams", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                List<MQMessage> a2 = com.meiqia.core.a.c.a(jSONObject.optJSONArray("messages"));
                Collections.sort(a2, new com.meiqia.core.a.h());
                onGetMessageListCallback.onSuccess(a2);
            }
        }, onGetMessageListCallback);
    }

    public void a(String str, int i2, String str2, final SimpleCallback simpleCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("app_key", MQManager.a);
        hashMap.put(MediaFormatExtraConstants.KEY_LEVEL, Integer.valueOf(i2));
        hashMap.put("content", str2);
        a(false, "https://new-api.meiqia.com/conversation/" + str + "/evaluation", (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                simpleCallback.onSuccess();
            }
        }, (OnFailureCallBack) simpleCallback);
    }

    public void a(String str, final OnGetClientCallback onGetClientCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("app_key", MQManager.a);
        if (!TextUtils.isEmpty(str)) {
            hashMap.put("track_id", str);
        }
        a(false, "https://new-api.meiqia.com/sdk/init_sdk_user", (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                String optString = jSONObject.optString("track_id");
                String optString2 = jSONObject.optString("enterprise_id");
                String optString3 = jSONObject.optString("browser_id");
                String optString4 = jSONObject.optString("visit_page_id");
                String optString5 = jSONObject.optString("visit_id");
                onGetClientCallback.onSuccess(true, jSONObject.optString("aes_key"), optString, optString2, optString3, optString4, optString5);
            }
        }, (OnFailureCallBack) onGetClientCallback);
    }

    public void a(String str, final OnRegisterDeviceTokenCallback onRegisterDeviceTokenCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("device_token", str);
        a("https://new-api.meiqia.com/client/device_token", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                onRegisterDeviceTokenCallback.onSuccess();
            }
        }, onRegisterDeviceTokenCallback);
    }

    public void a(String str, final SimpleCallback simpleCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", com.meiqia.core.d.a.getTrackId());
        hashMap.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
        hashMap.put("content", str);
        a(false, "https://new-api.meiqia.com/client/prechat-survey-msg", (Map<String, Object>) hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                SimpleCallback simpleCallback2 = simpleCallback;
                if (simpleCallback2 != null) {
                    simpleCallback2.onSuccess();
                }
            }
        }, (OnFailureCallBack) simpleCallback);
    }

    public void a(String str, final String str2, final OnValueCallback<List<MQNotificationMessage>> onValueCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", str);
        hashMap.put("ent_id", str2);
        b("https://new-api.meiqia.com/unified-api/conversations/v1/client/unreceived_mass_messages", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                ArrayList arrayList = new ArrayList();
                try {
                    JSONArray optJSONArray = jSONObject.optJSONArray(Constants.Name.ROWS);
                    for (int i2 = 0; i2 < optJSONArray.length(); i2++) {
                        MQNotificationMessage e2 = com.meiqia.core.a.c.e(optJSONArray.getJSONObject(i2));
                        e2.setEntId(Long.parseLong(str2));
                        arrayList.add(e2);
                    }
                } catch (Exception e3) {
                    e3.printStackTrace();
                }
                onValueCallback.onSuccess(arrayList);
            }
        }, new OnFailureCallBack() {
            @Override
            public void onFailure(int i2, String str3) {
                onValueCallback.onFailure(i2, str3);
            }
        });
    }

    public void a(String str, String str2, String str3, final SimpleCallback simpleCallback) {
        final File file = new File(str2, str3);
        e.newCall(new Request.Builder().url(str).build()).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException iOException) {
                simpleCallback.onFailure(0, "download failed");
            }

            @Override
            public void onResponse(Call call, Response response) {
                if (!response.isSuccessful()) {
                    simpleCallback.onFailure(0, "download failed");
                    return;
                }
                BufferedSink buffer = Okio.buffer(Okio.sink(file));
                buffer.writeAll(response.body().source());
                buffer.close();
                simpleCallback.onSuccess();
            }
        });
    }

    public void a(final String str, Map<String, Object> map, final SimpleCallback simpleCallback) {
        a(true, str, "https://new-api.meiqia.com/sdk/statistics", map, (Map<String, String>) null, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                com.meiqia.core.a.f.b("DvcInfo " + str);
                simpleCallback.onSuccess();
            }
        }, (OnFailureCallBack) simpleCallback);
    }

    public void a(String str, Map<String, Object> map, final InterfaceC0024h interfaceC0024h) {
        a(str, map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                JSONObject optJSONObject = jSONObject.optJSONObject(NotificationCompat.CATEGORY_MESSAGE);
                final String optString = jSONObject.optString("result");
                if (optJSONObject == null) {
                    h.this.f.post(new Runnable() {
                        @Override
                        public void run() {
                            if (TextUtils.equals(optString, "queueing")) {
                                interfaceC0024h.onFailure(ErrorCode.QUEUEING, "queueing");
                            } else {
                                interfaceC0024h.onFailure(20000, "msg object is null");
                            }
                        }
                    });
                    return;
                }
                String optString2 = optJSONObject.optString("created_on");
                long optLong = optJSONObject.optLong("id");
                JSONObject optJSONObject2 = jSONObject.optJSONObject("sensitive_content");
                String str2 = null;
                if (optJSONObject2 != null && optJSONObject2.optBoolean("contains_sensitive_words", false)) {
                    str2 = optJSONObject2.toString();
                }
                if (!TextUtils.isEmpty(optString)) {
                    JSONObject jSONObject2 = new JSONObject();
                    try {
                        jSONObject2.put("result", optString);
                        str2 = jSONObject2.toString();
                    } catch (JSONException e2) {
                        e2.printStackTrace();
                    }
                }
                interfaceC0024h.a(optString2, optLong, str2);
            }
        }, interfaceC0024h);
    }

    public void a(String str, Map<String, Object> map, Map<String, String> map2, final SimpleCallback simpleCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", str);
        hashMap.put("ent_id", com.meiqia.core.d.a.getEnterpriseId());
        hashMap.put("data", map);
        a(false, f(), "https://new-api.meiqia.com/client/forms", (Map<String, Object>) hashMap, map2, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                simpleCallback.onSuccess();
            }
        }, (OnFailureCallBack) simpleCallback);
    }

    public void a(Map<String, Object> map, long j2, final f fVar) {
        a(false, "https://new-api.meiqia.com/client/tickets_v2/" + j2 + "/replies", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                fVar.a(jSONObject.optString("created_at"), jSONObject.optLong("ticket_id"));
            }
        }, (OnFailureCallBack) fVar);
    }

    public void a(Map<String, Object> map, final OnClientInfoCallback onClientInfoCallback) {
        com.meiqia.core.a.f.b("setAttrs");
        c("https://new-api.meiqia.com/client/attrs", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                OnClientInfoCallback onClientInfoCallback2 = onClientInfoCallback;
                if (onClientInfoCallback2 != null) {
                    onClientInfoCallback2.onSuccess();
                }
            }
        }, onClientInfoCallback);
    }

    public void a(Map<String, String> map, final OnGetMessageListCallback onGetMessageListCallback) {
        b("https://new-api.meiqia.com/conversation/" + com.meiqia.core.d.a.getTrackId() + "/messages_streams", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                List<MQMessage> a2 = com.meiqia.core.a.c.a(jSONObject.optJSONArray("messages"));
                Collections.sort(a2, new com.meiqia.core.a.h());
                onGetMessageListCallback.onSuccess(a2);
            }
        }, onGetMessageListCallback);
    }

    public void a(Map<String, Object> map, final SuccessCallback successCallback) {
        map.put("track_id", com.meiqia.core.d.a.getTrackId());
        a(false, "https://new-api.meiqia.com/client/" + com.meiqia.core.d.a.getTrackId() + "/reply_card", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                h.this.f.post(new Runnable() {
                    @Override
                    public void run() {
                        successCallback.onSuccess();
                    }
                });
            }
        }, (OnFailureCallBack) successCallback);
    }

    public void a(final Map<String, Object> map, final a aVar) {
        a("https://new-api.meiqia.com/scheduler", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                MQAgent c2;
                boolean equals = TextUtils.equals(jSONObject.optString("result"), "queueing");
                if (equals) {
                    aVar.a(equals, null, null, null);
                } else {
                    JSONObject optJSONObject = jSONObject.optJSONObject("agent");
                    JSONObject optJSONObject2 = jSONObject.optJSONObject("conv");
                    if (optJSONObject == null) {
                        c2 = new MQAgent();
                        c2.setIsOnline(true);
                        c2.setStatus("online");
                        MQEnterpriseConfig e2 = h.this.e();
                        if (com.meiqia.core.d.c != null && e2 != null) {
                            c2.setNickname(e2.public_nickname);
                            c2.setAvatar(e2.avatar);
                        }
                    } else {
                        c2 = com.meiqia.core.a.c.c(optJSONObject);
                    }
                    MQConversation d2 = com.meiqia.core.a.c.d(optJSONObject2);
                    d2.setAgent_id(c2.getId());
                    aVar.a(false, c2, d2, com.meiqia.core.a.c.a(jSONObject.optJSONArray("messages")));
                }
                com.meiqia.core.a.f.b("scheduler " + map.get("track_id"));
            }
        }, aVar);
    }

    public void a(Map<String, Object> map, final e eVar) {
        a(false, "https://new-api.meiqia.com/sdk/init", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                if (jSONObject != null) {
                    eVar.a(jSONObject);
                } else {
                    h.this.f.post(new Runnable() {
                        @Override
                        public void run() {
                            eVar.onFailure(20000, "UNKNOW");
                        }
                    });
                }
            }
        }, (OnFailureCallBack) eVar);
    }

    public void a(Map<String, Object> map, final f fVar) {
        a(false, "https://new-api.meiqia.com/client/tickets_v2", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                fVar.a(jSONObject.optString("created_at"), jSONObject.optLong("id"));
            }
        }, (OnFailureCallBack) fVar);
    }

    public void a(Map<String, Object> map, final g gVar) {
        a("https://new-api.meiqia.com/client/tickets", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                gVar.a(jSONObject.optJSONArray("replies"));
            }
        }, gVar);
    }

    public void a(Map<String, String> map, String str, final OnGetMessageListCallback onGetMessageListCallback) {
        b("https://new-api.meiqia.com/client/tickets_v2/" + str + "/replies", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                List<MQMessage> a2 = com.meiqia.core.a.c.a(jSONObject.optJSONArray("replies"));
                Collections.sort(a2, new com.meiqia.core.a.h());
                onGetMessageListCallback.onSuccess(a2);
            }
        }, onGetMessageListCallback);
    }

    public void b(long j2, String str, long j3, JSONArray jSONArray, b bVar) {
        HashMap hashMap = new HashMap();
        hashMap.put("ent_id", Long.valueOf(j2));
        hashMap.put("track_id", str);
        hashMap.put("conv_id", Long.valueOf(j3));
        hashMap.put("msg_ids", jSONArray);
        a(false, "https://new-api.meiqia.com/client/msg_read", (Map<String, Object>) hashMap, bVar, (OnFailureCallBack) null);
    }

    public void b(MQNotificationMessage mQNotificationMessage, final OnFailureCallBack onFailureCallBack) {
        HashMap hashMap = new HashMap();
        hashMap.put("track_id", mQNotificationMessage.getTrackId());
        hashMap.put("ent_id", Long.valueOf(mQNotificationMessage.getEntId()));
        hashMap.put("conv_id", Long.valueOf(mQNotificationMessage.getConvId()));
        hashMap.put("mass_message_push_id", Long.valueOf(mQNotificationMessage.getPushId()));
        c("https://new-api.meiqia.com/unified-api/conversations/v1/client/sdk/mass_messages/" + mQNotificationMessage.getMessageId() + "/open", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
            }
        }, new OnFailureCallBack() {
            @Override
            public void onFailure(int i2, String str) {
                onFailureCallBack.onFailure(i2, str);
            }
        });
    }

    public void b(File file, final b bVar, OnFailureCallBack onFailureCallBack) {
        String str = "https://new-api.meiqia.com/upload?user_id=" + f() + "&ent_id=" + (com.meiqia.core.d.a != null ? com.meiqia.core.d.a.getEnterpriseId() : "");
        file.exists();
        a(new Request.Builder().url(str).post(new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("file", "file.amr", RequestBody.create(MediaType.parse("audio/amr"), file)).build()).build(), new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                bVar.a(jSONObject, response);
            }
        }, onFailureCallBack);
    }

    public void b(String str) {
        c = str;
    }

    public void b(String str, final OnGetClientCallback onGetClientCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("dev_client_id", str);
        a("https://new-api.meiqia.com/sdk/get_dev_client_id", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                boolean optBoolean = jSONObject.optBoolean("found_client");
                String optString = jSONObject.optString("track_id");
                String optString2 = jSONObject.optString("enterprise_id");
                String optString3 = jSONObject.optString("browser_id");
                String optString4 = jSONObject.optString("visit_page_id");
                String optString5 = jSONObject.optString("visit_id");
                onGetClientCallback.onSuccess(optBoolean, jSONObject.optString("aes_key"), optString, optString2, optString3, optString4, optString5);
            }
        }, onGetClientCallback);
    }

    public void b(String str, final OnRegisterDeviceTokenCallback onRegisterDeviceTokenCallback) {
        HashMap hashMap = new HashMap();
        hashMap.put("device_token", str);
        a("https://new-api.meiqia.com/sdk/refresh_push_info", hashMap, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                onRegisterDeviceTokenCallback.onSuccess();
            }
        }, onRegisterDeviceTokenCallback);
    }

    public void b(Map<String, Object> map, final OnClientInfoCallback onClientInfoCallback) {
        com.meiqia.core.a.f.b("setEvents");
        a(false, "https://new-api.meiqia.com/client/client_events", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                OnClientInfoCallback onClientInfoCallback2 = onClientInfoCallback;
                if (onClientInfoCallback2 != null) {
                    onClientInfoCallback2.onSuccess();
                }
            }
        }, (OnFailureCallBack) onClientInfoCallback);
    }

    public void b(Map<String, Object> map, final SuccessCallback successCallback) {
        a(true, "https://new-api.meiqia.com/mpush/copy/statistics", map, new b() {
            @Override
            public void a(JSONObject jSONObject, Response response) {
                h.this.f.post(new Runnable() {
                    @Override
                    public void run() {
                        successCallback.onSuccess();
                    }
                });
            }
        }, (OnFailureCallBack) successCallback);
    }

    public void c() {
        e.dispatcher().cancelAll();
    }
}