Kaynağa Gözat

1、添加拼多多授权

2、修改验证码登录
3、把跳转原生抽取成一个方法
tags/0.0.13+2^0
PH2 3 yıl önce
ebeveyn
işleme
381b1afb9b
10 değiştirilmiş dosya ile 480 ekleme ve 96 silme
  1. BIN
     
  2. BIN
     
  3. +4
    -4
      lib/pages/login_page/account/login_account_page.dart
  4. +2
    -0
      lib/pages/login_page/invite/bloc/login_invite_repository.dart
  5. +52
    -0
      lib/util/pdd_auth/pdd_auth.dart
  6. +86
    -0
      lib/util/pdd_auth/pdd_auth_dialog.dart
  7. +48
    -0
      lib/util/pdd_auth/pdd_auth_model.dart
  8. +59
    -0
      lib/util/pdd_auth/pdd_auth_repository.dart
  9. +228
    -92
      lib/util/turn_chain/turn_chain_util.dart
  10. +1
    -0
      pubspec.yaml


+ 4
- 4
lib/pages/login_page/account/login_account_page.dart Dosyayı Görüntüle

@@ -80,14 +80,14 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i
}

/// 跳转到邀请码页面
void _openInvitePage(String mobile) {
void _openInvitePage(String mobile, String captcha) {
print('跳转到邀请码页面');
RouterUtil.hideKeyboard(context);
Navigator.push(
context,
CupertinoPageRoute(
// builder: (_) => PageFactory.create('login_invite', null)
builder: (_) => LoginInvitePage({'mobile': mobile})));
builder: (_) => LoginInvitePage({'mobile': mobile, 'captcha': captcha})));
}

/// 登陆成功页面
@@ -289,11 +289,11 @@ class _LoginAccountPageContianerState extends State<LoginAccountPageContianer> i
Fluttertoast.showToast(msg: '登录成功~');
_isLogging = true;

/// 打开也买
/// 打开登录成功首页
_openLoginSuccessPage();
} else {
/// 打开邀请页面
_openInvitePage(current?.model?.mobile);
_openInvitePage(current?.model?.mobile, current?.model?.captcha);
}
return false;
}


+ 2
- 0
lib/pages/login_page/invite/bloc/login_invite_repository.dart Dosyayı Görüntüle

@@ -51,6 +51,8 @@ class LoginInviteRepository {
params['mobile'] = event.mobile;
params['zone'] = '86';
params['parent_uid'] = event.num;
// 新版本version = 2 需要添加上一步的验证码
// params['version'] = '2';

if(!EmptyUtil.isEmpty(data['captcha'])){
params['captcha'] = data['captcha'];


+ 52
- 0
lib/util/pdd_auth/pdd_auth.dart Dosyayı Görüntüle

@@ -0,0 +1,52 @@
import 'package:flutter/material.dart';
import 'package:zhiying_comm/util/dialog/loading/loading.dart';
import 'package:zhiying_comm/util/pdd_auth/pdd_auth_dialog.dart';
import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:flutter/cupertino.dart';
import 'package:url_launcher/url_launcher.dart';

import 'pdd_auth_model.dart';
import 'pdd_auth_repository.dart';

class PddAuth {
///
/// 进行拼多多授权 (无参数授权,需要请求接口)
/// bool = true 需要授权,bool = false 不需要授权
///
static Future<bool> auth(BuildContext context, {String isShare = '1'}) async {
// 开启loading
Loading.show(context);
PddAuthModel model = await PddAuthRepository().fetchNetData(isShare: isShare);
Loading.dismiss();
if (!EmptyUtil.isEmpty(model)) {
return await PddAuth.authParam(context, model.toJson());
}
return false;
}

///
/// 进行拼多多授权(有参数授权)
///
static Future<bool> authParam(context, Map<String, dynamic> data) async {
try {
if (EmptyUtil.isEmpty(context) || EmptyUtil.isEmpty(data)) return false;
PddAuthModel model = PddAuthModel.fromJson(data);
if (EmptyUtil.isEmpty(model) || EmptyUtil.isEmpty(model.noOpenAppUrl) || EmptyUtil.isEmpty(model.schemaUrl) || (model?.isPop ?? '0') == '0') return false;
bool isConfirm = await showDialog(context: context, builder: (_) => PddAuthDialog());
/// 前往授权
if (isConfirm) {
// 1. 判断是否安装
bool launched = await canLaunch(model.schemaUrl);
if (launched) {
launched = await launch(model.schemaUrl);
}
if (!launched) {
RouterUtil.openWebview(model.noOpenAppUrl, context);
}
}
} catch (e, s) {
Logger.error(e, s);
}
return true;
}
}

+ 86
- 0
lib/util/pdd_auth/pdd_auth_dialog.dart Dosyayı Görüntüle

@@ -0,0 +1,86 @@
import 'package:flutter/material.dart';

class PddAuthDialog extends StatelessWidget {
@override
Widget build(BuildContext context) {
return GestureDetector(
child: Scaffold(
backgroundColor: Colors.transparent,
body: Center(
child: GestureDetector(
child: Container(
padding: EdgeInsets.all(20),
width: 230,
height: 226,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(13),
),
child: Column(
children: <Widget>[
Container(
width: 62,
height: 62,
child: Image.asset(
'assets/images/icon_pdd.png',
package: 'zhiying_comm',
),
),
Padding(
padding: EdgeInsets.only(top: 10, bottom: 4),
child: Text(
'申请拼多多授权',
style: TextStyle(
color: Color(0xff333333),
fontSize: 15,
),
)),
Expanded(
child: Text(
'应平台要求,需要先进行授权\n方可获得更多搜索结果',
textAlign: TextAlign.center,
style: TextStyle(
color: Color(0xff999999),
fontSize: 12,
),
),
),
GestureDetector(
child: Container(
width: 180,
height: 34,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color(0xFFFF6D6D),
Color(0xFFFF2C2C),
],
),
borderRadius: BorderRadius.circular(17),
),
child: Center(
child: Text(
'前往授权',
style: TextStyle(fontSize: 12, color: Colors.white),
),
),
),
onTap: () {
Navigator.pop(context, true);
},
),
],
),
),
onTap: () {},
),
),
),
onTap: () {
Navigator.pop(context);
},
);
}
}

