【全球收单】
1. Android WebView设置参考代码
java
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setPluginState(WebSettings.PluginState.ON); //enable plugin. Ex: flash. deprecated on API 18
//whether the zoom controls display on screen.
webSettings.setBuiltInZoomControls(true);
webSettings.setSupportZoom(true);
webSettings.setDisplayZoomControls(false);
//disable the webview font size changes according the phone font size.
webSettings.setTextZoom(100);
webSettings.setSaveFormData(true);
webSettings.setUseWideViewPort(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setAllowFileAccess(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
CookieManager.getInstance().setAcceptThirdPartyCookies(this, true);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
webSettings.setAllowUniversalAccessFromFileURLs(true);
}
webSettings.setAppCacheEnabled(true);
String appCacheDir = getDir("cache", Context.MODE_PRIVATE).getPath();
webSettings.setAppCachePath(appCacheDir);
webSettings.setAppCacheMaxSize(1024*1024*20);
webSettings.setDomStorageEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
try {
mWebView.removeJavascriptInterface("searchBoxJavaBridge_");
mWebView.removeJavascriptInterface("accessibility");
mWebView.removeJavascriptInterface("accessibilityTraversal");
} catch (Exception e) {}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mWebView.enableSlowWholeDocumentDraw();
}
2. 验签失败问题
- 确保加签和验签使用相同的密钥对:检查公钥和私钥是否配对。验签确认使用Payloco提供的公钥。
- 检查数据是否一致:在加签和验签前,将待签名的数据进行日志输出,对比两者是否完全相同。检查原始请求体是否被修改(空格/换行符/编码),不同平台(Windows/Linux)的换行符不同
- 确保相同的算法:检查代码中加签和验签使用的算法字符串是否完全一致。签名算法未使用SHA256withRSA。
- 检查编码处理:确保在需要编码转换(如Base64)时,加签和验签两端使用相同的编码方式。
- 规范数据格式:比如JSON数据可以使用紧凑模式(去除不必要的空格)或者使用规范的序列化(如按字段名排序)。
- 调试日志:在关键步骤打印日志,如待签名数据、签名结果、验签时的数据和签名等,以便对比。
- 使用标准库和规范实现:避免自己实现复杂的签名流程,使用成熟的库和工具。
- 私钥格式错误(必须使用PKCS#8格式)
- 请求头未携带X-Signature参数
- 框架配置陷阱
- 过滤器顺序问题,Spring框架中,验签过滤器在 CharacterEncodingFilter 之前执行,导致请求体被多次读取后失效;
- 参数解析干扰,框架自动解析的请求体(如 @RequestBody)已修改原始数据(如日期格式化)
- HTTP 工具行为差异,使用 HttpServletRequest.getParameter() 读取参数时,若 Content-Type 非 application/x-www-form-urlencoded,返回值可能为 null