QQ浏览器 v12.2.3.7053版本的 MD5 值为:8285ab3059e5c8b521a264dfbc5c3685
以下内容为反编译后的 TranslateTask.java 源代码,内容仅作参考
package com.tencent.mtt.external.pagetoolbox.quicktranslate;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.huawei.hms.framework.common.ContainerUtils;
import com.huawei.hms.push.constant.RemoteMessageConst;
import com.tencent.common.http.MttInputStream;
import com.tencent.common.http.MttRequestBase;
import com.tencent.common.http.MttResponse;
import com.tencent.mtt.R;
import com.tencent.mtt.base.skin.MttResources;
import com.tencent.mtt.base.task.NetworkTask;
import com.tencent.mtt.base.task.Task;
import com.tencent.mtt.external.pagetoolbox.facade.OnResultHintViewClickListener;
import com.tencent.mtt.log.access.Logs;
import com.tencent.mtt.setting.PublicSettingManager;
import com.tencent.mtt.view.toast.MttToaster;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
import org.apache.http.NameValuePair;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
public class TranslateTask extends Task {
private String f56240a;
private final String f56241b = "https://fy.iciba.com/api/tencent.php";
private final String f56242c = "110109198001010038";
private final String f56243d = "https://tmt.tencentcloudapi.com";
private final String e = "AKIDNYZMyLHm9HrHSSdyRv98wWv4ye5YqoX5";
private final String f = "Z1E4ez82kBSVI5ey25tNdWAYlkY7UfcL";
private Handler g;
private Context h;
private OnResultHintViewClickListener i;
public TranslateTask(Context context, String str, OnResultHintViewClickListener onResultHintViewClickListener) {
this.f56240a = str;
this.h = context;
this.i = onResultHintViewClickListener;
a();
}
public String a(String str) {
if (TextUtils.isEmpty(str)) {
return MttResources.l(R.string.bqx);
}
try {
Object nextValue = new JSONTokener(str).nextValue();
if (nextValue == null || !(nextValue instanceof JSONObject)) {
return MttResources.l(R.string.br0);
}
JSONObject jSONObject = (JSONObject) nextValue;
if (!jSONObject.has("Error")) {
if (!jSONObject.has("Response")) {
return MttResources.l(R.string.br0);
}
JSONObject jSONObject2 = jSONObject.getJSONObject("Response");
if (jSONObject2 == null || !jSONObject2.has("TargetText")) {
return MttResources.l(R.string.br0);
}
String obj = jSONObject2.get("TargetText").toString();
return obj != null ? obj : MttResources.l(R.string.br0);
}
JSONObject jSONObject3 = jSONObject.getJSONObject("Error");
String string = jSONObject3.has("Code") ? jSONObject3.getString("Code") : "";
String string2 = jSONObject3.has("Message") ? jSONObject3.getString("Message") : "";
Logs.e(TranslateTask.class.getSimpleName(), "errCode : " + string + " ; errorMsg : " + string2);
char c2 = 65535;
switch (string.hashCode()) {
case -1805899673:
if (string.equals("AuthFailure.UnauthorizedOperation")) {
c2 = 5;
break;
}
break;
case -1693386453:
if (string.equals("InternalError")) {
c2 = '\f';
break;
}
break;
case -1606676670:
if (string.equals("ResourceUnavailable")) {
c2 = 3;
break;
}
break;
case -1493513981:
if (string.equals("MissingParameter")) {
c2 = 19;
break;
}
break;
case -1181827405:
if (string.equals("UnauthorizedOperation")) {
c2 = 4;
break;
}
break;
case -1080408387:
if (string.equals("ResourceNotFound")) {
c2 = 2;
break;
}
break;
case -911345939:
if (string.equals("InvalidAction")) {
c2 = 15;
break;
}
break;
case -465368577:
if (string.equals("RequestLimitExceeded")) {
c2 = 21;
break;
}
break;
case -329110162:
if (string.equals("AuthFailure.MFAFailure")) {
c2 = 7;
break;
}
break;
case -272092176:
if (string.equals("NoSuchVersion")) {
c2 = 20;
break;
}
break;
case -201654135:
if (string.equals("FailedOperation.NoFreeAmount")) {
c2 = 22;
break;
}
break;
case 126584657:
if (string.equals("ResourceInsufficient")) {
c2 = 1;
break;
}
break;
case 337669010:
if (string.equals("InvalidParameter")) {
c2 = 16;
break;
}
break;
case 343384319:
if (string.equals("InvalidParameterValue")) {
c2 = 17;
break;
}
break;
case 529031206:
if (string.equals("FailedOperation.UserNotRegistered")) {
c2 = 24;
break;
}
break;
case 932177934:
if (string.equals("LimitExceeded")) {
c2 = 18;
break;
}
break;
case 1019383947:
if (string.equals("AuthFailure.SignatureExpire")) {
c2 = '\t';
break;
}
break;
case 1543970672:
if (string.equals("InternalError.BackendTimeout")) {
c2 = '\r';
break;
}
break;
case 1709265814:
if (string.equals("AuthFailure.InvalidSecretId")) {
c2 = 6;
break;
}
break;
case 1758054036:
if (string.equals("ResourceInUse")) {
c2 = 0;
break;
}
break;
case 1758792606:
if (string.equals("AuthFailure.SignatureFailure")) {
c2 = '\n';
break;
}
break;
case 1793262909:
if (string.equals("AuthFailure.TokenFailure")) {
c2 = 11;
break;
}
break;
case 1802870053:
if (string.equals("InternalError.ErrorUnknown")) {
c2 = 14;
break;
}
break;
case 2046000442:
if (string.equals("FailedOperation.ServiceIsolate")) {
c2 = 23;
break;
}
break;
case 2089424742:
if (string.equals("AuthFailure.SecretIdNotFound")) {
c2 = '\b';
break;
}
break;
}
switch (c2) {
case 0:
case 1:
case 2:
case 3:
return MttResources.l(R.string.br3);
case 4:
case 5:
case 6:
case 7:
case '\b':
case '\t':
case '\n':
case 11:
return MttResources.l(R.string.bqy);
case '\f':
case '\r':
case 14:
case 15:
case 16:
case 17:
case 18:
case 19:
case 20:
case 21:
case 22:
case 23:
case 24:
return MttResources.l(R.string.br2);
default:
return MttResources.l(R.string.br1);
}
} catch (Exception e) {
return e instanceof JSONException ? MttResources.l(R.string.bqz) : MttResources.l(R.string.bqx);
}
}
private String a(String str, String str2) {
try {
SecretKeySpec secretKeySpec = new SecretKeySpec(str2.getBytes(), "HmacSHA1");
Mac mac = Mac.getInstance("HmacSHA1");
mac.init(secretKeySpec);
byte[] encodeBase64 = Base64.encodeBase64(mac.doFinal(str.getBytes()));
if (encodeBase64 != null) {
return new String(encodeBase64);
}
} catch (NullPointerException | InvalidKeyException | NoSuchAlgorithmException unused) {
}
return null;
}
private String a(String str, String str2, HashMap<String, String> hashMap) {
ArrayList arrayList = new ArrayList(hashMap.keySet());
Collections.sort(arrayList);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(str);
stringBuffer.append(str2);
stringBuffer.append("/?");
for (int i = 0; i < arrayList.size(); i++) {
stringBuffer.append((String) arrayList.get(i));
stringBuffer.append(ContainerUtils.KEY_VALUE_DELIMITER);
stringBuffer.append(hashMap.get(arrayList.get(i)));
if (i < arrayList.size() - 1) {
stringBuffer.append(ContainerUtils.FIELD_DELIMITER);
}
}
return stringBuffer.toString();
}
private List<NameValuePair> a(HashMap<String, String> hashMap) {
ArrayList arrayList = new ArrayList();
for (String str : hashMap.keySet()) {
arrayList.add(new BasicNameValuePair(str, hashMap.get(str)));
}
return arrayList;
}
private void a() {
this.g = new Handler(Looper.getMainLooper()) {
@Override
public void handleMessage(Message message) {
if (message.what == 3) {
String string = message.getData().getString("RetStr");
String string2 = message.getData().getString("ResStr");
String string3 = message.getData().getString("FullInfo");
boolean z = message.getData().getBoolean("isEnglishWord", false);
if (TextUtils.isEmpty(string)) {
return;
}
if (TranslateTask.this.h != null) {
new TranslateResultDialogUtil().a(TranslateTask.this.h, string2, string, string3, z, TranslateTask.this.i);
} else {
MttToaster.show(string, 0);
}
}
}
};
}
public void a(String str, Message message) {
Bundle bundle = new Bundle();
bundle.putString("ResStr", this.f56240a);
bundle.putString("RetStr", a(str));
bundle.putString("FullInfo", str);
message.setData(bundle);
message.sendToTarget();
}
private void a(String str, String str2, String str3, final Message message) {
ArrayList arrayList = new ArrayList(2);
arrayList.add(new BasicNameValuePair("q", str3));
arrayList.add(new BasicNameValuePair("from", "auto"));
arrayList.add(new BasicNameValuePair(RemoteMessageConst.TO, "auto"));
arrayList.add(new BasicNameValuePair("key", str2));
new NetworkTask(str, URLEncodedUtils.format(arrayList, "UTF-8").getBytes(), new NetworkTask.NetworkTaskCallback() {
@Override
public void onTaskFailed(MttRequestBase mttRequestBase, int i) {
TranslateTask.this.a("", message);
}
@Override
public void onTaskSuccess(MttRequestBase mttRequestBase, MttResponse mttResponse) {
BufferedReader bufferedReader;
if (mttResponse != null && 200 == mttResponse.getStatusCode().intValue()) {
MttInputStream inputStream = mttResponse.getInputStream();
try {
StringBuffer stringBuffer = new StringBuffer();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
String stringBuffer2 = stringBuffer.toString();
Bundle bundle = new Bundle();
bundle.putString("ResStr", TranslateTask.this.f56240a);
bundle.putString("RetStr", TranslateTask.this.b(stringBuffer2));
bundle.putString("FullInfo", stringBuffer2);
message.setData(bundle);
message.sendToTarget();
try {
bufferedReader.close();
return;
} catch (IOException unused) {
return;
}
}
stringBuffer.append(readLine);
} catch (IOException unused2) {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused3) {
}
}
TranslateTask.this.a("", message);
} catch (Throwable th) {
th = th;
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused4) {
}
}
throw th;
}
}
} catch (IOException unused5) {
bufferedReader = null;
} catch (Throwable th2) {
th = th2;
bufferedReader = null;
}
}
TranslateTask.this.a("", message);
}
}).d();
}
public String b(String str) {
int i;
if (TextUtils.isEmpty(str) || str.indexOf("\"error\"") == -1) {
return MttResources.l(R.string.bqx);
}
try {
JSONObject jSONObject = (JSONObject) new JSONTokener(str).nextValue();
int i2 = jSONObject.getInt("error");
if (i2 != 0) {
i = i2 != 509 ? i2 != 501 ? i2 != 502 ? R.string.br1 : R.string.bqy : R.string.br3 : R.string.br2;
} else {
try {
return jSONObject.getString("ret");
} catch (JSONException unused) {
i = R.string.br0;
}
}
return MttResources.l(i);
} catch (Exception e) {
return e instanceof JSONException ? MttResources.l(R.string.bqz) : MttResources.l(R.string.bqx);
}
}
private void b(String str, Message message) {
if (TextUtils.isEmpty(str)) {
a(MttResources.l(R.string.bqw), message);
} else if (PublicSettingManager.a().getBoolean("key_translate_use_fanyijun", true)) {
c(str, message);
} else {
a("https://fy.iciba.com/api/tencent.php", "110109198001010038", str, message);
}
}
private void c(String str, final Message message) {
if (str == null) {
return;
}
String replaceAll = str.replaceAll("\"", " "").replaceAll("'", "'");
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("Action", "TextTranslate");
hashMap.put("Region", "ap-guangzhou");
hashMap.put("Timestamp", String.valueOf(System.currentTimeMillis() / 1000));
hashMap.put("Nonce", String.valueOf(new Random().nextInt(Integer.MAX_VALUE)));
hashMap.put("SecretId", "AKIDNYZMyLHm9HrHSSdyRv98wWv4ye5YqoX5");
hashMap.put("Version", "2018-03-21");
hashMap.put("SourceText", replaceAll);
hashMap.put("Source", "auto");
hashMap.put("Target", "zh,en");
hashMap.put("ProjectId", "0");
String a2 = a("POST", "tmt.tencentcloudapi.com", hashMap);
if (TextUtils.isEmpty(a2)) {
a("", message);
return;
}
String a3 = a(a2, "Z1E4ez82kBSVI5ey25tNdWAYlkY7UfcL");
if (TextUtils.isEmpty(a3)) {
a("", message);
} else {
hashMap.put("Signature", a3);
new NetworkTask("https://tmt.tencentcloudapi.com", URLEncodedUtils.format(a(hashMap), "UTF-8").getBytes(), new NetworkTask.NetworkTaskCallback() {
@Override
public void onTaskFailed(MttRequestBase mttRequestBase, int i) {
TranslateTask.this.a("", message);
}
@Override
public void onTaskSuccess(MttRequestBase mttRequestBase, MttResponse mttResponse) {
BufferedReader bufferedReader;
if (mttResponse != null && 200 == mttResponse.getStatusCode().intValue()) {
MttInputStream inputStream = mttResponse.getInputStream();
try {
StringBuffer stringBuffer = new StringBuffer();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
while (true) {
try {
String readLine = bufferedReader.readLine();
if (readLine == null) {
String stringBuffer2 = stringBuffer.toString();
bufferedReader.close();
String a4 = TranslateTask.this.a(stringBuffer2);
Bundle bundle = new Bundle();
bundle.putString("ResStr", TranslateTask.this.f56240a);
bundle.putString("RetStr", a4);
bundle.putString("FullInfo", stringBuffer2);
bundle.putBoolean("isEnglishWord", false);
message.setData(bundle);
message.sendToTarget();
try {
bufferedReader.close();
return;
} catch (IOException unused) {
return;
}
}
stringBuffer.append(readLine);
} catch (IOException unused2) {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused3) {
}
}
TranslateTask.this.a("", message);
} catch (Throwable th) {
th = th;
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException unused4) {
}
}
throw th;
}
}
} catch (IOException unused5) {
bufferedReader = null;
} catch (Throwable th2) {
th = th2;
bufferedReader = null;
}
}
TranslateTask.this.a("", message);
}
}).d();
}
}
@Override
public void cancel() {
}
@Override
public void doRun() {
Message obtainMessage = this.g.obtainMessage();
obtainMessage.what = 3;
b(this.f56240a, obtainMessage);
}
}