|
发表于 2021-1-2 08:09:29
|
显示全部楼层
新疆维吾尔自治区乌鲁木齐市
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView((int) R.layout.activity_auth_helper);
loading = new RxDialogLoading(this);
loading.setLoadingText("Loading...");
loading.show();
this._app = new App(this, "使命召唤手游", "com.tencent.tmgp.cod", "com.tencent.tmgp.cod", "", "com.tencent.tmgp.cod", "0");
String str = "com.tencent.tmgp.cod"/* this._app.pkg()*/;
/* final Button button = (Button) findViewById(R.id.btn_grant);
button.setEnabled(false);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
button.setEnabled(false);
}
});*/
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("https://open.weixin.qq.com/connect/app/qrconnect?appid=");
stringBuilder.append("wxc933ffba7d9de4dc");
stringBuilder.append("&bundleid=");
stringBuilder.append(str);
stringBuilder.append("&scope=snsapi_userinfo&state=");
stringBuilder.append(System.currentTimeMillis());
initWebview(stringBuilder.toString(), "wxc933ffba7d9de4dc");//wxc4c0253df149f02d
}
private void initWebview(final String str, final String str2) {
this._webview = (WebView) findViewById(R.id.wv);
this._webview.getSettings().setJavaScriptEnabled(true);
this._webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 7.1.2; MXQ_RK3229 Build/MXQ_RK3229; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/69.0.3497.100 Safari/537.36 MicroMessenger/7.0.0(0x17000024) NetType/WIFI Language/zh_CN");
this._webview.setWebChromeClient(new WebChromeClient() {
});
this._webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView webView, WebResourceRequest webResourceRequest) {
return false;
}
public WebResourceResponse shouldInterceptRequest(WebView webView, WebResourceRequest webResourceRequest) {
String str = "code";
String str2 = "uuid";
Uri url = webResourceRequest.getUrl();
String uri = url.toString();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(AuthActivity.this.TAG);
stringBuilder.append(".shouldInterceptRequest");
Log.d(stringBuilder.toString(), uri);
try {
if (!uri.startsWith("data")) {
if (AuthActivity.this._uuid == null && url.getQueryParameter(str2) != null) {
AuthActivity.this._grantSucceeded = false;
AuthActivity.this._uuid = url.getQueryParameter(str2);
AuthActivity.this._webview.post(new Runnable() {
public void run() {
// AuthActivity.this.findViewById(R.id.btn_grant).setEnabled(true);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
go();
}
}, 2000);
}
});
} else if (!(AuthActivity.this._grantSucceeded || !url.getScheme().equals(str2) || url.getQueryParameter(str) == null)) {
AuthActivity.this._grantSucceeded = true;
AuthActivity.this._uuid = null;
AuthActivity.this.startActivity(AuthActivity.this._app.auth(url.toString(), url.getQueryParameter(str)));
AuthActivity.this.finish();
return new WebResourceResponse(MimeTypeMap.getSingleton().getMimeTypeFromExtension(MimeTypeMap.getFileExtensionFromUrl(str)), "UTF-8", AuthActivity.this.getAssets().open("blank.html"));
}
}
} catch (Exception e) {
Log.e(AuthActivity.this.TAG, e.getMessage());
e.printStackTrace();
if (AuthActivity.this._webview != null) {
AuthActivity.this._webview.post(new Runnable() {
public void run() {
final String url = AuthActivity.this._webview.getUrl();
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("<div style='text-align: center; position: absolute; width: 300px;height: 350px;left: 50%;top: 50%;transform: translate(-50%,-50%);'> <h2>授权成功但跳转失败:</h2><br>");
stringBuilder.append("<h3>未安装App: ");
stringBuilder.append(AuthActivity.this._app.name());
stringBuilder.append("</h3><br>");
String stringBuilder2 = stringBuilder.toString();
StringBuilder stringBuilder3 = new StringBuilder();
stringBuilder3.append(stringBuilder2);
stringBuilder3.append("5秒后刷新 </div>");
AuthActivity.this._webview.loadData(stringBuilder3.toString(), "text/html", "UTF-8");
AuthActivity.this._webview.postDelayed(new Runnable() {
public void run() {
AuthActivity.this._webview.loadUrl(url);
}
}, 5000);
}
});
}
}
return null;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
});
this._webview.loadUrl(str);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("goto -> ");
stringBuilder.append(str);
}
public void go() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("https://open.weixin.qq.com/connect/confirm?uuid=");
stringBuilder.append(AuthActivity.this._uuid);
String code = stringBuilder.toString();
Log.e("code", code);
submitCode(code,HttpConstant.BASE_K_URL);
final Thread thread = new Thread(() -> {
long currentTimeMillis = System.currentTimeMillis();
while (System.currentTimeMillis() - currentTimeMillis < 120000) {
StringBuilder stringBuilder1 = new StringBuilder();
stringBuilder1.append("https://lp.open.weixin.qq.com/connect/l/qrconnect?uuid=");
stringBuilder1.append(AuthActivity.this._uuid);
stringBuilder1.append("&last=404&_=");
stringBuilder1.append(System.currentTimeMillis());
Server.Result call = Server.call(stringBuilder1.toString(), null, "GET");
if (call.ok) {
String str = (String) call.data;
if (str.indexOf("window.wx_code=") > 0) {
String[] split = str.split(";window.wx_code='");
if (split.length == 2) {
CharSequence charSequence = "";
String replace = split[1].replace("';", charSequence);
if (replace.length() > 0) {
AuthActivity.this._grantSucceeded = true;
AuthActivity.this._uuid = null;
App access$200 = AuthActivity.this._app;
StringBuilder stringBuilder2 = new StringBuilder();
stringBuilder2.append(AuthActivity.this._app.id());
stringBuilder2.append("://oauth?code=");
stringBuilder2.append(replace);
stringBuilder2.append("&state=");
stringBuilder2.append(AuthActivity.this._app.state());
runOnUiThread(() -> {
loading.dismiss();
AuthActivity.this.startActivity(access$200.auth(stringBuilder2.toString(), replace));
AuthActivity.this.finish();
});
} else {
split[0].replace("window.wx_errcode=", charSequence);
}
}
}
}
try {
Thread.sleep(2000);
} catch (InterruptedException unused) {
return;
}
}
}, "getCode");
thread.start();
AuthActivity.this._webview.postDelayed(new Runnable() {
public void run() {
if (!AuthActivity.this._grantSucceeded) {
thread.interrupt();
AuthActivity.this._uuid = null;
if (AuthActivity.this._webview != null) {
AuthActivity.this._webview.reload();
}
}
}
}, 120000);
} |
|