Browse Source

1.优化android授权失败后的显示

tags/0.0.5
“yanghuaxuan” 3 years ago
parent
commit
f0974bf1ee
4 changed files with 58 additions and 13 deletions
  1. +35
    -7
      android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java
  2. +4
    -1
      android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java
  3. +2
    -2
      lib/alibc_model.dart
  4. +17
    -3
      lib/flutter_alibc.dart

+ 35
- 7
android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java View File

@@ -25,6 +25,7 @@ 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;
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;
@@ -49,14 +50,16 @@ public class FlutterAlibcHandle {


private static FlutterAlibcHandle handle; private static FlutterAlibcHandle handle;
private static Registrar register; private static Registrar register;
private static boolean isFirst = true;
private static Result result;


//第一次调用getInstance register不能为空 //第一次调用getInstance register不能为空
public static FlutterAlibcHandle getInstance(Registrar register) { public static FlutterAlibcHandle getInstance(Registrar register) {


synchronized (FlutterAlibcHandle.class) {
handle = new FlutterAlibcHandle();
FlutterAlibcHandle.register = register;
}
synchronized (FlutterAlibcHandle.class) {
handle = new FlutterAlibcHandle();
FlutterAlibcHandle.register = register;
}
return handle; return handle;
} }


@@ -169,6 +172,7 @@ public class FlutterAlibcHandle {
intent.putExtra("url", url); intent.putExtra("url", url);
intent.putExtra("arguments", map); intent.putExtra("arguments", map);
register.activity().startActivity(intent); register.activity().startActivity(intent);

} }


/** /**
@@ -180,12 +184,35 @@ public class FlutterAlibcHandle {
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("", "", "");
FlutterAlibcHandle.result=result;
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(isFirst){
isFirst=false;
register.addActivityResultListener(new PluginRegistry.ActivityResultListener() {
@Override
public boolean onActivityResult(int requestCode, int resultCode, Intent data) {
if (FlutterAlibcHandle.result == null) {
return false;
}
if (requestCode == 1111) {
if (resultCode == 222222) {
FlutterAlibcHandle.result.success(true);
} else if (resultCode == 111111) {
FlutterAlibcHandle.result.success(false);
}

return true;
} else {
return false;
}

}
});
}


if (!AlibcLogin.getInstance().isLogin()) { if (!AlibcLogin.getInstance().isLogin()) {


@@ -195,7 +222,8 @@ public class FlutterAlibcHandle {
Log.d("阿里百川打开WebView", "webview"); Log.d("阿里百川打开WebView", "webview");
Intent intent = new Intent(register.context(), WebActivity.class); Intent intent = new Intent(register.context(), WebActivity.class);
intent.putExtra("url", (String) call.argument("url")); intent.putExtra("url", (String) call.argument("url"));
register.activity().startActivity(intent);
register.activity().startActivityForResult(intent, 1111);

} }


@Override @Override
@@ -207,7 +235,7 @@ public class FlutterAlibcHandle {
Log.d("阿里百川打开WebView", "webview"); Log.d("阿里百川打开WebView", "webview");
Intent intent = new Intent(register.context(), WebActivity.class); Intent intent = new Intent(register.context(), WebActivity.class);
intent.putExtra("url", (String) call.argument("url")); intent.putExtra("url", (String) call.argument("url"));
register.activity().startActivity(intent);
register.activity().startActivityForResult(intent, 1111);
} }
///后渠道信息 ///后渠道信息
return; return;


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

@@ -169,10 +169,13 @@ public class WebActivity extends Activity {


try { try {
if (html.contains("成功")) {//成功 if (html.contains("成功")) {//成功
Toast.makeText(WebActivity.this, "授权成功", Toast.LENGTH_SHORT).show();
// Toast.makeText(WebActivity.this, "授权成功", Toast.LENGTH_SHORT).show();
setResult(222222);
finish(); finish();
} else {//失败 } else {//失败
setResult(111111);
mainWeb.setAlpha(0); mainWeb.setAlpha(0);
finish();
} }


} catch (Exception e) { } catch (Exception e) {


+ 2
- 2
lib/alibc_model.dart View File

@@ -50,9 +50,9 @@ class TaokeParams {
// url打开或者page打开等的数据 // url打开或者page打开等的数据
class TradeResult { class TradeResult {
// 错误码,0为成功,非0为失败 // 错误码,0为成功,非0为失败
final String errorCode;
String errorCode;
// 错误信息 // 错误信息
final String errorMessage;
String errorMessage;


TradeResultType type; TradeResultType type;




+ 17
- 3
lib/flutter_alibc.dart View File

@@ -1,4 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:io';


import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
@@ -20,6 +21,7 @@ class FlutterAlibc {


// 通信的桥接类 // 通信的桥接类
static final MethodChannel _channel = const MethodChannel("flutter_alibc"); static final MethodChannel _channel = const MethodChannel("flutter_alibc");

// ..setMethodCallHandler(_handler); // ..setMethodCallHandler(_handler);


static Future<String> get platformVersion async { static Future<String> get platformVersion async {
@@ -125,10 +127,10 @@ class FlutterAlibc {
AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTmall, AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTmall,
TaokeParams taokeParams, TaokeParams taokeParams,
String backUrl, String backUrl,
bool isAuth=false
bool isAuth = false
}) async { }) async {
Map taoKe = AlibcTools.getTaokeMap(taokeParams); Map taoKe = AlibcTools.getTaokeMap(taokeParams);
Map result = await _channel.invokeMethod("openByUrl", {
var result = await _channel.invokeMethod("openByUrl", {
"url": url, "url": url,
"openType": openType.index, "openType": openType.index,
"isNeedCustomNativeFailMode": isNeedCustomNativeFailMode, "isNeedCustomNativeFailMode": isNeedCustomNativeFailMode,
@@ -136,9 +138,21 @@ class FlutterAlibc {
"schemeType": schemeType.index, "schemeType": schemeType.index,
"taokeParams": taoKe, "taokeParams": taoKe,
"backUrl": backUrl, "backUrl": backUrl,
"auth":isAuth
"auth": isAuth
}); });
if (isAuth && Platform.isAndroid) {
TradeResult tradeResult = TradeResult("-1", "");


if (result != null && result) {
///授权成功
tradeResult.errorCode = "0";
return tradeResult;
} else {
///授权失败
tradeResult.errorCode = "-1";
return tradeResult;
}
}
TradeResult tradeResult = AlibcTools.getTradeResult(result); TradeResult tradeResult = AlibcTools.getTradeResult(result);
return tradeResult; return tradeResult;
} }


Loading…
Cancel
Save