+ 48
- 0
lib/util/pdd_auth/pdd_auth_model.dart Dosyayı Görüntüle

@@ -0,0 +1,48 @@
class PddAuthModel {
String isPop;
String noOpenAppUrl;
String openAppUrl;
String schemaUrl;
String ico;
String btnIco;
String title;
String info;
String btnStr;

PddAuthModel(
{this.isPop,
this.noOpenAppUrl,
this.openAppUrl,
this.schemaUrl,
this.ico,
this.btnIco,
this.title,
this.info,
this.btnStr});

PddAuthModel.fromJson(Map<String, dynamic> json) {
isPop = json['is_pop'];
noOpenAppUrl = json['no_open_app_url'];
openAppUrl = json['open_app_url'];
schemaUrl = json['schema_url'];
ico = json['ico'];
btnIco = json['btn_ico'];
title = json['title'];
info = json['info'];
btnStr = json['btn_str'];
}

Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
data['is_pop'] = this.isPop;
data['no_open_app_url'] = this.noOpenAppUrl;
data['open_app_url'] = this.openAppUrl;
data['schema_url'] = this.schemaUrl;
data['ico'] = this.ico;
data['btn_ico'] = this.btnIco;
data['title'] = this.title;
data['info'] = this.info;
data['btn_str'] = this.btnStr;
return data;
}
}

+ 59
- 0
lib/util/pdd_auth/pdd_auth_repository.dart Dosyayı Görüntüle

@@ -0,0 +1,59 @@

import 'package:flutter/cupertino.dart';
import 'package:zhiying_comm/util/pdd_auth/pdd_auth_model.dart';
import 'package:zhiying_comm/zhiying_comm.dart';

class PddAuthRepository {
///
/// 缓存style Data
/// 多加一个goods_id 用于区分数据
Future<bool> cacheData(String isShare) async {
try {
var result = await NetUtil.post('/api/v1/pdd/check/$isShare',
method: NetMethod.GET,
cache: true,
);
if (NetUtil.isSuccess(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
return true;
}
} catch (e, s) {
Logger.error(e, s);
}
return false;
}

///
/// 获取网络数据
///
Future<PddAuthModel> fetchNetData({@required String isShare}) async{
try {
var result = await NetUtil.post('/api/v1/pdd/check/$isShare', method: NetMethod.GET);
if (!EmptyUtil.isEmpty(result) && !EmptyUtil.isEmpty(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA])) {
PddAuthModel model = PddAuthModel.fromJson(result[GlobalConfig.HTTP_RESPONSE_KEY_DATA]);
return model;
}
} catch (e, s) {
Logger.error(e, s);
}
return null;
}

///
/// 获取缓存的data
/// 多加一个goods_id 用于区分数据
///
Future<PddAuthModel> fetchCacheData(String isShare) async {
try {
var result = await NetUtil.getRequestCachedData('/api/v1/pdd/check/$isShare');
if (!EmptyUtil.isEmpty(result)) {
PddAuthModel model = PddAuthModel.fromJson(result);
if (!EmptyUtil.isEmpty(model)) {
return model;
}
}
} catch (e, s) {
Logger.error(e, s);
}
return null;
}
}

