QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685

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


package com.tencent.now.utils.https;

import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.tencent.common.http.IHttpCookieManager;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.http.MttResponse;
import com.tencent.common.http.Requester;
import com.tencent.common.http.RequesterFactory;
import com.tencent.common.threadpool.BrowserExecutorSupplier;
import com.tencent.mtt.base.NowSdkFactory;
import com.tencent.mtt.businesscenter.facade.IConfigService;
import com.tencent.mtt.qbcontext.core.QBContext;
import com.tencent.now.utils.https.HttpsInterface;
import com.tencent.now.utils.log.LogFactory;
import com.tencent.now.utils.log.LogInterface;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import java.util.zip.GZIPInputStream;
import kotlin.text.Typography;
import org.json.JSONObject;

public class QBHttpsUtil implements HttpsInterface {

    private LogInterface f76117a = LogFactory.a();

    public void a(StringBuffer stringBuffer) {
        a(stringBuffer, "qua", NowSdkFactory.a().j().f31577d);
        a(stringBuffer, "guid", NowSdkFactory.a().j().f31576c);
        a(stringBuffer, "qbid", NowSdkFactory.a().j().e);
    }

    private void a(StringBuffer stringBuffer, String str, String str2) {
        if (stringBuffer.length() != 0) {
            stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
        }
        if (TextUtils.isEmpty(str) || TextUtils.isEmpty(str2)) {
            this.f76117a.e("QBHttpsUtil", String.format("key = %s, value = %s", str, str2));
            return;
        }
        stringBuffer.append(str);
        stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
        stringBuffer.append(str2);
    }

    public void a(final boolean z, final int i, final JSONObject jSONObject, final HttpsInterface.CallBack callBack, final String str) {
        new Handler(Looper.getMainLooper()).post(new Runnable() {
            @Override
            public void run() {
                if (z) {
                    HttpsInterface.CallBack callBack2 = callBack;
                    if (callBack2 != null) {
                        callBack2.a(jSONObject);
                        return;
                    }
                    return;
                }
                HttpsInterface.CallBack callBack3 = callBack;
                if (callBack3 != null) {
                    callBack3.a(i, str);
                }
            }
        });
    }

