Browse Source

1.修复登陆授权url没传进webview的问题

tags/0.0.2^0
杨华轩 4 years ago
parent
commit
e31cebc04a
2 changed files with 74 additions and 48 deletions
  1. +70
    -44
      android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java
  2. +4
    -4
      android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java

+ 70
- 44
android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java View File

@@ -5,6 +5,7 @@ import android.webkit.WebChromeClient;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import android.widget.Toast; import android.widget.Toast;
import android.content.Intent; import android.content.Intent;

import com.ali.auth.third.core.model.Session; import com.ali.auth.third.core.model.Session;
import com.alibaba.baichuan.trade.biz.context.AlibcResultType; import com.alibaba.baichuan.trade.biz.context.AlibcResultType;
import com.alibaba.baichuan.android.trade.AlibcTrade; import com.alibaba.baichuan.android.trade.AlibcTrade;
@@ -23,30 +24,36 @@ import com.alibaba.baichuan.trade.biz.login.AlibcLoginCallback;
import com.alibaba.baichuan.android.trade.AlibcTradeSDK; import com.alibaba.baichuan.android.trade.AlibcTradeSDK;
import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback; import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback;
import com.alibaba.baichuan.trade.common.utils.AlibcLogger; import com.alibaba.baichuan.trade.common.utils.AlibcLogger;

import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodCall;

import java.util.HashMap; import java.util.HashMap;

import android.app.AlertDialog; import android.app.AlertDialog;

import static com.wxwx.flutter_alibc.PluginConstants.*; import static com.wxwx.flutter_alibc.PluginConstants.*;
import static com.wxwx.flutter_alibc.PluginUtil.*; import static com.wxwx.flutter_alibc.PluginUtil.*;

import com.wxwx.flutter_alibc.web.WebViewActivity; import com.wxwx.flutter_alibc.web.WebViewActivity;

import java.util.Map; import java.util.Map;


