浏览代码

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

tags/0.0.5
“yanghuaxuan” 3 年前
父节点
当前提交
f0974bf1ee
共有 4 个文件被更改,包括 58 次插入13 次删除
  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 查看文件

@@ -25,6 +25,7 @@ import com.alibaba.baichuan.android.trade.AlibcTradeSDK;
import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback;
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.MethodChannel.Result;
import io.flutter.plugin.common.MethodCall;
@@ -49,14 +50,16 @@ public class FlutterAlibcHandle {

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

//第一次调用getInstance 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;
}

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

}

/**
@@ -180,12 +184,35 @@ public class FlutterAlibcHandle {
public void openByUrl(MethodCall call, Result result) {
AlibcShowParams showParams = new AlibcShowParams();
AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", "");
FlutterAlibcHandle.result=result;
showParams.setBackUrl(call.argument(key_BackUrl));

///渠道授权
if ((Boolean) call.argument(login_And_Auth)) {
///先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()) {

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

}

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


+ 4
- 1
android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java 查看文件

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

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

} catch (Exception e) {


+ 2
- 2
lib/alibc_model.dart 查看文件

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

TradeResultType type;



+ 17
- 3
lib/flutter_alibc.dart 查看文件

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

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

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

// ..setMethodCallHandler(_handler);

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


正在加载...
取消
保存