fix:解决googleplay审核问题(onReceivedSslError)

This commit is contained in:
Max
2024-01-23 11:38:28 +08:00
parent db75f129ee
commit 8aba5ebaa2
3 changed files with 79 additions and 67 deletions

View File

@@ -5,6 +5,7 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
@@ -26,6 +27,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AlertDialog;
import com.google.gson.Gson;
import com.netease.nim.uikit.StatusBarUtil;
@@ -36,7 +38,6 @@ import com.trello.rxlifecycle3.android.ActivityEvent;
import com.nnbc123.app.R;
import com.nnbc123.app.application.XChatApplication;
import com.nnbc123.app.base.BaseActivity;
import com.nnbc123.app.common.widget.dialog.BaseAlertDialogBuilder;
import com.nnbc123.app.ui.im.RouterHandler;
import com.nnbc123.app.ui.webview.event.ShowNavEvent;
import com.nnbc123.app.ui.webview.event.TaroPayResultEvent;
@@ -227,62 +228,14 @@ public class CommonWebViewActivity extends BaseActivity implements ShareDialog.O
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Logger.e("shouldOverrideUrlLoading--------" + url);
LogUtil.e("shouldOverrideUrlLoading" + url);
// LogUtil.e("shouldOverrideUrlLoading" + url);
targetUrl = url;
//modules/noble/paySuccess.html
//modules/noble/order.html?nobleIndex=1 // 获取上下文, H5PayDemoActivity为当前页面
// ------ 对alipays:相关的scheme处理 -------
if (url.startsWith("alipays:") || url.startsWith("alipay")) {
try {
CommonWebViewActivity.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
} catch (Exception e) {
new BaseAlertDialogBuilder(CommonWebViewActivity.this)
.setMessage("未检测到支付宝客户端,请安装后重试。")
.setPositiveButton("立即安装", (dialog, which) -> {
Uri alipayUrl = Uri.parse("https://d.alipay.com");
CommonWebViewActivity.this.startActivity(new Intent("android.intent.action.VIEW", alipayUrl));
}).setNegativeButton("取消", null).show();
}
return true;
}
if (url.startsWith("weixin://wap/pay")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
} catch (Exception e) {
toast("未安装微信");
}
return true;
}
if (url.contains("tel:")) {
//删除直接拨打电话的功能
return true;
}
if (url.startsWith("pubgmhd1106467070://")) {
// 跳转和平精英
Intent in = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
if (in.resolveActivity(getPackageManager()) == null) {
toast("您尚未安装游戏,跳转失败。");
} else {
in.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(in);
}
onGotoAppFinish(view);
return true;
}
if (url.startsWith("mqqopensdkapi://")) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
} catch (Exception e) {
toast("未安装QQ");
}
onGotoAppFinish(view);
return true;
}
// ------- 处理结束 -------
if (!(url.startsWith("http") || url.startsWith("https"))) {
@@ -297,8 +250,26 @@ public class CommonWebViewActivity extends BaseActivity implements ShareDialog.O
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error); //一定要去掉
// handler.cancel();// Android默认的处理方式
handler.proceed();// 接受所有网站的证书
// handler.proceed();// 接受所有网站的证书
// handleMessage(Message msg);// 进行其他处理
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(view.getContext());
builder.setMessage("SSL认证失败是否继续访问吗");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();// 接受https所有网站的证书
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
@Override

View File

@@ -1,5 +1,6 @@
package com.nnbc123.app.ui.webview;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
@@ -10,6 +11,8 @@ import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import androidx.appcompat.app.AlertDialog;
import com.orhanobut.logger.Logger;
import com.nnbc123.app.R;
import com.nnbc123.app.base.BaseBindingFragment;
@@ -44,19 +47,19 @@ public class CommonWebViewFragment extends BaseBindingFragment<FragmentCommonWeb
//modules/noble/paySuccess.html
//modules/noble/order.html?nobleIndex=1 // 获取上下文, H5PayDemoActivity为当前页面
// ------ 对alipays:相关的scheme处理 -------
if (url.startsWith("alipays:") || url.startsWith("alipay")) {
try {
CommonWebViewFragment.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
} catch (Exception e) {
new BaseAlertDialogBuilder(CommonWebViewFragment.this.mContext)
.setMessage("未检测到支付宝客户端,请安装后重试。")
.setPositiveButton("立即安装", (dialog, which) -> {
Uri alipayUrl = Uri.parse("https://d.alipay.com");
CommonWebViewFragment.this.startActivity(new Intent("android.intent.action.VIEW", alipayUrl));
}).setNegativeButton("取消", null).show();
}
return true;
}
// if (url.startsWith("alipays:") || url.startsWith("alipay")) {
// try {
// CommonWebViewFragment.this.startActivity(new Intent("android.intent.action.VIEW", Uri.parse(url)));
// } catch (Exception e) {
// new BaseAlertDialogBuilder(CommonWebViewFragment.this.mContext)
// .setMessage("未检测到支付宝客户端,请安装后重试。")
// .setPositiveButton("立即安装", (dialog, which) -> {
// Uri alipayUrl = Uri.parse("https://d.alipay.com");
// CommonWebViewFragment.this.startActivity(new Intent("android.intent.action.VIEW", alipayUrl));
// }).setNegativeButton("取消", null).show();
// }
// return true;
// }
if (url.contains("tel:")) {
//删除直接拨打电话的功能
return true;
@@ -75,8 +78,26 @@ public class CommonWebViewFragment extends BaseBindingFragment<FragmentCommonWeb
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error); //一定要去掉
// handler.cancel();// Android默认的处理方式
handler.proceed();// 接受所有网站的证书
// handler.proceed();// 接受所有网站的证书
// handleMessage(Message msg);// 进行其他处理
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(view.getContext());
builder.setMessage("SSL认证失败是否继续访问吗");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();// 接受https所有网站的证书
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
@Override

View File

@@ -3,6 +3,7 @@ package com.nnbc123.app.ui.webview;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslError;
@@ -23,6 +24,7 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.LayoutRes;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import com.netease.nim.uikit.StatusBarUtil;
@@ -123,8 +125,26 @@ public class SimpleWebViewActivity extends AppCompatActivity {
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
// super.onReceivedSslError(view, handler, error); //一定要去掉
// handler.cancel();// Android默认的处理方式
handler.proceed();// 接受所有网站的证书
// handler.proceed();// 接受所有网站的证书
// handleMessage(Message msg);// 进行其他处理
androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(view.getContext());
builder.setMessage("SSL认证失败是否继续访问吗");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.proceed();// 接受https所有网站的证书
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
handler.cancel();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
@Override