+ 228
- 92
lib/util/turn_chain/turn_chain_util.dart Dosyayı Görüntüle

@@ -12,6 +12,7 @@ import 'package:zhiying_comm/util/empty_util.dart';
import 'package:zhiying_comm/util/global_config.dart';
import 'package:zhiying_comm/util/log/let_log.dart';
import 'package:zhiying_comm/util/net_util.dart';
import 'package:zhiying_comm/util/pdd_auth/pdd_auth.dart';
import 'package:zhiying_comm/util/taobao/taobao_auth.dart';
import 'package:zhiying_comm/util/turn_chain/turn_chain_dialog_repository.dart';
import 'package:zhiying_comm/util/turn_chain/turn_chain_style_model.dart';
@@ -56,8 +57,8 @@ class TurnChainUtil {
/// 名片全能王: camcard://
///
static Future<void> openReceiveCoupon(BuildContext context, UserInfoModel userInfoModel, String goodsId, String provider, Map<String, dynamic> data, {bool isFree = false}) async {
///iOS 审核状态
String is_ios_review = await SharedPreferencesUtil.getStringValue(GlobalConfig.IS_IOS_REVIEW, defaultVal: '0');
/// iOS 审核状态
// String is_ios_review = await SharedPreferencesUtil.getStringValue(GlobalConfig.IS_IOS_REVIEW, defaultVal: '0');

/// 1、先判断是否登陆
if (EmptyUtil.isEmpty(userInfoModel) || EmptyUtil.isEmpty(userInfoModel?.token)) {
@@ -78,111 +79,239 @@ class TurnChainUtil {
String appUrl = result['app_url'];
String webUrl = result['no_open_app_url'];

/// 4、根据渠道进行不同的跳转
switch (provider) {
case GlobalConfig.PROVIDER_TB:
case GlobalConfig.PROVIDER_TM:
if (!EmptyUtil.isEmpty(openAppUrl)) {
TradeResult tradeResult;
if (Platform.isAndroid) {
// print("跳转链接"+openAppUrl);
tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl, backUrl: "alisdk://");
} else if (Platform.isIOS) {
if (is_ios_review == '1') {
print('iOS审核:' + is_ios_review);
RouterUtil.openWebview(webUrl, context);
} else {
tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl);
}
}
Logger.debug('taobao result = ${tradeResult.errorCode} ${tradeResult.errorMessage} ');
} else if (!EmptyUtil.isEmpty(webUrl)) {
RouterUtil.openWebview(webUrl, context);
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}
bool jumpResult = await jumpNative(context, provider: provider, openAppUrl: openAppUrl, appUrl: appUrl, webUrl: webUrl);
if (!jumpResult) {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}

break;
case GlobalConfig.PROVIDER_JD:
String tempURLScheme1 = 'openapp.jdmobile://virtual?params=%';
String tempURLScheme2 = 'openapp.jdmobile://';
if (!EmptyUtil.isEmpty(openAppUrl) && await canLaunch(tempURLScheme1) || await canLaunch(tempURLScheme2)) {
Jdsdk.openUrl(url: openAppUrl);
} else if (!EmptyUtil.isEmpty(webUrl)) {
RouterUtil.openWebview(webUrl, context);
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}
break;
case GlobalConfig.PROVIDER_KL:
case GlobalConfig.PROVIDER_PDD:
case GlobalConfig.PROVIDER_SN:
bool launchable = await canLaunch(appUrl);
if (Platform.isIOS) {
launchable = await launch(appUrl);
// /// 4、根据渠道进行不同的跳转
// switch (provider) {
// case GlobalConfig.PROVIDER_TB:
// case GlobalConfig.PROVIDER_TM:
// if (!EmptyUtil.isEmpty(openAppUrl)) {
// TradeResult tradeResult;
// if (Platform.isAndroid) {
// // print("跳转链接"+openAppUrl);
// tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl, backUrl: "alisdk://");
// } else if (Platform.isIOS) {
// if (is_ios_review == '1') {
// print('iOS审核:' + is_ios_review);
// RouterUtil.openWebview(webUrl, context);
// } else {
// tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl);
// }
// }
// Logger.debug('taobao result = ${tradeResult.errorCode} ${tradeResult.errorMessage} ');
// } else if (!EmptyUtil.isEmpty(webUrl)) {
// RouterUtil.openWebview(webUrl, context);
// } else {
// Fluttertoast.cancel();
// Fluttertoast.showToast(msg: '购买链接不存在');
// }
//
// break;
// case GlobalConfig.PROVIDER_JD:
// String tempURLScheme1 = 'openapp.jdmobile://virtual?params=%';
// String tempURLScheme2 = 'openapp.jdmobile://';
// if (!EmptyUtil.isEmpty(openAppUrl) && await canLaunch(tempURLScheme1) || await canLaunch(tempURLScheme2)) {
// Jdsdk.openUrl(url: openAppUrl);
// } else if (!EmptyUtil.isEmpty(webUrl)) {
// RouterUtil.openWebview(webUrl, context);
// } else {
// Fluttertoast.cancel();
// Fluttertoast.showToast(msg: '购买链接不存在');
// }
// break;
// case GlobalConfig.PROVIDER_KL:
// case GlobalConfig.PROVIDER_PDD:
// case GlobalConfig.PROVIDER_SN:
// bool launchable = await canLaunch(appUrl);
// if (Platform.isIOS) {
// launchable = await launch(appUrl);
// }
// if (launchable) {
// if (!Platform.isIOS) {
// if (appUrl.startsWith("suning")) {
// RouterUtil.openWebview(webUrl, context);
// } else {
// RouterUtil.openWebview(webUrl, context);
// }
// }
// } else if (!EmptyUtil.isEmpty(webUrl)) {
// Logger.log('打开${provider} webUrl, url = ${webUrl}');
// RouterUtil.openWebview(webUrl, context);
// } else {
// Fluttertoast.cancel();
// Fluttertoast.showToast(msg: '购买链接不存在');
// }
// break;
// case GlobalConfig.PROVIDER_VIP:
// bool launchable = await canLaunch(appUrl);
// if (Platform.isIOS) {
// launchable = await launch(appUrl);
// }
// if (launchable) {
// if (!Platform.isIOS) {
// await launch(appUrl);
// }
// } else if (!EmptyUtil.isEmpty(webUrl)) {
// Logger.log('打开${provider} webUrl, url = ${webUrl}');
// RouterUtil.openWebview(webUrl, context);
// } else {
// Fluttertoast.cancel();
// Fluttertoast.showToast(msg: '购买链接不存在');
// }
// break;
// default:
// if (!EmptyUtil.isEmpty(openAppUrl)) {
// bool launchable = await canLaunch(appUrl);
// if (launchable) {
// launchable = await launch(appUrl);
// }
// if (launchable) {
// if (!Platform.isIOS) {
// RouterUtil.openWebview(webUrl, context);
// }
// } else if (!EmptyUtil.isEmpty(webUrl)) {
// Logger.log('打开${provider} webUrl, url = ${webUrl}');
// RouterUtil.openWebview(webUrl, context);
// } else {
// Fluttertoast.cancel();
// Fluttertoast.showToast(msg: '购买链接不存在');
// }
// } else {
// Fluttertoast.cancel();
// Fluttertoast.showToast(msg: '购买链接不存在');
// }
// break;
// }
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}
}

///
/// 跳转原生或者webView打开购买链接
///
/// provider: 商品渠道
/// openAppUrl: 打开商品链接
/// appUrl: 打开商品链接,不是Http开头,类似 taobao://, opennapp.jdxxx://
/// webUrl: 打开商品WebView链接
///
static Future<bool> jumpNative(BuildContext context, {String provider = GlobalConfig.PROVIDER_TB, String openAppUrl, String appUrl, String webUrl}) async {
bool rlt = false;
///iOS 审核状态
String isIosReview = await SharedPreferencesUtil.getStringValue(GlobalConfig.IS_IOS_REVIEW, defaultVal: '0');

/// 4、根据渠道进行不同的跳转
switch (provider) {
case GlobalConfig.PROVIDER_TB:
case GlobalConfig.PROVIDER_TM:
if (!EmptyUtil.isEmpty(openAppUrl)) {
TradeResult tradeResult;
if (Platform.isAndroid) {
tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl, backUrl: "alisdk://");
rlt = true;
} else if (Platform.isIOS) {
if (isIosReview == '1') {
print('iOS审核:' + isIosReview);
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
tradeResult = await FlutterAlibc.openByUrl(url: openAppUrl);
rlt = true;
}
}
if (launchable) {
if (!Platform.isIOS) {
if (appUrl.startsWith("suning")) {
RouterUtil.openWebview(webUrl, context);
} else {
RouterUtil.openWebview(webUrl, context);
}
Logger.debug('taobao result = ${tradeResult.errorCode} ${tradeResult.errorMessage} ');
} else if (!EmptyUtil.isEmpty(webUrl)) {
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
rlt = false;
}
break;
case GlobalConfig.PROVIDER_JD:
String tempURLScheme1 = 'openapp.jdmobile://virtual?params=%';
String tempURLScheme2 = 'openapp.jdmobile://';
if (!EmptyUtil.isEmpty(openAppUrl) && await canLaunch(tempURLScheme1) || await canLaunch(tempURLScheme2)) {
Jdsdk.openUrl(url: openAppUrl);
rlt = true;
} else if (!EmptyUtil.isEmpty(webUrl)) {
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
rlt = false;
}
break;
case GlobalConfig.PROVIDER_KL:
case GlobalConfig.PROVIDER_PDD:
case GlobalConfig.PROVIDER_SN:
bool launchable = await canLaunch(appUrl);
if (Platform.isIOS) {
launchable = await launch(appUrl);
}
if (launchable) {
if (!Platform.isIOS) {
if (appUrl.startsWith("suning")) {
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
RouterUtil.openWebview(webUrl, context);
rlt = true;
}
} else if (!EmptyUtil.isEmpty(webUrl)) {
Logger.log('打开${provider} webUrl, url = ${webUrl}');
RouterUtil.openWebview(webUrl, context);
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}
break;
case GlobalConfig.PROVIDER_VIP:
} else if (!EmptyUtil.isEmpty(webUrl)) {
Logger.log('打开${provider} webUrl, url = ${webUrl}');
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
rlt = false;
}
break;
case GlobalConfig.PROVIDER_VIP:
bool launchable = await canLaunch(appUrl);
if (Platform.isIOS) {
launchable = await launch(appUrl);
}
if (launchable) {
if (!Platform.isIOS) {
await launch(appUrl);
rlt = true;
}
} else if (!EmptyUtil.isEmpty(webUrl)) {
Logger.log('打开${provider} webUrl, url = ${webUrl}');
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
rlt = false;
}
break;
default:
if (!EmptyUtil.isEmpty(openAppUrl)) {
bool launchable = await canLaunch(appUrl);
if (Platform.isIOS) {
if (launchable) {
launchable = await launch(appUrl);
}
if (launchable) {
if (!Platform.isIOS) {
await launch(appUrl);
RouterUtil.openWebview(webUrl, context);
rlt = true;
}
} else if (!EmptyUtil.isEmpty(webUrl)) {
Logger.log('打开${provider} webUrl, url = ${webUrl}');
RouterUtil.openWebview(webUrl, context);
rlt = true;
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}
break;
default:
if (!EmptyUtil.isEmpty(openAppUrl)) {
bool launchable = await canLaunch(appUrl);
if (launchable) {
launchable = await launch(appUrl);
}
if (launchable) {
if (!Platform.isIOS) {
RouterUtil.openWebview(webUrl, context);
}
} else if (!EmptyUtil.isEmpty(webUrl)) {
Logger.log('打开${provider} webUrl, url = ${webUrl}');
RouterUtil.openWebview(webUrl, context);
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
}
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
rlt = false;
}
break;
}
} else {
Fluttertoast.cancel();
Fluttertoast.showToast(msg: '购买链接不存在');
} else {
rlt = false;
}
break;
}
return Future.value(rlt);
}

///
@@ -203,11 +332,18 @@ class TurnChainUtil {
}

/// 2、如果是淘宝,判断是否授权
if (provider == GlobalConfig.PROVIDER_TB && !userInfoModel.isTBAuth) {
if (provider == GlobalConfig.PROVIDER_TB || provider == GlobalConfig.PROVIDER_TM && !userInfoModel.isTBAuth) {
TaobaoAuth.auth(context);
return null;
}

/// 2.5 如果是拼多多,判断是否需要授权
if(provider == GlobalConfig.PROVIDER_PDD) {
// 如果为true,说明需要进行授权,停止执行。
bool result = await PddAuth.auth(context);
if (result) return null;
}

/// 3、获取转链的结果
Map<String, dynamic> result = await getTurnChainResult(context, goodsId, provider, data, isShare: true);
if (!EmptyUtil.isEmpty(result) && !EmptyUtil.isEmpty(result['open_app_url'])) {


+ 1
- 0
pubspec.yaml Dosyayı Görüntüle

@@ -129,6 +129,7 @@ flutter:
# To add assets to your plugin package, add an assets section, like this:
assets:
- assets/images/icon_taobao.png
- assets/images/icon_pdd.png

#
# For details regarding assets in packages, see


Yükleniyor…
İptal
Kaydet