按照官网给出的文档,在淘宝授权登录之后调用AlibcTrade.openByUrl()即可实现免密登录,那么问题来了。。。
1、首先不传webview 淘宝授权之后 调用方法,让输入用户名密码。
2、传入百川webview淘宝授权之后,还是输入用户名密码;
3、自定义webview淘宝授权之后,不用想了肯定还是同样问题;
private void openByUrl(String url) {
AlibcShowParams showParams = new AlibcShowParams();
showParams.setOpenType(OpenType.Native);
showParams.setBackUrl("");
AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", "");
Map<String, String> trackParams = new HashMap<>();
AlibcTrade.openByUrl(ChannelWebActivity.this, "", url, null,
new WebViewClient(), new WebChromeClient() {
}
showParams, taokeParams, trackParams, new AlibcTradeCallback() {
@Override
public void onTradeSuccess(AlibcTradeResult tradeResult) {
AlibcLogger.i("WebViewActivity", "request success");
}
@Override
public void onFailure(int code, String msg) {
AlibcLogger.e("WebViewActivity", "code=" + code + ", msg=" + msg);
}
});}}
解决办法:网址重定向调取下面方法(子线程)
new Thread(() -> {
String url = getRedirectUrl(NetConfig.TAOBAOURL);
}).start();
/**
* 获取重定向地址
* @param path
*/
private static StringgetRedirectUrl(String path) {
String url =null;
try {
HttpURLConnection conn = (HttpURLConnection)new URL(path).openConnection();
conn.setInstanceFollowRedirects(false);
conn.setConnectTimeout(5000);
url = conn.getHeaderField("Location");
conn.disconnect();
}catch (Exception e) {
e.printStackTrace();
}
return url;
}
不喜勿喷!!!