360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0
以下内容为反编译后的 AccountService.java 源代码,内容仅作参考
package com.qihoo.accountcenter.service;
import android.app.Service;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.IBinder;
import android.text.TextUtils;
import android.util.Log;
import com.qihoo.appstore.personnalcenter.h;
import com.qihoo.appstore.personnalcenter.sdk.e;
import com.qihoo.appstore.utils.bk;
import com.qihoo.appstore.utils.ct;
import com.qihoo.appstore.utils.dc;
import com.qihoo.appstore.utils.de;
import com.qihoo.freewifi.push.R;
import com.qihoo.speedometer.Config;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class AccountService extends Service {
private static final String[] f572b = {"360zhushou", "open_ms", "360yxhezi"};
private static final String[] c = {"j8a7i2u6", "2a9u8q4y", "u72g3fds"};
private final com.qihoo.accountcenter.a.b f573a = new a(this);
public int a(int i, String str, String str2, String[] strArr) {
int i2;
String[] strArr2;
strArr[0] = "unauthorized";
String[] a2 = a(i, str);
int length = a2.length;
SQLiteDatabase writableDatabase = new com.qihoo.accountcenter.b.a(this).getWritableDatabase();
int i3 = 0;
while (true) {
if (i3 >= length) {
i2 = 99102;
break;
}
if (!TextUtils.isEmpty(a2[i3])) {
strArr2 = c.f577a;
Cursor query = writableDatabase.query("verify", strArr2, "pkg_name=? AND app_key=? AND public_key=?", new String[]{str, str2, a2[i3]}, null, null, null);
if (query != null) {
try {
try {
if (query.moveToFirst()) {
long j = query.getLong(0);
if (System.currentTimeMillis() - j <= Config.TASK_EXPIRATION_MSEC && System.currentTimeMillis() - j >= 0) {
i2 = 0;
if (query != null) {
query.close();
}
}
}
} catch (Throwable th) {
if (query != null) {
query.close();
}
throw th;
}
} catch (Exception e) {
e.printStackTrace();
if (query != null) {
query.close();
}
}
}
if (query != null) {
query.close();
}
}
i3++;
}
if (i2 != 0) {
writableDatabase.delete("verify", "pkg_name=? AND app_key=?", new String[]{str, str2});
int i4 = 0;
while (true) {
if (i4 >= length) {
break;
}
if (!TextUtils.isEmpty(a2[i4])) {
InputStream inputStream = null;
com.qihoo.accountcenter.c.a aVar = null;
try {
try {
aVar = com.qihoo.accountcenter.c.a.a((String) null);
HttpPost httpPost = new HttpPost("http://openapi.360.cn/internal/verify_mobile_app.json");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setHeader("Charset", "UTF8");
ArrayList arrayList = new ArrayList();
arrayList.add(new BasicNameValuePair("app_name", str2));
arrayList.add(new BasicNameValuePair("public_key", a2[i4]));
httpPost.setEntity(new UrlEncodedFormEntity(arrayList, "UTF8"));
HttpResponse execute = aVar.execute(httpPost);
if (execute.getStatusLine().getStatusCode() == 200) {
inputStream = execute.getEntity().getContent();
if ("verified".equalsIgnoreCase(new JSONObject(new String(a(inputStream), "UTF8")).optString("ret"))) {
i2 = 0;
ContentValues contentValues = new ContentValues();
contentValues.put("pkg_name", str);
contentValues.put("app_key", str2);
contentValues.put("public_key", a2[i4]);
contentValues.put("verify_time", Long.valueOf(System.currentTimeMillis()));
writableDatabase.insert("verify", null, contentValues);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
} catch (Throwable th2) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
throw th2;
}
} catch (Exception e5) {
e5.printStackTrace();
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e6) {
e6.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
}
}
i4++;
}
}
writableDatabase.close();
return i2;
}
public static int a(String str, JSONObject jSONObject) {
InputStream inputStream = null;
int i = 5099;
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpGet httpGet = new HttpGet(h.a());
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
httpGet.setHeader("Cookie", str);
try {
try {
HttpResponse execute = a2.execute(httpGet);
if (execute.getStatusLine().getStatusCode() == 200) {
inputStream = execute.getEntity().getContent();
JSONObject jSONObject2 = new JSONObject(a(new String(a(inputStream), "UTF8"), execute));
int i2 = jSONObject2.getInt("errno");
if (i2 == 0) {
JSONObject optJSONObject = jSONObject2.optJSONObject("data");
if (optJSONObject != null) {
i = 0;
jSONObject.put("details", optJSONObject);
}
} else {
i = i2;
}
}
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
}
} catch (Exception e2) {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getUserInfo failed.", e2);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
}
return i;
}
public int a(String str, String[] strArr) {
InputStream inputStream = null;
int i = 5099;
strArr[0] = getString(R.string.unknown_error_check_qt);
if (!TextUtils.isEmpty(str)) {
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpGet httpGet = new HttpGet("http://openapi.360.cn/internal/verify_q_t.json");
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
httpGet.setHeader("Cookie", str);
try {
try {
HttpResponse execute = a2.execute(httpGet);
if (execute.getStatusLine().getStatusCode() == 200) {
inputStream = execute.getEntity().getContent();
String optString = new JSONObject(new String(a(inputStream), "UTF8")).optString("ret");
if ("verified".equalsIgnoreCase(optString)) {
i = 0;
} else {
try {
strArr[0] = optString;
i = 4010207;
} catch (Exception e) {
i = 4010207;
e = e;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", e);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
return i;
}
}
}
} catch (Exception e3) {
e = e3;
}
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
}
}
return i;
}
public int a(String str, String[] strArr, String str2, JSONObject jSONObject) {
Exception exc;
int i;
InputStream inputStream;
HttpResponse execute;
InputStream inputStream2 = null;
strArr[0] = "用户中心修改密码未知错误";
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpGet httpGet = new HttpGet(str);
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
try {
try {
execute = a2.execute(httpGet);
} catch (Exception e) {
exc = e;
i = 5099;
inputStream = null;
}
if (execute.getStatusLine().getStatusCode() == 200) {
inputStream2 = execute.getEntity().getContent();
try {
JSONObject jSONObject2 = new JSONObject(a(new String(a(inputStream2), "UTF8"), execute));
int i2 = jSONObject2.getInt("errno");
if (i2 == 0) {
String str3 = Config.INVALID_IP;
Header[] headers = execute.getHeaders("set-cookie");
for (Header header : headers) {
String value = header.getValue();
int indexOf = value.indexOf("Q=");
if (indexOf < 0) {
indexOf = value.indexOf("T=");
}
if (indexOf >= 0) {
str3 = str3.concat(value.substring(indexOf, value.indexOf(";", indexOf) + 1));
}
}
if (!TextUtils.isEmpty(str3)) {
try {
jSONObject.put("qt", str3.substring(0, str3.length() - 1));
jSONObject.put("qid", str2);
i = 0;
} catch (Exception e2) {
inputStream = inputStream2;
i = 0;
exc = e2;
try {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
}
if (inputStream != null) {
}
if (a2 != null) {
}
return i;
} catch (Throwable th) {
th = th;
inputStream2 = inputStream;
if (inputStream2 != null) {
}
if (a2 != null) {
}
throw th;
}
}
}
} else {
try {
strArr[0] = jSONObject2.optString("errmsg");
if (TextUtils.isEmpty(strArr[0])) {
strArr[0] = "密码修改失败";
}
i = i2;
} catch (Exception e3) {
exc = e3;
inputStream = inputStream2;
i = i2;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", exc);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
return i;
}
}
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (IOException e5) {
e5.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
} catch (Exception e6) {
exc = e6;
i = 5099;
inputStream = inputStream2;
}
return i;
}
i = 5099;
if (inputStream2 != null) {
}
if (a2 != null) {
}
return i;
} catch (Throwable th2) {
th = th2;
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (IOException e7) {
e7.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
throw th;
}
}
private static String a(String str, HttpResponse httpResponse) {
try {
new JSONObject(str);
return str;
} catch (JSONException e) {
Header firstHeader = httpResponse.getFirstHeader("From");
if (firstHeader == null) {
return str;
}
String value = firstHeader.getValue();
bk.b("AccountService", "preDes header from=" + value);
for (int i = 0; i < f572b.length; i++) {
if (value.equals(f572b[i])) {
return h.c(str, c[i]);
}
}
return str;
}
}
private String a(byte[] bArr) {
try {
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(bArr);
return b(messageDigest.digest());
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
return null;
}
}
public static JSONArray a(Context context) {
Cursor cursor;
Cursor cursor2;
SQLiteDatabase sQLiteDatabase;
SQLiteDatabase sQLiteDatabase2 = null;
try {
JSONArray jSONArray = new JSONArray();
SQLiteDatabase writableDatabase = new com.qihoo.accountcenter.b.a(context).getWritableDatabase();
try {
cursor = writableDatabase.query("account", b.f575a, "account_type!=0", null, null, null, "login_time DESC, qid DESC");
if (cursor == null) {
if (cursor != null) {
try {
cursor.close();
} catch (Exception e) {
}
}
if (writableDatabase != null) {
try {
writableDatabase.close();
} catch (Exception e2) {
}
}
return null;
}
try {
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
String string = cursor.getString(0);
String string2 = cursor.getString(2);
if (!TextUtils.isEmpty(string) && !TextUtils.isEmpty(string2)) {
String str = new String(com.qihoo.express.mini.c.c.b(com.qihoo.appstore.utils.h.a(string2, 0)));
JSONObject jSONObject = new JSONObject();
jSONObject.put("account", string);
jSONObject.put("qt", str);
jSONArray.put(jSONObject);
}
cursor.moveToNext();
}
if (cursor != null) {
try {
cursor.close();
} catch (Exception e3) {
}
}
if (writableDatabase != null) {
try {
writableDatabase.close();
} catch (Exception e4) {
}
}
return jSONArray;
} catch (Exception e5) {
sQLiteDatabase = writableDatabase;
cursor2 = cursor;
if (cursor2 != null) {
try {
cursor2.close();
} catch (Exception e6) {
}
}
if (sQLiteDatabase != null) {
try {
sQLiteDatabase.close();
} catch (Exception e7) {
}
}
return null;
} catch (Throwable th) {
sQLiteDatabase2 = writableDatabase;
th = th;
if (cursor != null) {
try {
cursor.close();
} catch (Exception e8) {
}
}
if (sQLiteDatabase2 == null) {
throw th;
}
try {
sQLiteDatabase2.close();
throw th;
} catch (Exception e9) {
throw th;
}
}
} catch (Exception e10) {
sQLiteDatabase = writableDatabase;
cursor2 = null;
} catch (Throwable th2) {
cursor = null;
sQLiteDatabase2 = writableDatabase;
th = th2;
}
} catch (Exception e11) {
cursor2 = null;
sQLiteDatabase = null;
} catch (Throwable th3) {
th = th3;
cursor = null;
}
}
public static JSONObject a(Context context, int i) {
SQLiteDatabase sQLiteDatabase;
SQLiteDatabase writableDatabase;
String[] strArr;
Cursor cursor = null;
JSONObject jSONObject = new JSONObject();
String valueOf = i > 0 ? String.valueOf(i) : null;
try {
writableDatabase = new com.qihoo.accountcenter.b.a(context).getWritableDatabase();
} catch (Exception e) {
e = e;
sQLiteDatabase = null;
} catch (Throwable th) {
th = th;
sQLiteDatabase = null;
}
try {
strArr = b.d;
cursor = writableDatabase.query("account", strArr, "account_type!=0", null, null, null, "login_time DESC, qid DESC", valueOf);
if (cursor != null && cursor.moveToFirst()) {
String string = cursor.getString(0);
HashSet hashSet = new HashSet();
hashSet.add(string);
while (cursor.moveToNext()) {
String string2 = cursor.getString(0);
if (!hashSet.contains(string2)) {
hashSet.add(string2);
string = string.concat(";" + string2);
}
}
jSONObject.put("account", string);
}
if (cursor != null) {
try {
cursor.close();
} catch (Exception e2) {
}
}
if (writableDatabase != null) {
try {
writableDatabase.close();
} catch (Exception e3) {
}
}
} catch (Exception e4) {
sQLiteDatabase = writableDatabase;
e = e4;
try {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
bk.c("AccountService", "queryUserList failed.", e);
}
if (cursor != null) {
try {
cursor.close();
} catch (Exception e5) {
}
}
if (sQLiteDatabase != null) {
try {
sQLiteDatabase.close();
} catch (Exception e6) {
}
}
return jSONObject;
} catch (Throwable th2) {
th = th2;
if (cursor != null) {
try {
cursor.close();
} catch (Exception e7) {
}
}
if (sQLiteDatabase != null) {
throw th;
}
try {
sQLiteDatabase.close();
throw th;
} catch (Exception e8) {
throw th;
}
}
} catch (Throwable th3) {
sQLiteDatabase = writableDatabase;
th = th3;
if (cursor != null) {
}
if (sQLiteDatabase != null) {
}
}
return jSONObject;
}
public static void a(Context context, int i, String str, String str2, String str3) {
String[] strArr;
try {
SQLiteDatabase writableDatabase = new com.qihoo.accountcenter.b.a(context).getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put("pkg_name", context.getPackageName());
contentValues.put("qt", e.b(str3));
contentValues.put("login_time", Long.valueOf(System.currentTimeMillis()));
Cursor query = writableDatabase.query("account", b.f575a, null, null, null, null, "login_time DESC, qid DESC");
try {
try {
if (query.getCount() > 0) {
writableDatabase.delete("account", "account=? AND account_type!=0", new String[]{str});
}
} catch (Exception e) {
e.printStackTrace();
if (query != null) {
query.close();
}
}
contentValues.put("account", str);
int i2 = 4;
if (i == 1) {
i2 = 1;
} else if (i == 2) {
i2 = 2;
}
contentValues.put("account_type", Integer.valueOf(i2));
strArr = b.c;
Cursor query2 = writableDatabase.query("account", strArr, "qid=?", new String[]{str2}, null, null, null);
if (query2 != null) {
try {
try {
if (query2.getCount() > 0) {
writableDatabase.update("account", contentValues, "qid=?", new String[]{str2});
if (query2 != null) {
query2.close();
}
writableDatabase.close();
}
} catch (Exception e2) {
e2.printStackTrace();
if (query2 != null) {
query2.close();
}
writableDatabase.close();
return;
}
} catch (Throwable th) {
if (query2 != null) {
query2.close();
}
writableDatabase.close();
throw th;
}
}
contentValues.put("qid", str2);
writableDatabase.insert("account", null, contentValues);
if (query2 != null) {
}
writableDatabase.close();
} finally {
if (query != null) {
query.close();
}
}
} catch (Exception e3) {
}
}
public static void a(Context context, String str, String str2) {
SQLiteDatabase writableDatabase = new com.qihoo.accountcenter.b.a(context).getWritableDatabase();
try {
String b2 = com.qihoo.appstore.utils.h.b(com.qihoo.express.mini.c.c.a(str2.getBytes()), 0);
ContentValues contentValues = new ContentValues();
contentValues.put("qt", b2);
writableDatabase.update("account", contentValues, "qid=?", new String[]{str});
} catch (Exception e) {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
bk.c("AccountService", "modifyPwd failed.", e);
}
} finally {
writableDatabase.close();
}
}
public static byte[] a(InputStream inputStream) {
byte[] bArr = new byte[1024];
try {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
while (true) {
int read = inputStream.read(bArr);
if (read == -1) {
byteArrayOutputStream.close();
inputStream.close();
return byteArrayOutputStream.toByteArray();
}
byteArrayOutputStream.write(bArr, 0, read);
}
} catch (Exception e) {
e.printStackTrace();
return new byte[1024];
} catch (OutOfMemoryError e2) {
System.gc();
e2.printStackTrace();
return new byte[1024];
}
}
private String[] a(int i, String str) {
String[] strArr = null;
PackageManager packageManager = getPackageManager();
String[] packagesForUid = packageManager.getPackagesForUid(i);
int length = packagesForUid.length;
int i2 = 0;
while (true) {
if (i2 >= length) {
str = null;
break;
}
if (str.equalsIgnoreCase(packagesForUid[i2])) {
break;
}
i2++;
}
if (TextUtils.isEmpty(str)) {
return null;
}
try {
PackageInfo packageInfo = packageManager.getPackageInfo(str, 64);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
int length2 = packageInfo.signatures.length;
String[] strArr2 = new String[length2];
for (int i3 = 0; i3 < length2; i3++) {
try {
strArr2[i3] = a(((X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(packageInfo.signatures[i3].toByteArray()))).getPublicKey().getEncoded());
} catch (PackageManager.NameNotFoundException e) {
strArr = strArr2;
e = e;
e.printStackTrace();
return strArr;
} catch (CertificateException e2) {
strArr = strArr2;
e = e2;
e.printStackTrace();
return strArr;
}
}
return strArr2;
} catch (PackageManager.NameNotFoundException e3) {
e = e3;
} catch (CertificateException e4) {
e = e4;
}
}
public int b(String str, int i, String[] strArr, JSONObject jSONObject) {
HttpResponse execute;
int i2 = 5099;
strArr[0] = getString(R.string.unknown_error_mobile);
HttpGet httpGet = new HttpGet(str);
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
long currentTimeMillis = System.currentTimeMillis();
long j = currentTimeMillis;
while (true) {
if (j - currentTimeMillis >= 60000) {
break;
}
com.qihoo.accountcenter.c.a aVar = null;
InputStream inputStream = null;
try {
try {
aVar = com.qihoo.accountcenter.c.a.a((String) null);
execute = aVar.execute(httpGet);
} catch (Throwable th) {
th = th;
}
if (execute.getStatusLine().getStatusCode() != 200) {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
} else {
inputStream = execute.getEntity().getContent();
String a2 = a(new String(a(inputStream), "UTF8"), execute);
if (!ct.a(a2)) {
JSONObject jSONObject2 = new JSONObject(a2);
i2 = jSONObject2.optInt("errno", 5099);
if (i2 != 0) {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
} else {
JSONObject optJSONObject = jSONObject2.optJSONObject("data");
i2 = optJSONObject.optInt("errno", 5099);
String optString = optJSONObject.optString("isregsucc");
if (i2 == 0 && "yes".equals(optString)) {
jSONObject.put("account", optJSONObject.optString("mobile"));
jSONObject.put("qid", optJSONObject.optLong("qid"));
String concat = "Q=".concat(URLEncoder.encode(optJSONObject.optString("q"), "UTF8")).concat(";").concat("T=").concat(URLEncoder.encode(optJSONObject.optString("t"), "UTF8"));
jSONObject.put("qt", concat);
i2 = a(concat, jSONObject);
if (i2 == 0) {
jSONObject.put("randpwd", optJSONObject.optString("randpwd"));
jSONObject.put("tmptoken", optJSONObject.optString("tmptoken"));
jSONObject.put("randcode", optJSONObject.optString("randcode"));
jSONObject.put("mobile", optJSONObject.optString("mobile"));
jSONObject.put("REG_ACCOUNT_ALREADY_EXIST", false);
}
jSONObject.put("fields", jSONObject2);
strArr[0] = getString(R.string.succeed_register);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
} else if (i2 == 1037 && "no".equals(optString)) {
String optString2 = optJSONObject.optString("mobile");
String optString3 = optJSONObject.optString("tmptoken");
Object optString4 = optJSONObject.optString("randcode");
int b2 = b(a(optString2, optString3), new String[2], jSONObject);
try {
i2 = a(jSONObject.optString("qt"), jSONObject);
if (i2 == 0) {
strArr[0] = getString(R.string.succeed_login);
}
jSONObject.put("mobile", optString2);
jSONObject.put("account", optString2);
jSONObject.put("tmptoken", optString3);
jSONObject.put("randcode", optString4);
jSONObject.put("REG_ACCOUNT_ALREADY_EXIST", true);
if (ct.a(jSONObject.optString("fields"))) {
jSONObject.put("fields", jSONObject2);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
} catch (Throwable th2) {
i2 = b2;
th = th2;
bk.d("AccountService", "failed in registerBySmsNoPwd", th);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e5) {
e5.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
synchronized (this) {
}
}
} else if (i2 != 1020302) {
strArr[0] = jSONObject2.optString("errmsg");
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e6) {
e6.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
} else {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e7) {
e7.printStackTrace();
}
}
if (aVar != null) {
aVar.a();
}
synchronized (this) {
try {
wait(5000L);
} catch (Exception e8) {
e8.printStackTrace();
}
}
j = System.currentTimeMillis();
}
}
}
}
} finally {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException e9) {
e9.printStackTrace();
}
}
if (0 != 0) {
aVar.a();
}
}
}
return i2;
}
public int b(String str, String str2, String[] strArr, JSONObject jSONObject) {
int i;
int i2 = 5099;
strArr[0] = getString(R.string.unknown_error_get_auth_code);
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpPost httpPost = new HttpPost(str);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setHeader("Charset", "UTF8");
httpPost.setHeader("Cookie", str2);
ArrayList arrayList = new ArrayList();
arrayList.add(new BasicNameValuePair("authorize", "sdk_by_cookie"));
try {
try {
httpPost.setEntity(new UrlEncodedFormEntity(arrayList, "UTF8"));
HttpResponse execute = a2.execute(httpPost);
if (execute.getStatusLine().getStatusCode() == 302) {
String value = execute.getFirstHeader("Location").getValue();
Matcher matcher = Pattern.compile("[?&]code=([0-9a-zA-Z]*)").matcher(value);
Matcher matcher2 = Pattern.compile("[?&]state=([0-9a-zA-Z_]*)").matcher(value);
if (matcher.find()) {
jSONObject.put("auth_code", matcher.group(1));
i2 = 0;
}
if (matcher2.find()) {
jSONObject.put("state", matcher2.group(1));
}
i = i2;
} else {
strArr[0] = getString(R.string.fail_invalid_qt);
i = 4010207;
}
} catch (Exception e) {
i = 5099;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", e);
}
if (a2 != null) {
a2.a();
}
}
return i;
} finally {
if (a2 != null) {
a2.a();
}
}
}
public int b(String str, String[] strArr, JSONObject jSONObject) {
Exception exc;
int i;
InputStream inputStream;
HttpResponse execute;
InputStream inputStream2 = null;
strArr[0] = getString(R.string.unknown_error_get_qt);
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpGet httpGet = new HttpGet(str);
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
try {
try {
execute = a2.execute(httpGet);
} catch (Exception e) {
exc = e;
i = 5099;
inputStream = null;
}
if (execute.getStatusLine().getStatusCode() == 200) {
inputStream2 = execute.getEntity().getContent();
try {
JSONObject jSONObject2 = new JSONObject(a(new String(a(inputStream2), "UTF8"), execute));
int i2 = jSONObject2.getInt("errno");
if (i2 == 0) {
String str2 = Config.INVALID_IP;
Header[] headers = execute.getHeaders("set-cookie");
for (Header header : headers) {
String value = header.getValue();
int indexOf = value.indexOf("Q=");
if (indexOf < 0) {
indexOf = value.indexOf("T=");
}
if (indexOf >= 0) {
str2 = str2.concat(value.substring(indexOf, value.indexOf(";", indexOf) + 1));
}
}
JSONObject optJSONObject = jSONObject2.optJSONObject("user");
if (optJSONObject != null) {
jSONObject.put("fields", optJSONObject);
jSONObject.put("qid", optJSONObject.optLong("qid"));
}
if (!TextUtils.isEmpty(str2)) {
try {
jSONObject.put("qt", str2.substring(0, str2.length() - 1));
i = 0;
} catch (Exception e2) {
inputStream = inputStream2;
i = 0;
exc = e2;
try {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
}
if (inputStream != null) {
}
if (a2 != null) {
}
return i;
} catch (Throwable th) {
th = th;
inputStream2 = inputStream;
if (inputStream2 != null) {
}
if (a2 != null) {
}
throw th;
}
}
}
} else {
try {
strArr[0] = jSONObject2.optString("errmsg");
if (TextUtils.isEmpty(strArr[0])) {
strArr[0] = getString(R.string.fail_invalid_username_or_pwd);
}
i = i2;
} catch (Exception e3) {
exc = e3;
inputStream = inputStream2;
i = i2;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", exc);
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
return i;
}
}
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (IOException e5) {
e5.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
} catch (Exception e6) {
exc = e6;
i = 5099;
inputStream = inputStream2;
}
return i;
}
i = 5099;
if (inputStream2 != null) {
}
if (a2 != null) {
}
return i;
} catch (Throwable th2) {
th = th2;
if (inputStream2 != null) {
try {
inputStream2.close();
} catch (IOException e7) {
e7.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
throw th;
}
}
private String b(byte[] bArr) {
char[] cArr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
StringBuilder sb = new StringBuilder(bArr.length * 2);
for (int i = 0; i < bArr.length; i++) {
sb.append(cArr[(bArr[i] & 240) >>> 4]);
sb.append(cArr[bArr[i] & 15]);
}
return sb.toString();
}
public int a(String str, int i, String[] strArr, JSONObject jSONObject) {
int i2 = 5099;
strArr[0] = getString(R.string.unknown_error_mobile);
HttpGet httpGet = new HttpGet(str);
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
long currentTimeMillis = System.currentTimeMillis();
long j = currentTimeMillis;
while (true) {
if (j - currentTimeMillis >= 60000) {
break;
}
com.qihoo.accountcenter.c.a aVar = null;
InputStream inputStream = null;
try {
try {
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpResponse execute = a2.execute(httpGet);
if (execute.getStatusLine().getStatusCode() == 200) {
inputStream = execute.getEntity().getContent();
JSONObject jSONObject2 = new JSONObject(a(new String(a(inputStream), "UTF8"), execute));
if (jSONObject2.has("errno")) {
i2 = jSONObject2.optInt("errno", 5099);
if (i2 == 0) {
JSONObject jSONObject3 = jSONObject2.getJSONObject("data");
i2 = jSONObject3.optInt("errno", 5099);
if (i2 == 0) {
jSONObject.put("account", jSONObject3.optString("mobile"));
jSONObject.put("qid", jSONObject3.optLong("qid"));
jSONObject.put("qt", "Q=".concat(URLEncoder.encode(jSONObject3.optString("q"), "UTF8")).concat(";").concat("T=").concat(URLEncoder.encode(jSONObject3.optString("t"), "UTF8")));
jSONObject.put("fields", jSONObject3);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
} else if (i2 != 1020302) {
strArr[0] = jSONObject3.optString("errmsg");
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
}
} else {
strArr[0] = jSONObject2.optString("errmsg");
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e3) {
e3.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
}
} else {
JSONObject jSONObject4 = jSONObject2.getJSONObject("ret");
i2 = jSONObject4.optInt("regist_errno", 5099);
if (i2 == 0) {
jSONObject.put("account", jSONObject4.optString("mobile_phone_number"));
jSONObject.put("qid", jSONObject4.optLong("qid"));
jSONObject.put("qt", "Q=".concat(URLEncoder.encode(jSONObject4.optString("q"), "UTF8")).concat(";").concat("T=").concat(URLEncoder.encode(jSONObject4.optString("t"), "UTF8")));
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e4) {
e4.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
} else if (i2 != 9999) {
if (jSONObject4.optString("mobile_phone_number") != null) {
jSONObject.put("account", jSONObject4.optString("mobile_phone_number"));
}
strArr[0] = getString(R.string.fail_sms_reg_fail);
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e5) {
e5.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
}
}
}
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e6) {
e6.printStackTrace();
}
}
if (a2 != null) {
a2.a();
}
} catch (Exception e7) {
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", e7);
}
if (0 != 0) {
try {
inputStream.close();
} catch (IOException e8) {
e8.printStackTrace();
}
}
if (0 != 0) {
aVar.a();
}
}
synchronized (this) {
try {
wait(5000L);
} catch (Exception e9) {
e9.printStackTrace();
}
}
j = System.currentTimeMillis();
} catch (Throwable th) {
if (0 != 0) {
try {
inputStream.close();
} catch (IOException e10) {
e10.printStackTrace();
}
}
if (0 != 0) {
aVar.a();
}
throw th;
}
}
return i2;
}
public int a(String str, String str2, String[] strArr, JSONObject jSONObject) {
int i;
Exception exc;
String str3 = null;
int i2 = 5099;
strArr[0] = getString(R.string.unknown_error_try);
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpGet httpGet = new HttpGet(str2);
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
if (!TextUtils.isEmpty(str)) {
httpGet.setHeader("Cookie", str);
}
try {
try {
HttpResponse execute = a2.execute(httpGet);
if (execute.getStatusLine().getStatusCode() == 200) {
JSONObject jSONObject2 = new JSONObject(a(new String(a(execute.getEntity().getContent()), "UTF8"), execute));
jSONObject.put("account", jSONObject2.optString("name"));
jSONObject.put("qid", jSONObject2.optLong("id"));
jSONObject.put("is_register", jSONObject2.optString("is_register"));
Header[] headers = execute.getHeaders("set-cookie");
int i3 = 0;
while (true) {
if (i3 >= headers.length) {
break;
}
String value = headers[i3].getValue();
int indexOf = value.indexOf("try_id=");
if (indexOf >= 0) {
str3 = value.substring(indexOf, value.indexOf(";", indexOf));
break;
}
i3++;
}
if (!TextUtils.isEmpty(str3)) {
try {
jSONObject.put("qt", str3);
i2 = 0;
} catch (Exception e) {
exc = e;
i = 0;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", exc);
}
if (a2 != null) {
a2.a();
}
return i;
}
}
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put("head_pic", jSONObject2.optString("avatar"));
jSONObject.put("fields", jSONObject3);
i = i2;
} else {
strArr[0] = getString(R.string.fail_try_reg_fail);
i = 99110;
}
} catch (Exception e2) {
i = 5099;
exc = e2;
}
return i;
} finally {
if (a2 != null) {
a2.a();
}
}
}
public int a(String str, String[] strArr, JSONObject jSONObject) {
Exception exc;
int i;
HttpResponse execute;
strArr[0] = getString(R.string.unknown_error_name_or_email);
com.qihoo.accountcenter.c.a a2 = com.qihoo.accountcenter.c.a.a((String) null);
HttpGet httpGet = new HttpGet(str);
httpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpGet.setHeader("Charset", "UTF8");
try {
try {
execute = a2.execute(httpGet);
} finally {
if (a2 != null) {
a2.a();
}
}
} catch (Exception e) {
exc = e;
i = 5099;
}
if (execute.getStatusLine().getStatusCode() == 200) {
JSONObject jSONObject2 = new JSONObject(a(new String(a(execute.getEntity().getContent()), "UTF8"), execute));
int i2 = jSONObject2.getInt("errno");
if (i2 == 0) {
String str2 = Config.INVALID_IP;
Header[] headers = execute.getHeaders("set-cookie");
for (Header header : headers) {
String value = header.getValue();
int indexOf = value.indexOf("Q=");
if (indexOf < 0) {
indexOf = value.indexOf("T=");
}
if (indexOf >= 0) {
str2 = str2.concat(value.substring(indexOf, value.indexOf(";", indexOf) + 1));
}
}
JSONObject optJSONObject = jSONObject2.optJSONObject("data");
if (optJSONObject != null) {
jSONObject.put("fields", optJSONObject);
jSONObject.put("qid", optJSONObject.optLong("qid"));
}
if (!TextUtils.isEmpty(str2)) {
try {
jSONObject.put("qt", str2.substring(0, str2.length() - 1));
i = 0;
} catch (Exception e2) {
i = 0;
exc = e2;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
Log.e("AccountService", "getQT failed.", exc);
}
if (a2 != null) {
a2.a();
}
return i;
}
}
} else {
try {
strArr[0] = jSONObject2.optString("errmsg");
if (TextUtils.isEmpty(strArr[0])) {
strArr[0] = getString(R.string.fail_name_or_email_reg_fial);
}
i = i2;
} catch (Exception e3) {
exc = e3;
i = i2;
if (com.qihoo360.mobilesafe.a.a.f5313a) {
}
if (a2 != null) {
}
return i;
}
}
return i;
}
i = 5099;
return i;
}
protected String a(String str, String str2) {
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append("account=").append(str).append("&token=").append(str2).append("&method=CommonAccount.mobileLoginByToken").append("&v=").append(de.f(this)).append("&from=mpc_zhushou").append("&mid=").append(dc.L()).append("&format=json").append("&vt_guid=").append(String.valueOf(Math.abs(new Random().nextInt())));
String stringBuffer2 = stringBuffer.toString();
return "https://login.360.cn/intf.php?" + stringBuffer2 + "&sig=" + de.g(stringBuffer2);
}
@Override
public IBinder onBind(Intent intent) {
return this.f573a;
}
}