package com.intsig.snslogin.twitter; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; import android.graphics.Bitmap; import android.net.http.SslError; import android.os.Handler; import android.text.TextUtils; import android.webkit.SslErrorHandler; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; import com.facebook.appevents.AppEventsConstants; import com.google.logging.type.LogSeverity; import com.intsig.log.LogUtils; import com.intsig.snslogin.AccessInfo; import com.intsig.snslogin.LoginCallback; import com.intsig.snslogin.R; import com.intsig.snslogin.SnsMethod; import com.intsig.snslogin.util.Base64; import com.intsig.snslogin.util.SnsUtils; import com.intsig.utils.net.KVBean; import com.intsig.utils.net.OkHttpUtil; import java.io.File; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.security.InvalidKeyException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Random; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import okhttp3.Response; import org.json.JSONObject; import org.scribe.model.OAuthConstants; public class Twitter implements SnsMethod { /* renamed from: n reason: collision with root package name */ private static final ArrayList<String> f38563n; /* renamed from: a reason: collision with root package name */ private String f38564a = "FswboGw3Q4VGORffYYKzA"; /* renamed from: b reason: collision with root package name */ private String f38565b = "bXXJ1l57k2UOoJXTtXUtJYkF3bYp2xQ67T4ZNaodZg"; /* renamed from: c reason: collision with root package name */ private ArrayList<String> f38566c = f38563n; /* renamed from: d reason: collision with root package name */ private LoginCallback f38567d; /* renamed from: e reason: collision with root package name */ private Dialog f38568e; /* renamed from: f reason: collision with root package name */ private ProgressDialog f38569f; /* renamed from: g reason: collision with root package name */ private Handler f38570g; /* renamed from: h reason: collision with root package name */ private boolean f38571h = false; /* renamed from: i reason: collision with root package name */ private boolean f38572i = false; /* renamed from: j reason: collision with root package name */ private AccessInfo f38573j = new AccessInfo(); /* renamed from: k reason: collision with root package name */ private String f38574k; /* renamed from: l reason: collision with root package name */ private String f38575l; /* renamed from: m reason: collision with root package name */ private boolean f38576m = false; /* access modifiers changed from: private */ public class WeiboClient extends WebViewClient { /* renamed from: a reason: collision with root package name */ Dialog f38587a; /* renamed from: b reason: collision with root package name */ Activity f38588b; public WeiboClient(Activity activity, Dialog dialog) { this.f38587a = dialog; this.f38588b = activity; } /* JADX WARNING: Removed duplicated region for block: B:13:0x0042 */ public void onPageFinished(WebView webView, String str) { super.onPageFinished(webView, str); if (!Twitter.this.f38571h) { Twitter.this.f38571h = true; if (Twitter.this.f38569f.isShowing()) { try { Twitter.this.f38569f.dismiss(); } catch (Exception e10) { LogUtils.e("Twitter", e10); } if (str != null) { try { Twitter.this.f38568e.show(); return; } catch (RuntimeException e11) { LogUtils.e("Twitter", e11); } } } if (str != null) { } } } public void onPageStarted(WebView webView, final String str, Bitmap bitmap) { boolean z10; super.onPageStarted(webView, str, bitmap); Iterator it = Twitter.this.f38566c.iterator(); while (true) { if (it.hasNext()) { if (str.startsWith((String) it.next())) { z10 = true; break; } } else { z10 = false; break; } } if (z10) { if (!Twitter.this.f38572i) { Twitter.this.f38572i = true; this.f38587a.dismiss(); if (Twitter.this.f38569f != null) { Twitter.this.f38569f.show(); } new Thread() { /* class com.intsig.snslogin.twitter.Twitter.WeiboClient.AnonymousClass1 */ public void run() { String F = Twitter.F(str, OAuthConstants.VERIFIER); LogUtils.a("Twitter", "authedUrl=" + str + " \n +=" + F); boolean A = Twitter.this.A(F); Twitter.this.f38570g.post(new Runnable() { /* class com.intsig.snslogin.twitter.Twitter.WeiboClient.AnonymousClass1.AnonymousClass1 */ public void run() { if (Twitter.this.f38569f != null && Twitter.this.f38569f.isShowing()) { try { Twitter.this.f38569f.dismiss(); } catch (Exception e10) { LogUtils.e("Twitter", e10); } } } }); if (A) { if (Twitter.this.f38567d != null) { Twitter.this.f38567d.b(Twitter.this.f38573j); } } else if (Twitter.this.f38567d != null) { Twitter.this.f38567d.a(-3); } } }.start(); return; } LogUtils.c("Twitter", "illegal case: second time to twitter"); this.f38587a.dismiss(); } } public void onReceivedSslError(WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) { LogUtils.a("Twitter", "onReceivedSslError() :" + sslError); LogUtils.a("Twitter", "onReceivedSslError() mShowConfirmDialog " + Twitter.this.f38576m); if (!Twitter.this.f38576m) { Twitter.this.f38576m = true; Twitter.this.J(this.f38588b, sslErrorHandler); return; } sslErrorHandler.cancel(); } @Override // android.webkit.WebViewClient public boolean shouldOverrideUrlLoading(WebView webView, String str) { if (Twitter.this.f38572i) { return true; } return super.shouldOverrideUrlLoading(webView, str); } } static { ArrayList<String> arrayList = new ArrayList<>(); f38563n = arrayList; arrayList.add("http://www.intsig.com"); arrayList.add("https://www.intsig.com"); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private boolean A(String str) { String str2 = this.f38574k; String str3 = this.f38575l; ArrayList arrayList = new ArrayList(); arrayList.add(new KVBean(OAuthConstants.VERIFIER, str)); String v10 = v("POST", arrayList, "https://api.twitter.com/oauth/access_token", str2, str3); LogUtils.a("Twitter", "accessToken header=" + v10); String w10 = w("https://api.twitter.com/oauth/access_token", v10); String F = F(w10, OAuthConstants.TOKEN); String F2 = F(w10, OAuthConstants.TOKEN_SECRET); this.f38573j.f(F); this.f38573j.h(F2); this.f38573j.g(-13); LogUtils.a("Twitter", "access_token:" + F + "|oauth_token_secret" + F2); return !TextUtils.isEmpty(F) && !TextUtils.isEmpty(F2); } private static String B(boolean z10) { String valueOf = String.valueOf(new Random().nextInt(9876599) + 123400); if (z10) { try { MessageDigest instance = MessageDigest.getInstance("MD5"); instance.update(valueOf.getBytes()); byte[] digest = instance.digest(); StringBuilder sb2 = new StringBuilder(""); for (byte b10 : digest) { int i10 = b10; if (b10 < 0) { i10 = b10 + 256; } if (i10 < 16) { sb2.append(AppEventsConstants.EVENT_PARAM_VALUE_NO); } sb2.append(Integer.toHexString(i10 == 1 ? 1 : 0)); } return sb2.toString(); } catch (NoSuchAlgorithmException e10) { LogUtils.e("Twitter", e10); } } return valueOf; } private static String C() { return String.valueOf(System.currentTimeMillis() / 1000); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private String D() { String v10 = v("POST", null, "https://api.twitter.com/oauth/request_token", null, null); LogUtils.a("Twitter", "authorize header=" + v10); String w10 = w("https://api.twitter.com/oauth/request_token", v10); LogUtils.a("Twitter", "response " + w10); if (w10 == null) { return null; } if (this.f38573j == null) { this.f38573j = new AccessInfo(); } this.f38574k = F(w10, OAuthConstants.TOKEN); this.f38575l = F(w10, OAuthConstants.TOKEN_SECRET); return "https://api.twitter.com/oauth/authorize?oauth_token=" + this.f38574k; } private static String E(String str, String str2, String str3, String str4) { LogUtils.a("Signature", "method:" + str + "|url:" + str2 + "|params:" + str3 + "|secret:" + str4); StringBuilder sb2 = new StringBuilder(); sb2.append(str); sb2.append("&"); sb2.append(x(str2)); sb2.append("&"); sb2.append(x(str3)); String sb3 = sb2.toString(); LogUtils.a("Signature", "baseString: " + sb3); return H(sb3, str4); } /* access modifiers changed from: private */ public static String F(String str, String str2) { String str3 = str + "&"; String str4 = str2 + "="; if (str3.indexOf(str4) == -1) { return null; } int indexOf = str3.indexOf(str4) + str4.length(); return str3.substring(indexOf, str3.indexOf("&", indexOf)); } private void G(int i10) { if (i10 == 401) { this.f38573j.f(null); this.f38573j.g(System.currentTimeMillis()); } } private static String H(String str, String str2) { byte[] bArr; try { Mac instance = Mac.getInstance("HmacSHA1"); instance.init(new SecretKeySpec(str2.getBytes(), "HmacSHA1")); bArr = instance.doFinal(str.getBytes()); } catch (InvalidKeyException e10) { LogUtils.e("Twitter", e10); } catch (NoSuchAlgorithmException unused) { } return Base64.c(bArr, 0); bArr = null; return Base64.c(bArr, 0); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void J(Activity activity, final SslErrorHandler sslErrorHandler) { if (activity == null || activity.isFinishing()) { sslErrorHandler.cancel(); return; } AlertDialog.Builder builder = new AlertDialog.Builder(activity); builder.setTitle(R.string.verify_failure); builder.setMessage(R.string.a_msg_ssl_err); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { /* class com.intsig.snslogin.twitter.Twitter.AnonymousClass3 */ public void onClick(DialogInterface dialogInterface, int i10) { sslErrorHandler.proceed(); } }); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { /* class com.intsig.snslogin.twitter.Twitter.AnonymousClass4 */ public void onClick(DialogInterface dialogInterface, int i10) { sslErrorHandler.cancel(); Twitter.this.f38576m = false; Twitter.this.f38571h = true; try { Twitter.this.f38568e.dismiss(); } catch (Exception e10) { LogUtils.d("Twitter", "mLoginDialog.dismiss() ", e10); } try { Twitter.this.f38569f.dismiss(); } catch (Exception e11) { LogUtils.d("Twitter", "mProgress.dismiss() ", e11); } } }); builder.create().show(); } private String v(String str, List<KVBean> list, String str2, String str3, String str4) { StringBuilder sb2; String B = B(true); String C = C(); if (list != null) { sb2 = new StringBuilder(); for (int i10 = 0; i10 < list.size(); i10++) { sb2.append(list.get(i10).key); sb2.append("=" + x(list.get(i10).val) + ""); if (i10 != list.size() - 1) { sb2.append("&"); } } } else { sb2 = null; } StringBuilder sb3 = new StringBuilder(); sb3.append("oauth_consumer_key="); sb3.append(this.f38564a); sb3.append("&oauth_nonce="); sb3.append(B); sb3.append("&oauth_signature_method=HMAC-SHA1&oauth_timestamp="); sb3.append(C); sb3.append("&"); sb3.append(str3 == null ? "" : "oauth_token=" + str3 + "&"); sb3.append("oauth_version=1.0"); sb3.append(sb2 == null ? "" : "&" + sb2.toString()); String sb4 = sb3.toString(); StringBuilder sb5 = new StringBuilder(); sb5.append(this.f38565b); sb5.append("&"); if (str4 == null) { str4 = ""; } sb5.append(str4); String E = E(str, str2, sb4, sb5.toString()); LogUtils.a("Twitter", "oauth_signature = " + E); ArrayList arrayList = new ArrayList(); arrayList.add(new KVBean(OAuthConstants.CONSUMER_KEY, this.f38564a)); arrayList.add(new KVBean(OAuthConstants.NONCE, B)); arrayList.add(new KVBean(OAuthConstants.SIGNATURE, E)); arrayList.add(new KVBean(OAuthConstants.SIGN_METHOD, "HMAC-SHA1")); arrayList.add(new KVBean(OAuthConstants.TIMESTAMP, C)); if (str3 != null) { arrayList.add(new KVBean(OAuthConstants.TOKEN, str3)); } arrayList.add(new KVBean(OAuthConstants.VERSION, "1.0")); if (list != null) { arrayList.addAll(list); } StringBuilder sb6 = new StringBuilder(); sb6.append("OAuth"); for (int i11 = 0; i11 < arrayList.size(); i11++) { sb6.append(" " + ((KVBean) arrayList.get(i11)).key); sb6.append("=\"" + x(((KVBean) arrayList.get(i11)).val) + "\","); } return sb6.substring(0, sb6.length() - 1); } public static String w(String str, String str2) { try { HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "application/x-www-form-urlencoded"); hashMap.put("Authorization", str2); Response h10 = OkHttpUtil.t().h(str, null, hashMap, true); LogUtils.a("Twitter", "doPost code" + h10.p() + " message" + h10.A()); if (h10.z()) { String string = h10.e().string(); LogUtils.a("Twitter", "result: " + string); return string; } } catch (Exception e10) { LogUtils.e("Twitter", e10); } return null; } private static String x(String str) { int i10; boolean z10; if (str == null) { return ""; } try { String encode = URLEncoder.encode(str, "UTF-8"); StringBuilder sb2 = new StringBuilder(); int i11 = 0; while (i11 < encode.length()) { char charAt = encode.charAt(i11); if (charAt == '+') { sb2.append("%20"); } else if (charAt == '*') { sb2.append("%2A"); } else { if (charAt == '%' && (i10 = i11 + 1) < encode.length()) { int i12 = i11 + 2; if (((encode.charAt(i10) == '7') && (i12 < encode.length())) && encode.charAt(i12) == 'E') { sb2.append("~"); i11 = i12; } } sb2.append(charAt); } i11++; } return sb2.toString(); } catch (UnsupportedEncodingException e10) { throw new RuntimeException(e10.getMessage(), e10); } } public boolean I(String str) { String str2 = str + SnsUtils.c(); LogUtils.a("Twitter", "postStatus()"); AccessInfo accessInfo = this.f38573j; if (accessInfo != null) { if (accessInfo.e()) { HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "application/x-www-form-urlencoded"); ArrayList arrayList = new ArrayList(); arrayList.add(new KVBean("status", str2)); String v10 = v("POST", arrayList, "https://api.twitter.com/1.1/statuses/update.json", this.f38573j.a(), this.f38573j.c()); LogUtils.a("Twitter", "header: " + v10); hashMap.put("Authorization", v10); HashMap hashMap2 = new HashMap(); hashMap2.put("status", str2); try { Response h10 = OkHttpUtil.t().h("https://api.twitter.com/1.1/statuses/update.json", hashMap2, hashMap, true); int p10 = h10.p(); LogUtils.a("Twitter", "resultCode: " + p10); LogUtils.a("Twitter", "result: " + h10.e().string()); if (p10 == 200) { return true; } G(p10); } catch (Exception e10) { LogUtils.d("Twitter", "cocern failed", e10); } } return false; } return false; } @Override // com.intsig.snslogin.SnsMethod public AccessInfo a() { return this.f38573j; } @Override // com.intsig.snslogin.SnsMethod public boolean b(String str, String str2) { LogUtils.a("Twitter", "postStatus()"); AccessInfo accessInfo = this.f38573j; boolean z10 = false; if (accessInfo != null) { if (!accessInfo.e()) { return z10; } if (!TextUtils.isEmpty(str2) && str2.length() > 110) { str2 = str2.substring(0, 110) + "..."; LogUtils.a("Twitter", "statu: " + str2); } try { String v10 = v("POST", null, "https://api.twitter.com/1.1/statuses/update_with_media.json", this.f38573j.a(), this.f38573j.c()); LogUtils.a("Twitter", "header: " + v10); HashMap hashMap = new HashMap(); hashMap.put("Authorization", v10); HashMap hashMap2 = new HashMap(); hashMap2.put("status", str2); HashMap hashMap3 = new HashMap(); hashMap3.put("media[]", new File(str)); LogUtils.a("Twitter", "image path=" + str); Response m10 = OkHttpUtil.t().m("https://api.twitter.com/1.1/statuses/update_with_media.json", hashMap2, hashMap3, hashMap, true); int p10 = m10.p(); LogUtils.a("Twitter", "response Code:" + p10); String string = m10.e().string(); LogUtils.a("Twitter", "response:" + string); if (p10 == 200) { int optInt = new JSONObject(string).optInt("code"); LogUtils.a("Twitter", "json code: " + optInt); if (optInt != 0) { if (!(optInt == 32 || optInt == 135)) { if (optInt == 215) { } } this.f38573j.f(null); this.f38573j.g(0); } else { z10 = true; } } else { G(p10); } } catch (Exception e10) { LogUtils.e("Twitter", e10); } LogUtils.a("Twitter", "tw postStatus result = " + z10); } return z10; } @Override // com.intsig.snslogin.SnsMethod public void c(Activity activity, int i10, LoginCallback loginCallback) { this.f38567d = loginCallback; this.f38570g = new Handler(); final WebView webView = new WebView(activity); webView.setMinimumHeight(LogSeverity.NOTICE_VALUE); webView.setVerticalScrollBarEnabled(false); webView.setHorizontalScrollBarEnabled(false); webView.getSettings().setJavaScriptEnabled(true); FrameLayout frameLayout = new FrameLayout(activity); frameLayout.addView(webView); ProgressDialog progressDialog = new ProgressDialog(activity); this.f38569f = progressDialog; progressDialog.setProgressStyle(0); this.f38569f.setMessage(activity.getString(R.string.a_global_msg_loading)); this.f38569f.setCancelable(true); this.f38569f.setCanceledOnTouchOutside(false); this.f38569f.setOnCancelListener(new DialogInterface.OnCancelListener() { /* class com.intsig.snslogin.twitter.Twitter.AnonymousClass1 */ public void onCancel(DialogInterface dialogInterface) { webView.stopLoading(); webView.setWebViewClient(null); } }); this.f38569f.show(); Dialog dialog = new Dialog(activity); this.f38568e = dialog; dialog.requestWindowFeature(1); this.f38568e.getWindow().setSoftInputMode(16); this.f38568e.setCancelable(true); frameLayout.setMinimumHeight(400); this.f38568e.setContentView(frameLayout); webView.setWebViewClient(new WeiboClient(activity, this.f38568e)); this.f38571h = false; new Thread() { /* class com.intsig.snslogin.twitter.Twitter.AnonymousClass2 */ public void run() { final String D = Twitter.this.D(); if (D == null) { if (Twitter.this.f38567d != null) { Twitter.this.f38567d.a(-2); } try { Twitter.this.f38569f.dismiss(); } catch (Exception e10) { LogUtils.e("Twitter", e10); } } else { Twitter.this.f38570g.post(new Runnable() { /* class com.intsig.snslogin.twitter.Twitter.AnonymousClass2.AnonymousClass1 */ public void run() { LogUtils.a("Twitter", "webView-load url: " + D); webView.loadUrl(D); } }); } } }.start(); } @Override // com.intsig.snslogin.SnsMethod public boolean d(int i10) { if (i10 == 0) { return y("212127041"); } return false; } @Override // com.intsig.snslogin.SnsMethod public void e(AccessInfo accessInfo) { this.f38573j = accessInfo; } public boolean y(String str) { LogUtils.a("Twitter", "follow"); AccessInfo accessInfo = this.f38573j; if (accessInfo != null) { if (accessInfo.e()) { HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "application/x-www-form-urlencoded"); ArrayList arrayList = new ArrayList(); arrayList.add(new KVBean("user_id", str)); String v10 = v("POST", arrayList, "https://api.twitter.com/1.1/friendships/create.json", this.f38573j.a(), this.f38573j.c()); LogUtils.a("Twitter", "header: " + v10); hashMap.put("Authorization", v10); try { Response h10 = OkHttpUtil.t().h("https://api.twitter.com/1.1/friendships/create.json", null, hashMap, true); int p10 = h10.p(); LogUtils.a("Twitter", "resultCode: " + p10); if (h10.z()) { String string = h10.e().string(); LogUtils.a("Twitter", "result: " + string); } if (p10 != 200) { if (p10 != 403) { G(p10); } } return true; } catch (IOException e10) { LogUtils.d("Twitter", "cocern failed", e10); } } return false; } return false; } public boolean z(String str, String str2) { LogUtils.a("Twitter", "forwardStatus id=" + str); AccessInfo accessInfo = this.f38573j; if (accessInfo != null) { if (!accessInfo.e()) { return false; } HashMap hashMap = new HashMap(); hashMap.put("Content-Type", "application/x-www-form-urlencoded"); ArrayList arrayList = new ArrayList(); arrayList.add(new KVBean("id", str)); String v10 = v("POST", arrayList, "https://api.twitter.com/1.1/statuses/retweet/:id.json", this.f38573j.a(), this.f38573j.c()); LogUtils.a("Twitter", "header: " + v10); hashMap.put("Authorization", v10); try { Response h10 = OkHttpUtil.t().h("https://api.twitter.com/1.1/statuses/retweet/:id.json", null, hashMap, true); int p10 = h10.p(); LogUtils.a("Twitter", "resultCode: " + p10); if (h10.z()) { String string = h10.e().string(); LogUtils.a("Twitter", "result: " + string); } if (p10 == 200) { return true; } } catch (Exception e10) { LogUtils.d("Twitter", "cocern failed", e10); } } return false; } }