    @Override
    public void a(final String str, final String str2, final HttpsInterface.CallBack callBack, final String str3) {
        BrowserExecutorSupplier.postForBackgroundTasks(new BrowserExecutorSupplier.BackgroundRunable() {
            @Override
            public void doRun() {
                QBHttpsUtil qBHttpsUtil;
                boolean z;
                int intValue;
                JSONObject jSONObject;
                HttpsInterface.CallBack callBack2;
                String str4;
                Requester requester = RequesterFactory.getRequester();
                MttRequestBase mttRequestBase = RequesterFactory.getMttRequestBase();
                mttRequestBase.setUrl(str);
                mttRequestBase.setMethod((byte) 1);
                mttRequestBase.setRequestType(MttRequestBase.REQUEST_NORMAL);
                mttRequestBase.setCookie(str3);
                mttRequestBase.addHeader("Content-Type", "application/x-www-form-urlencoded");
                mttRequestBase.addHeader("Referer", "https://now.qq.com");
                try {
                    mttRequestBase.setPostData(str2);
                    MttResponse execute = requester.execute(mttRequestBase);
                    if (execute.getStatusCode().intValue() == 200) {
                        BufferedReader bufferedReader = new BufferedReader("gzip".equals(execute.getContentEncoding()) ? new InputStreamReader(new GZIPInputStream(execute.getInputStream())) : new InputStreamReader(execute.getInputStream()));
                        StringBuilder sb = new StringBuilder();
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else {
                                sb.append(readLine);
                            }
                        }
                        jSONObject = new JSONObject(sb.toString());
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = true;
                        intValue = 0;
                        callBack2 = callBack;
                        str4 = "";
                    } else {
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = false;
                        intValue = execute.getStatusCode().intValue();
                        jSONObject = null;
                        callBack2 = callBack;
                        str4 = "";
                    }
                    qBHttpsUtil.a(z, intValue, jSONObject, callBack2, str4);
                } catch (Exception e) {
                    QBHttpsUtil.this.a(false, -1, null, callBack, e.getMessage());
                    QBHttpsUtil.this.f76117a.e("QBHttpsUtil", String.format("url=%s, param=%s, cookie=%s, exception= %s", str, str2.toString(), str3, e.getMessage()));
                }
            }
        });
    }

    @Override
    public void a(final String str, final Map<String, String> map, final HttpsInterface.CallBack callBack, final String str2) {
        BrowserExecutorSupplier.postForBackgroundTasks(new BrowserExecutorSupplier.BackgroundRunable() {
            @Override
            public void doRun() {
                QBHttpsUtil qBHttpsUtil;
                boolean z;
                int intValue;
                JSONObject jSONObject;
                HttpsInterface.CallBack callBack2;
                String str3;
                Requester requester = RequesterFactory.getRequester();
                MttRequestBase mttRequestBase = RequesterFactory.getMttRequestBase();
                mttRequestBase.setUrl(str);
                mttRequestBase.setMethod((byte) 1);
                mttRequestBase.setRequestType(MttRequestBase.REQUEST_NORMAL);
                StringBuffer stringBuffer = new StringBuffer();
                mttRequestBase.setCookie(str2);
                mttRequestBase.addHeader("Content-Type", "application/x-www-form-urlencoded");
                mttRequestBase.addHeader("Referer", "https://now.qq.com");
                try {
                    if (map != null) {
                        for (Map.Entry entry : map.entrySet()) {
                            if (stringBuffer.length() != 0) {
                                stringBuffer.append(Typography.amp);
                            }
                            stringBuffer.append(URLEncoder.encode((String) entry.getKey(), "UTF-8"));
                            stringBuffer.append('=');
                            stringBuffer.append(URLEncoder.encode(String.valueOf(entry.getValue()), "UTF-8"));
                        }
                    }
                    QBHttpsUtil.this.a(stringBuffer);
                    mttRequestBase.setPostData(stringBuffer.toString());
                    MttResponse execute = requester.execute(mttRequestBase);
                    if (execute.getStatusCode().intValue() == 200) {
                        BufferedReader bufferedReader = new BufferedReader("gzip".equals(execute.getContentEncoding()) ? new InputStreamReader(execute.getInputStream()) : new InputStreamReader(execute.getInputStream()));
                        StringBuilder sb = new StringBuilder();
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else {
                                sb.append(readLine);
                            }
                        }
                        jSONObject = new JSONObject(sb.toString());
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = true;
                        intValue = 0;
                        callBack2 = callBack;
                        str3 = "";
                    } else {
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = false;
                        intValue = execute.getStatusCode().intValue();
                        jSONObject = null;
                        callBack2 = callBack;
                        str3 = "";
                    }
                    qBHttpsUtil.a(z, intValue, jSONObject, callBack2, str3);
                } catch (Exception e) {
                    QBHttpsUtil.this.a(false, -1, null, callBack, e.getMessage());
                    QBHttpsUtil.this.f76117a.e("QBHttpsUtil", String.format("url=%s, param=%s, cookie=%s, exception= %s", str, map.toString(), str2, e.getMessage()));
                }
            }
        });
    }

    @Override
    public void a(final String str, final JSONObject jSONObject, final HttpsInterface.CallBack callBack) {
        BrowserExecutorSupplier.postForBackgroundTasks(new BrowserExecutorSupplier.BackgroundRunable() {
            @Override
            public void doRun() {
                QBHttpsUtil qBHttpsUtil;
                boolean z;
                int intValue;
                JSONObject jSONObject2;
                HttpsInterface.CallBack callBack2;
                String str2;
                Requester requester = RequesterFactory.getRequester();
                MttRequestBase mttRequestBase = RequesterFactory.getMttRequestBase();
                mttRequestBase.setUrl(str);
                mttRequestBase.setMethod((byte) 1);
                mttRequestBase.setRequestType(MttRequestBase.REQUEST_NORMAL);
                new StringBuffer();
                mttRequestBase.addHeader("Content-Type", "application/json");
                try {
                    mttRequestBase.setPostData(jSONObject.toString());
                    MttResponse execute = requester.execute(mttRequestBase);
                    if (execute.getStatusCode().intValue() == 200) {
                        BufferedReader bufferedReader = new BufferedReader("gzip".equals(execute.getContentEncoding()) ? new InputStreamReader(new GZIPInputStream(execute.getInputStream())) : new InputStreamReader(execute.getInputStream()));
                        StringBuilder sb = new StringBuilder();
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else {
                                sb.append(readLine);
                            }
                        }
                        jSONObject2 = new JSONObject(sb.toString());
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = true;
                        intValue = 0;
                        callBack2 = callBack;
                        str2 = "";
                    } else {
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = false;
                        intValue = execute.getStatusCode().intValue();
                        jSONObject2 = null;
                        callBack2 = callBack;
                        str2 = "";
                    }
                    qBHttpsUtil.a(z, intValue, jSONObject2, callBack2, str2);
                } catch (Exception e) {
                    QBHttpsUtil.this.a(false, -1, null, callBack, e.getMessage());
                }
            }
        });
    }

    @Override
    public void a(final String str, final JSONObject jSONObject, final HttpsInterface.CallBack callBack, final String str2) {
        BrowserExecutorSupplier.postForBackgroundTasks(new BrowserExecutorSupplier.BackgroundRunable() {
            @Override
            public void doRun() {
                QBHttpsUtil qBHttpsUtil;
                boolean z;
                int intValue;
                JSONObject jSONObject2;
                HttpsInterface.CallBack callBack2;
                String str3;
                Requester requester = RequesterFactory.getRequester();
                MttRequestBase mttRequestBase = RequesterFactory.getMttRequestBase();
                mttRequestBase.setUrl(str);
                mttRequestBase.setMethod((byte) 1);
                mttRequestBase.setRequestType(MttRequestBase.REQUEST_NORMAL);
                new StringBuffer();
                mttRequestBase.addHeader("Content-Type", "application/json");
                mttRequestBase.addHeader("Referer", "https://now.qq.com");
                mttRequestBase.setCookieManager(new IHttpCookieManager() {
                    @Override
                    public String getCookie(String str4) {
                        return str2;
                    }

                    @Override
                    public String getQCookie(String str4) {
                        return str2;
                    }

                    @Override
                    public boolean isQQDomain(URL url) {
                        if (url == null) {
                            return false;
                        }
                        return ((IConfigService) QBContext.getInstance().getService(IConfigService.class)).isQQDomain(url.getHost(), true);
                    }

                    @Override
                    public void setCookie(URL url, Map<String, List<String>> map) {
                    }

                    @Override
                    public void setQCookie(String str4, String str5) {
                    }
                });
                mttRequestBase.addHeaders(false, true, false);
                try {
                    mttRequestBase.setPostData(jSONObject.toString());
                    requester.setCookieManager(new IHttpCookieManager() {
                        @Override
                        public String getCookie(String str4) {
                            return str2;
                        }

                        @Override
                        public String getQCookie(String str4) {
                            return str2;
                        }

                        @Override
                        public boolean isQQDomain(URL url) {
                            if (url == null) {
                                return false;
                            }
                            return ((IConfigService) QBContext.getInstance().getService(IConfigService.class)).isQQDomain(url.getHost(), true);
                        }

                        @Override
                        public void setCookie(URL url, Map<String, List<String>> map) {
                        }

                        @Override
                        public void setQCookie(String str4, String str5) {
                        }
                    });
                    MttResponse execute = requester.execute(mttRequestBase);
                    if (execute.getStatusCode().intValue() == 200) {
                        BufferedReader bufferedReader = new BufferedReader("gzip".equals(execute.getContentEncoding()) ? new InputStreamReader(new GZIPInputStream(execute.getInputStream())) : new InputStreamReader(execute.getInputStream()));
                        StringBuilder sb = new StringBuilder();
                        while (true) {
                            String readLine = bufferedReader.readLine();
                            if (readLine == null) {
                                break;
                            } else {
                                sb.append(readLine);
                            }
                        }
                        jSONObject2 = new JSONObject(sb.toString());
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = true;
                        intValue = 0;
                        callBack2 = callBack;
                        str3 = "";
                    } else {
                        qBHttpsUtil = QBHttpsUtil.this;
                        z = false;
                        intValue = execute.getStatusCode().intValue();
                        jSONObject2 = null;
                        callBack2 = callBack;
                        str3 = "";
                    }
                    qBHttpsUtil.a(z, intValue, jSONObject2, callBack2, str3);
                } catch (Exception e) {
                    QBHttpsUtil.this.a(false, -1, null, callBack, e.getMessage());
                    QBHttpsUtil.this.f76117a.e("QBHttpsUtil", String.format("url=%s, param=%s, cookie=%s, exception= %s", str, jSONObject.toString(), str2, e.getMessage()));
                }
            }
        });
    }
}