From e31cebc04abb0dfce8118ac83ffe1ba07699fd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=8D=8E=E8=BD=A9?= <646903573@qq.com> Date: Wed, 4 Nov 2020 10:16:32 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E7=99=BB=E9=99=86=E6=8E=88?= =?UTF-8?q?=E6=9D=83url=E6=B2=A1=E4=BC=A0=E8=BF=9Bwebview=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flutter_alibc/FlutterAlibcHandle.java | 114 +++++++++++------- .../com/wxwx/flutter_alibc/WebActivity.java | 8 +- 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java b/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java index aeb4651..e7ca838 100644 --- a/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java +++ b/android/src/main/java/com/wxwx/flutter_alibc/FlutterAlibcHandle.java @@ -5,6 +5,7 @@ import android.webkit.WebChromeClient; import android.webkit.WebViewClient; import android.widget.Toast; import android.content.Intent; + import com.ali.auth.third.core.model.Session; import com.alibaba.baichuan.trade.biz.context.AlibcResultType; 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.callback.AlibcTradeInitCallback; import com.alibaba.baichuan.trade.common.utils.AlibcLogger; + import io.flutter.plugin.common.PluginRegistry.Registrar; import io.flutter.plugin.common.MethodChannel.Result; import io.flutter.plugin.common.MethodCall; + import java.util.HashMap; + import android.app.AlertDialog; + import static com.wxwx.flutter_alibc.PluginConstants.*; import static com.wxwx.flutter_alibc.PluginUtil.*; + import com.wxwx.flutter_alibc.web.WebViewActivity; + import java.util.Map; /** * @Author karedem * @Date 2019/9/7 19:55 * @Description 接口处理者 -**/ -public class FlutterAlibcHandle{ + **/ +public class FlutterAlibcHandle { private static FlutterAlibcHandle handle; private Registrar 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.register = register; } @@ -56,15 +63,17 @@ public class FlutterAlibcHandle{ /** * 初始化阿里百川 + * * @param call * @param result */ - public void initAlibc(MethodCall call, Result result){ + public void initAlibc(MethodCall call, Result result) { AlibcTradeSDK.asyncInit(register.activity().getApplication(), new AlibcTradeInitCallback() { @Override public void onSuccess() { result.success(PluginResponse.success(null).toMap()); } + @Override public void onFailure(int code, String msg) { result.success(new PluginResponse(Integer.toString(code), msg, null).toMap()); @@ -74,11 +83,12 @@ public class FlutterAlibcHandle{ /** * 登陆淘宝 + * * @param result */ - public void loginTaoBao(Result result){ + public void loginTaoBao(Result result) { final AlibcLogin alibcLogin = AlibcLogin.getInstance(); - if (alibcLogin.isLogin()){ + if (alibcLogin.isLogin()) { Session session = AlibcLogin.getInstance().getSession(); Map userInfo = new HashMap<>(); userInfo.put("nick", session.nick); @@ -103,6 +113,7 @@ public class FlutterAlibcHandle{ userInfo.put("topAuthCode", session.topAuthCode); result.success(PluginResponse.success(userInfo).toMap()); } + @Override public void onFailure(int code, String msg) { // code:错误码 msg: 错误信息 @@ -113,14 +124,16 @@ public class FlutterAlibcHandle{ /** * 登出 + * * @param result */ - public void loginOut(Result result){ + public void loginOut(Result result) { AlibcLogin alibcLogin = AlibcLogin.getInstance(); alibcLogin.logout(new AlibcLoginCallback() { @Override public void onSuccess(int loginResult, String openId, String userNick) { } + @Override public void onFailure(int code, String msg) { // code:错误码 msg: 错误信息 @@ -130,24 +143,25 @@ public class FlutterAlibcHandle{ /** * 淘宝授权登陆 获取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 result */ - public void taoKeLogin(MethodCall call, Result result){ - HashMap map = (HashMap)call.arguments; + public void taoKeLogin(MethodCall call, Result result) { + HashMap map = (HashMap) call.arguments; String url = call.argument("url"); WebViewActivity.setCallBack(new WebViewActivity.CallBack() { @Override public void success(String accessToken) { - Map resMap = new HashMap(); + Map resMap = new HashMap(); resMap.put("accessToken", accessToken); result.success(resMap); } @Override public void failed(String errorMsg) { - Map resMap = new HashMap(); + Map resMap = new HashMap(); resMap.put("accessToken", ""); result.success(resMap); } @@ -160,17 +174,18 @@ public class FlutterAlibcHandle{ /** * 通过URL方式打开淘宝 + * * @param call * @param result */ - public void openByUrl(MethodCall call, Result result){ + public void openByUrl(MethodCall call, Result result) { AlibcShowParams showParams = new AlibcShowParams(); - AlibcTaokeParams taokeParams = new AlibcTaokeParams("","",""); + AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", ""); showParams.setBackUrl(call.argument(key_BackUrl)); ///渠道授权 - if((Boolean) call.argument(login_And_Auth)){ + if ((Boolean) call.argument(login_And_Auth)) { ///先APP授权 if (!AlibcLogin.getInstance().isLogin()) { @@ -178,18 +193,22 @@ public class FlutterAlibcHandle{ AlibcLogin.getInstance().showLogin(new AlibcLoginCallback() { @Override 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 public void onFailure(int i, String s) { - Log.d("阿里百川授权失败",s); + Log.d("阿里百川授权失败", s); } }); } 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; @@ -203,8 +222,8 @@ public class FlutterAlibcHandle{ // System.out.println("clientType " + 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"))){ // showParams.setNativeOpenFailedMode(AlibcFailModeType.AlibcNativeFailModeNONE); @@ -221,15 +240,16 @@ public class FlutterAlibcHandle{ @Override public void onTradeSuccess(AlibcTradeResult tradeResult) { Map results = new HashMap<>(); - if (AlibcResultType.TYPECART == tradeResult.resultType){ + if (AlibcResultType.TYPECART == tradeResult.resultType) { results.put("type", 1); - }else if (AlibcResultType.TYPEPAY == tradeResult.resultType){ + } else if (AlibcResultType.TYPEPAY == tradeResult.resultType) { results.put("type", 0); results.put("payFailedOrders", tradeResult.payResult.payFailedOrders); results.put("paySuccessOrders", tradeResult.payResult.paySuccessOrders); } result.success(PluginResponse.success(results).toMap()); } + @Override public void onFailure(int code, String msg) { result.success(new PluginResponse(Integer.toString(code), msg, null).toMap()); @@ -241,53 +261,56 @@ public class FlutterAlibcHandle{ /** * 打开商店 + * * @param call * @param result */ - public void openShop(MethodCall call, Result result){ + public void openShop(MethodCall call, Result result) { AlibcBasePage page = new AlibcShopPage(call.argument("shopId")); openByBizCode(page, "shop", call, result); } /** * 打开购物车 + * * @param result */ - public void openCart(MethodCall call, Result result){ + public void openCart(MethodCall call, Result result) { AlibcBasePage page = new AlibcMyCartsPage(); - openByBizCode(page, "cart",call, result); + openByBizCode(page, "cart", call, result); } /** * 打开商品详情 + * * @param call call.argument["itemID"] 详情id * @param result */ - public void openItemDetail(MethodCall call, Result result){ + public void openItemDetail(MethodCall call, Result result) { AlibcBasePage page = new AlibcDetailPage(call.argument("itemID")); 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(); AlibcTaokeParams taokeParams = new AlibcTaokeParams("", "", ""); 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); - }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 trackParams = new HashMap<>(); @@ -297,15 +320,16 @@ public class FlutterAlibcHandle{ @Override public void onTradeSuccess(AlibcTradeResult tradeResult) { Map results = new HashMap<>(); - if (AlibcResultType.TYPECART == tradeResult.resultType){ + if (AlibcResultType.TYPECART == tradeResult.resultType) { results.put("type", 1); - }else if (AlibcResultType.TYPEPAY == tradeResult.resultType){ + } else if (AlibcResultType.TYPEPAY == tradeResult.resultType) { results.put("type", 0); results.put("payFailedOrders", tradeResult.payResult.payFailedOrders); results.put("paySuccessOrders", tradeResult.payResult.paySuccessOrders); } result.success(PluginResponse.success(results).toMap()); } + @Override public void onFailure(int code, String msg) { // 失败回调信息 @@ -316,17 +340,19 @@ public class FlutterAlibcHandle{ /** * 设置淘客打点策略 是否异步 + * * @param call */ - public void syncForTaoke(MethodCall call){ + public void syncForTaoke(MethodCall call) { AlibcTradeSDK.setSyncForTaoke(call.argument("isSync")); } /** * TODO + * * @param call */ - public void useAlipayNative(MethodCall call){ + public void useAlipayNative(MethodCall call) { AlibcTradeSDK.setShouldUseAlipay(call.argument("isNeed")); } diff --git a/android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java b/android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java index c32e488..73deb06 100644 --- a/android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java +++ b/android/src/main/java/com/wxwx/flutter_alibc/WebActivity.java @@ -50,6 +50,7 @@ public class WebActivity extends Activity { mainWeb.getSettings().setAllowFileAccess(true); mainWeb.getSettings().setDatabaseEnabled(true); + String url = getIntent().getStringExtra("url"); ImageView imageView = findViewById(R.id.go_to_back); 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, "")); AlibcShowParams showParams = new AlibcShowParams(); 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, new AlibcTaokeParams("", "", ""), exParams, new AlibcTradeCallback() { @Override @@ -91,7 +92,7 @@ public class WebActivity extends Activity { 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); mainWeb.addJavascriptInterface(new InJavaScriptLocalObj(), "java_obj"); } @@ -123,7 +124,7 @@ public class WebActivity extends Activity { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { // WebLoad.setVisibility(View.GONE); - // mainWeb.setVisibility(View.GONE); + // mainWeb.setVisibility(View.GONE); //开始加载设置为透明 super.onPageStarted(view, url, favicon); } @@ -145,7 +146,6 @@ public class WebActivity extends Activity { view.loadUrl("javascript:window.java_obj.showDescription(" + "document.querySelector('meta[name=\"share-description\"]').getAttribute('content')" + ");"); - // quanyikaText(); super.onPageFinished(view, url); }