|
|
@@ -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'])) { |
|
|
|