/** /**
* @Author karedem * @Author karedem
* @Date 2019/9/7 19:55 * @Date 2019/9/7 19:55
* @Description 接口处理者 * @Description 接口处理者
**/
public class FlutterAlibcHandle{
**/
public class FlutterAlibcHandle {


private static FlutterAlibcHandle handle; private static FlutterAlibcHandle handle;
private Registrar register; private Registrar register;


//第一次调用getInstance register不能为空 //第一次调用getInstance register不能为空
public static FlutterAlibcHandle getInstance(Registrar register){
if (handle == null){
synchronized (FlutterAlibcHandle.class){
public static FlutterAlibcHandle getInstance(Registrar register) {
if (handle == null) {
synchronized (FlutterAlibcHandle.class) {
handle = new FlutterAlibcHandle(); handle = new FlutterAlibcHandle();
handle.register = register; handle.register = register;
} }
@@ -56,15 +63,17 @@ public class FlutterAlibcHandle{


/** /**
* 初始化阿里百川 * 初始化阿里百川
*
* @param call * @param call
* @param result * @param result
*/ */
public void initAlibc(MethodCall call, Result result){
public void initAlibc(MethodCall call, Result result) {
AlibcTradeSDK.asyncInit(register.activity().getApplication(), new AlibcTradeInitCallback() { AlibcTradeSDK.asyncInit(register.activity().getApplication(), new AlibcTradeInitCallback() {
@Override @Override
public void onSuccess() { public void onSuccess() {
result.success(PluginResponse.success(null).toMap()); result.success(PluginResponse.success(null).toMap());
} }

@Override @Override
public void onFailure(int code, String msg) { public void onFailure(int code, String msg) {
result.success(new PluginResponse(Integer.toString(code), msg, null).toMap()); result.success(new PluginResponse(Integer.toString(code), msg, null).toMap());
@@ -74,11 +83,12 @@ public class FlutterAlibcHandle{


/** /**
* 登陆淘宝 * 登陆淘宝
*
* @param result * @param result
*/ */
public void loginTaoBao(Result result){
public void loginTaoBao(Result result) {
final AlibcLogin alibcLogin = AlibcLogin.getInstance(); final AlibcLogin alibcLogin = AlibcLogin.getInstance();
if (alibcLogin.isLogin()){
if (alibcLogin.isLogin()) {
Session session = AlibcLogin.getInstance().getSession(); Session session = AlibcLogin.getInstance().getSession();
Map<String, Object> userInfo = new HashMap<>(); Map<String, Object> userInfo = new HashMap<>();
userInfo.put("nick", session.nick); userInfo.put("nick", session.nick);
@@ -103,6 +113,7 @@ public class FlutterAlibcHandle{
userInfo.put("topAuthCode", session.topAuthCode); userInfo.put("topAuthCode", session.topAuthCode);
result.success(PluginResponse.success(userInfo).toMap()); result.success(PluginResponse.success(userInfo).toMap());
} }

@Override @Override
public void onFailure(int code, String msg) { public void onFailure(int code, String msg) {
// code:错误码 msg: 错误信息 // code:错误码 msg: 错误信息
@@ -113,14 +124,16 @@ public class FlutterAlibcHandle{


/** /**
* 登出 * 登出
*
* @param result * @param result
*/ */
public void loginOut(Result result){
public void loginOut(Result result) {
AlibcLogin alibcLogin = AlibcLogin.getInstance(); AlibcLogin alibcLogin = AlibcLogin.getInstance();
alibcLogin.logout(new AlibcLoginCallback() { alibcLogin.logout(new AlibcLoginCallback() {
@Override @Override
public void onSuccess(int loginResult, String openId, String userNick) { public void onSuccess(int loginResult, String openId, String userNick) {
} }

@Override @Override
public void onFailure(int code, String msg) { public void onFailure(int code, String msg) {
// code:错误码 msg: 错误信息 // code:错误码 msg: 错误信息
@@ -130,24 +143,25 @@ public class FlutterAlibcHandle{


/** /**
* 淘宝授权登陆 获取access_token * 淘宝授权登陆 获取access_token
* 官方说明文档 {https://open.taobao.com/doc.htm?docId=118&docType=1}
* 官方说明文档 {https://open.taobao.com/doc.htm?docId=118&docType=1}
*
* @param call * @param call
* @param result * @param result
*/ */
public void taoKeLogin(MethodCall call, Result result){
HashMap<String, Object> map = (HashMap<String, Object>)call.arguments;
public void taoKeLogin(MethodCall call, Result result) {
HashMap<String, Object> map = (HashMap<String, Object>) call.arguments;
String url = call.argument("url"); String url = call.argument("url");
WebViewActivity.setCallBack(new WebViewActivity.CallBack() { WebViewActivity.setCallBack(new WebViewActivity.CallBack() {
@Override @Override
public void success(String accessToken) { public void success(String accessToken) {
Map<String,String> resMap = new HashMap();
Map<String, String> resMap = new HashMap();
resMap.put("accessToken", accessToken); resMap.put("accessToken", accessToken);
result.success(resMap); result.success(resMap);
} }


@Override @Override
public void failed(String errorMsg) { public void failed(String errorMsg) {
Map<String,String> resMap = new HashMap();
Map<String, String> resMap = new HashMap();
resMap.put("accessToken", ""); resMap.put("accessToken", "");
result.success(resMap); result.success(resMap);
} }
@@ -160,17 +174,18 @@ public class FlutterAlibcHandle{


/** /**
* 通过URL方式打开淘宝 * 通过URL方式打开淘宝
*
* @param call * @param call
* @param result * @param result
*/ */
public void openByUrl(MethodCall call, Result result){
public void openByUrl(MethodCall call, Result result) {
AlibcShowParams showParams = new AlibcShowParams(); AlibcShowParams showParams = new AlibcShowParams();
AlibcTaokeParams taokeParams = new AlibcTaokeParams("","","");
AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", "");


showParams.setBackUrl(call.argument(key_BackUrl)); showParams.setBackUrl(call.argument(key_BackUrl));


///渠道授权 ///渠道授权
if((Boolean) call.argument(login_And_Auth)){
if ((Boolean) call.argument(login_And_Auth)) {
///先APP授权 ///先APP授权


if (!AlibcLogin.getInstance().isLogin()) { if (!AlibcLogin.getInstance().isLogin()) {
@@ -178,18 +193,22 @@ public class FlutterAlibcHandle{
AlibcLogin.getInstance().showLogin(new AlibcLoginCallback() { AlibcLogin.getInstance().showLogin(new AlibcLoginCallback() {
@Override @Override
public void onSuccess(int i, String s, String s1) { public void onSuccess(int i, String s, String s1) {
Log.d("阿里百川打开WebView","webview");
register.activity().startActivity(new Intent(register.activity(),WebActivity.class));
Log.d("阿里百川打开WebView", "webview");
Intent intent = new Intent(register.activity(), WebActivity.class);
intent.putExtra("url", (String) call.argument("url"));
register.activity().startActivity(intent);
} }


@Override @Override
public void onFailure(int i, String s) { public void onFailure(int i, String s) {
Log.d("阿里百川授权失败",s);
Log.d("阿里百川授权失败", s);
} }
}); });
} else { } else {
Log.d("阿里百川打开WebView","webview");
register.activity().startActivity(new Intent(register.activity(),WebActivity.class));
Log.d("阿里百川打开WebView", "webview");
Intent intent = new Intent(register.activity(), WebActivity.class);
intent.putExtra("url", (String) call.argument("url"));
register.activity().startActivity(intent);
} }
///后渠道信息 ///后渠道信息
return; return;
@@ -203,8 +222,8 @@ public class FlutterAlibcHandle{
// System.out.println("clientType " + call.argument(key_ClientType)); // System.out.println("clientType " + call.argument(key_ClientType));
// showParams.setClientType(getClientType(""+call.argument(key_ClientType))); // showParams.setClientType(getClientType(""+call.argument(key_ClientType)));
// } // }
if (call.argument("taokeParams") != null){
taokeParams = getTaokeParams(call.argument("taokeParams"));
if (call.argument("taokeParams") != null) {
taokeParams = getTaokeParams(call.argument("taokeParams"));
} }
// if ("false".equals(call.argument("isNeedCustomNativeFailMode"))){ // if ("false".equals(call.argument("isNeedCustomNativeFailMode"))){
// showParams.setNativeOpenFailedMode(AlibcFailModeType.AlibcNativeFailModeNONE); // showParams.setNativeOpenFailedMode(AlibcFailModeType.AlibcNativeFailModeNONE);
@@ -221,15 +240,16 @@ public class FlutterAlibcHandle{
@Override @Override
public void onTradeSuccess(AlibcTradeResult tradeResult) { public void onTradeSuccess(AlibcTradeResult tradeResult) {
Map<String, Object> results = new HashMap<>(); Map<String, Object> results = new HashMap<>();
if (AlibcResultType.TYPECART == tradeResult.resultType){
if (AlibcResultType.TYPECART == tradeResult.resultType) {
results.put("type", 1); results.put("type", 1);
}else if (AlibcResultType.TYPEPAY == tradeResult.resultType){
} else if (AlibcResultType.TYPEPAY == tradeResult.resultType) {
results.put("type", 0); results.put("type", 0);
results.put("payFailedOrders", tradeResult.payResult.payFailedOrders); results.put("payFailedOrders", tradeResult.payResult.payFailedOrders);
results.put("paySuccessOrders", tradeResult.payResult.paySuccessOrders); results.put("paySuccessOrders", tradeResult.payResult.paySuccessOrders);
} }
result.success(PluginResponse.success(results).toMap()); result.success(PluginResponse.success(results).toMap());
} }

@Override @Override
public void onFailure(int code, String msg) { public void onFailure(int code, String msg) {
result.success(new PluginResponse(Integer.toString(code), msg, null).toMap()); result.success(new PluginResponse(Integer.toString(code), msg, null).toMap());
@@ -241,53 +261,56 @@ public class FlutterAlibcHandle{


/** /**
* 打开商店 * 打开商店
*
* @param call * @param call
* @param result * @param result
*/ */
public void openShop(MethodCall call, Result result){
public void openShop(MethodCall call, Result result) {
AlibcBasePage page = new AlibcShopPage(call.argument("shopId")); AlibcBasePage page = new AlibcShopPage(call.argument("shopId"));
openByBizCode(page, "shop", call, result); openByBizCode(page, "shop", call, result);
} }


/** /**
* 打开购物车 * 打开购物车
*
* @param result * @param result
*/ */
public void openCart(MethodCall call, Result result){
public void openCart(MethodCall call, Result result) {
AlibcBasePage page = new AlibcMyCartsPage(); AlibcBasePage page = new AlibcMyCartsPage();
openByBizCode(page, "cart",call, result);
openByBizCode(page, "cart", call, result);
} }


/** /**
* 打开商品详情 * 打开商品详情
*
* @param call call.argument["itemID"] 详情id * @param call call.argument["itemID"] 详情id
* @param result * @param result
*/ */
public void openItemDetail(MethodCall call, Result result){
public void openItemDetail(MethodCall call, Result result) {
AlibcBasePage page = new AlibcDetailPage(call.argument("itemID")); AlibcBasePage page = new AlibcDetailPage(call.argument("itemID"));
openByBizCode(page, "detail", call, result); openByBizCode(page, "detail", call, result);
} }


private void openByBizCode(AlibcBasePage page,String type, MethodCall call, Result result){
private void openByBizCode(AlibcBasePage page, String type, MethodCall call, Result result) {
AlibcShowParams showParams = new AlibcShowParams(); AlibcShowParams showParams = new AlibcShowParams();
AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", ""); AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", "");


showParams.setBackUrl(call.argument(key_BackUrl)); showParams.setBackUrl(call.argument(key_BackUrl));


if (call.argument(key_OpenType) != null){
showParams.setOpenType(getOpenType(""+call.argument(key_OpenType)));
if (call.argument(key_OpenType) != null) {
showParams.setOpenType(getOpenType("" + call.argument(key_OpenType)));
} }
if (call.argument(key_ClientType) != null){
showParams.setClientType(getClientType(""+call.argument(key_ClientType)));
if (call.argument(key_ClientType) != null) {
showParams.setClientType(getClientType("" + call.argument(key_ClientType)));
} }
if (call.argument("taokeParams") != null){
taokeParams = getTaokeParams(call.argument("taokeParams"));
if (call.argument("taokeParams") != null) {
taokeParams = getTaokeParams(call.argument("taokeParams"));
} }


if ("false".equals(call.argument("isNeedCustomNativeFailMode"))){
if ("false".equals(call.argument("isNeedCustomNativeFailMode"))) {
showParams.setNativeOpenFailedMode(AlibcFailModeType.AlibcNativeFailModeNONE); showParams.setNativeOpenFailedMode(AlibcFailModeType.AlibcNativeFailModeNONE);
}else if (call.argument(key_NativeFailMode) != null){
showParams.setNativeOpenFailedMode(getFailModeType(""+call.argument(key_NativeFailMode)));
} else if (call.argument(key_NativeFailMode) != null) {
showParams.setNativeOpenFailedMode(getFailModeType("" + call.argument(key_NativeFailMode)));
} }


Map<String, String> trackParams = new HashMap<>(); Map<String, String> trackParams = new HashMap<>();
@@ -297,15 +320,16 @@ public class FlutterAlibcHandle{
@Override @Override
public void onTradeSuccess(AlibcTradeResult tradeResult) { public void onTradeSuccess(AlibcTradeResult tradeResult) {
Map<String, Object> results = new HashMap<>(); Map<String, Object> results = new HashMap<>();
if (AlibcResultType.TYPECART == tradeResult.resultType){
if (AlibcResultType.TYPECART == tradeResult.resultType) {
results.put("type", 1); results.put("type", 1);
}else if (AlibcResultType.TYPEPAY == tradeResult.resultType){
} else if (AlibcResultType.TYPEPAY == tradeResult.resultType) {
results.put("type", 0); results.put("type", 0);
results.put("payFailedOrders", tradeResult.payResult.payFailedOrders); results.put("payFailedOrders", tradeResult.payResult.payFailedOrders);
results.put("paySuccessOrders", tradeResult.payResult.paySuccessOrders); results.put("paySuccessOrders", tradeResult.payResult.paySuccessOrders);
} }
result.success(PluginResponse.success(results).toMap()); result.success(PluginResponse.success(results).toMap());
} }

@Override @Override
public void onFailure(int code, String msg) { public void onFailure(int code, String msg) {
// 失败回调信息 // 失败回调信息
@@ -316,17 +340,19 @@ public class FlutterAlibcHandle{


/** /**
* 设置淘客打点策略 是否异步 * 设置淘客打点策略 是否异步
*
* @param call * @param call
*/ */
public void syncForTaoke(MethodCall call){
public void syncForTaoke(MethodCall call) {
AlibcTradeSDK.setSyncForTaoke(call.argument("isSync")); AlibcTradeSDK.setSyncForTaoke(call.argument("isSync"));
} }


/** /**
* TODO * TODO
*
* @param call * @param call
*/ */
public void useAlipayNative(MethodCall call){
public void useAlipayNative(MethodCall call) {
AlibcTradeSDK.setShouldUseAlipay(call.argument("isNeed")); AlibcTradeSDK.setShouldUseAlipay(call.argument("isNeed"));
} }




+ 4
- 4
android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java View File

@@ -50,6 +50,7 @@ public class WebActivity extends Activity {
mainWeb.getSettings().setAllowFileAccess(true); mainWeb.getSettings().setAllowFileAccess(true);
mainWeb.getSettings().setDatabaseEnabled(true); mainWeb.getSettings().setDatabaseEnabled(true);


String url = getIntent().getStringExtra("url");


ImageView imageView = findViewById(R.id.go_to_back); ImageView imageView = findViewById(R.id.go_to_back);
imageView.setOnClickListener(new View.OnClickListener() { imageView.setOnClickListener(new View.OnClickListener() {
@@ -67,7 +68,7 @@ public class WebActivity extends Activity {
// alibcTaokeParams.extraParams.put("taokeAppkey", SPUtils.getPrefString(mActivity, Pkey.APP_alliance_appkey, "")); // alibcTaokeParams.extraParams.put("taokeAppkey", SPUtils.getPrefString(mActivity, Pkey.APP_alliance_appkey, ""));
AlibcShowParams showParams = new AlibcShowParams(); AlibcShowParams showParams = new AlibcShowParams();
showParams.setBackUrl("alisdk://"); showParams.setBackUrl("alisdk://");
AlibcTrade.openByUrl(WebActivity.this, "", "http://www.izhim.com/comm/tb_callback.php?_ctrl=domain&domain_state=MTI2&domain_return_url=aHR0cDovLzE5Mi4xNjguMC4xMTM6NTAwMC9hcGkvdjEvdGFvYmFvL2F1dGgvY2FsbGJhY2s%2FdGltZT0xNjAyNDk4MjA3",
AlibcTrade.openByUrl(WebActivity.this, "", url,
mainWeb, new MyBaichuanWebClient(), new MyWebChromeClient(), showParams, mainWeb, new MyBaichuanWebClient(), new MyWebChromeClient(), showParams,
new AlibcTaokeParams("", "", ""), exParams, new AlibcTradeCallback() { new AlibcTaokeParams("", "", ""), exParams, new AlibcTradeCallback() {
@Override @Override
@@ -91,7 +92,7 @@ public class WebActivity extends Activity {


Log.d("百川拦截", url); Log.d("百川拦截", url);
//绑定会员关系时获取网页内容关闭网页 //绑定会员关系时获取网页内容关闭网页
if (url.contains("http://www.izhim.com/comm/tb_callback")&&!url.contains("redirect_uri")) {
if (url.contains("http://www.izhim.com/comm/tb_callback") && !url.contains("redirect_uri")) {
Log.d("百川系时获取网页内容关闭网页", url); Log.d("百川系时获取网页内容关闭网页", url);
mainWeb.addJavascriptInterface(new InJavaScriptLocalObj(), "java_obj"); mainWeb.addJavascriptInterface(new InJavaScriptLocalObj(), "java_obj");
} }
@@ -123,7 +124,7 @@ public class WebActivity extends Activity {
@Override @Override
public void onPageStarted(WebView view, String url, Bitmap favicon) { public void onPageStarted(WebView view, String url, Bitmap favicon) {
// WebLoad.setVisibility(View.GONE); // WebLoad.setVisibility(View.GONE);
// mainWeb.setVisibility(View.GONE);
// mainWeb.setVisibility(View.GONE);
//开始加载设置为透明 //开始加载设置为透明
super.onPageStarted(view, url, favicon); super.onPageStarted(view, url, favicon);
} }
@@ -145,7 +146,6 @@ public class WebActivity extends Activity {
view.loadUrl("javascript:window.java_obj.showDescription(" view.loadUrl("javascript:window.java_obj.showDescription("
+ "document.querySelector('meta[name=\"share-description\"]').getAttribute('content')" + "document.querySelector('meta[name=\"share-description\"]').getAttribute('content')"
+ ");"); + ");");
// quanyikaText();
super.onPageFinished(view, url); super.onPageFinished(view, url);
} }




Loading…
Cancel
Save