|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757 |
- //
- // FlutterAlibcHandle.m
- // flutter_alibc
- //
- // Created by 吴兴 on 2019/8/28.
- //
-
- #import "FlutterAlibcHandle.h"
- #import "FlutterAlibcTools.h"
- #import "FlutterAlibcConstKey.h"
- //#import <AlibcTradeSDK/AlibcTradeSDK.h>
- //#import <AlibabaAuthSDK/albbsdk.h>
- #import "ALiTradeWebViewController.h"
- #import "FlutterWxViewCtrlViewController.h"
- //#import <AlibabaAuthEntrance/ALBBSDK.h>
- //#import <AlibabaAuthEntrance/ALBBCompatibleSession.h>
- #import "UTDID/UTDevice.h"
-
-
- //旗舰版
-
-
- #import <AlibcTradeUltimateSDK/AlibcTradeUltimateSDK.h>
- //// 媒体电商套件图片库协议实现
- //#import "ALITradeDemoImageLoader.h"
- //#import <WindmillWeaver/WMLHandlerFactory.h>
- //// 电商套件外跳媒体页面实现
- //
- //#import <AlibcTradeContainer/AlibcTradeMiniAppURLRouter.h>
- //
- //#import <AlibcTradeUltimateBizSDK/AlibcTradeShowParams.h>
- //#import <AlibcTradeUltimateSDK/AlibcTradeUltimateSDKService.h>
- //#import <AlibcTradeUltimateBizSDK/AlibcTradeUrlParams.h>
- //
- //
- //#import <AlibcTradeUltimateBizSDK/AlibcTradeTaokeParams.h>
-
- #import <AlibcTradeContainer/AlibcTradeContainer.h>
- #import <WindmillWeaver/WMLImageLoaderProtocol.h>
- #import <WindmillWeaver/WMLHandlerFactory.h>
- #import <WindmillWeaver/TRVZipArchiveProtocol.h>
- #import <WindmillWeaver/WMLHandlerFactory.h>
- #import <WindmillWeaver/TRVZipArchiveProtocol.h>
- #import "FNALITradeZipArchiver.h"
-
-
- @interface FlutterAlibcHandle ()
- //// 图片库实现
- //@property (nonatomic,strong)ALITradeDemoImageLoader *imageLoaderImp;
- //
- //// 外跳路由协议实现
- //@property (nonatomic,strong)ALiTradeDemoURLHandler *urlHandlerImp;
-
- @end
-
- @implementation FlutterAlibcHandle
- FlutterMethodChannel *_flutterAlibcChannel = nil;
-
-
- - (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel {
- self = [super init];
- if (self) {
- _flutterAlibcChannel = flutterMethodChannel;
- }
- return self;
- }
-
- #pragma mark- 对flutter暴露的方法
- #pragma mark -- 初始化阿里百川
- - (void)initAlibc:(FlutterMethodCall *)call result:(FlutterResult)result {
- // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
- NSString *version = call.arguments[@"version"];
- NSString *appName = call.arguments[@"appName"];
- // 判断是否为空
- // if(![FlutterAlibcTools isNil:version]){
- // [[AlibcTradeSDK sharedInstance] setIsvVersion:version]; //设置三方App版本,可用于标识App版本
- // }
- // if(![FlutterAlibcTools isNil:appName]){
- // [[AlibcTradeSDK sharedInstance] setIsvAppName:appName]; //设置三方App名称,可用于标识App
- // }
- // [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];//开发阶段打开日志开关,方便排查错误信息
- // [[AlibcTradeSDK sharedInstance] setEnv:AlibcEnvironmentRelease];//线上环境
- //
- //
- // [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
- // // 告诉flutter,初始化完成
- // result(@{FlutterAlibcConstKey_ErrorCode:@"0",FlutterAlibcConstKey_ErrorMessage:@"success"});
- // } failure:^(NSError *error) {
- // NSLog(@"Init failed: %@", error.description);
- // result(@{FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],FlutterAlibcConstKey_ErrorMessage:error.description});
- // }];
-
- __weak typeof(self) weakSelf = self;
- // // 打开日志开关
- [[AlibcTradeUltimateSDK sharedInstance] setDebugLogOpen:YES];
- [[AlibcTradeUltimateSDK sharedInstance] asyncInitWithSuccess:^{
- NSLog(@"百川初始化成功");
- __strong typeof(self) self = weakSelf;
-
- [[AlibcTradeUltimateSDK sharedInstance] setDebugLogOpen:YES];
- [[AlibcTradeMiniAppURLRouter sharedInstance] addMiniAppRouterListener:self];
- [WMLHandlerFactory registerHandler:self withProtocol:@protocol(WMLImageLoaderProtocol)];
- [WMLHandlerFactory registerHandler:[FNALITradeZipArchiver new] withProtocol:@protocol(TRVZipArchiveProtocol)];
-
- #ifdef DEBUG
- //必须在百川初始化成功之后调用,开启自检工具的悬浮入口
- [[AlibcTradeUltimateSDK sharedInstance] enableAutoShowDebug:YES];
- [[AlibcTradeUltimateSDK sharedInstance] setDebugLogOpen:YES];
- #endif
-
- } failure:^(NSError * _Nonnull error) {
- NSLog(@"百川初始化失败");
- }];
-
-
- }
- #pragma mark --淘宝登录
- - (void)loginTaoBao:(FlutterMethodCall *)call result:(FlutterResult)result{
- // if(![[ALBBCompatibleSession sharedInstance] isLogin]) {
- // UIViewController *rootViewController =
- // [UIApplication sharedApplication].delegate.window.rootViewController;
- // [[ALBBSDK sharedInstance] setH5Only:NO];
- // [[ALBBSDK sharedInstance] auth:rootViewController successCallback:^{
- // ALBBUser *userInfo =[[ALBBCompatibleSession sharedInstance] getUser];
- // // 登录成功
- // result(@{
- // FlutterAlibcConstKey_ErrorCode:@"0",
- // FlutterAlibcConstKey_ErrorMessage:@"success",
- // FlutterAlibcConstKey_Data:@{
- // // 昵称
- // @"nick":userInfo.nick,
- // // 头像地址
- // @"avatarUrl":userInfo.avatarUrl,
- // @"openId":userInfo.openId,
- // @"openSid":userInfo.openSid,
- // @"topAccessToken":userInfo.topAccessToken,
- // @"topAuthCode":userInfo.topAuthCode,
- // }
- // });
- // } failureCallback:^(NSError *error) {
- // // 登录失败
- // result(@{
- // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- // FlutterAlibcConstKey_ErrorMessage:error.localizedDescription,
- // FlutterAlibcConstKey_Data:@{}
- // });
- // }];
- //
- // } else {
- // ALBBUser *userInfo =[[ALBBCompatibleSession sharedInstance] getUser];
- // // 登录成功
- // result(@{
- // FlutterAlibcConstKey_ErrorCode:@"0",
- // FlutterAlibcConstKey_ErrorMessage:@"success",
- // FlutterAlibcConstKey_Data:@{
- // // 昵称
- // @"nick":userInfo.nick,
- // // 头像地址
- // @"avatarUrl":userInfo.avatarUrl,
- // @"openId":userInfo.openId,
- // @"openSid":userInfo.openSid,
- // @"topAccessToken":userInfo.topAccessToken,
- // @"topAuthCode":userInfo.topAuthCode,
- // }
- // });
- // }
-
-
- NSLog(@"授权登录信息==%@",call.arguments);
- if (![[[AlibcTradeUltimateSDK sharedInstance] loginService] isLogin]) {
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
- [[[AlibcTradeUltimateSDK sharedInstance] loginService] setH5Only:NO];
- [[[AlibcTradeUltimateSDK sharedInstance] loginService] auth:rootViewController success:^(AlibcUser *user) {
- NSLog(@"登录成功");
- result(@{FlutterAlibcConstKey_ErrorCode:@"0",
- FlutterAlibcConstKey_ErrorMessage:@"success",
- FlutterAlibcConstKey_Data:@{
- // 昵称
- @"nick":user.nick,
- // 头像地址
- @"avatarUrl":user.avatarUrl,
- @"openId":user.openId,
- @"openSid":user.openSid,
- @"topAccessToken":@"",
- @"topAuthCode":@"",
- }
- });
- //无 topAccessToken topAuthCode
- } failure:^(NSError *error) {
- NSLog(@"登录失败");
- result(@{
- FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- FlutterAlibcConstKey_ErrorMessage:error.localizedDescription,
- FlutterAlibcConstKey_Data:@{}
- });
- }];
- } else {
- AlibcUser *user = [[[AlibcTradeUltimateSDK sharedInstance] loginService] getUser];
- NSLog(@"已登录");
- result(@{
- FlutterAlibcConstKey_ErrorCode:@"0",
- FlutterAlibcConstKey_ErrorMessage:@"success",
- FlutterAlibcConstKey_Data:@{
- @"nick":user.nick,
- @"avatarUrl":user.avatarUrl,
- @"openId":user.openId,
- @"openSid":user.openSid,
- @"topAccessToken":@"",
- @"topAuthCode":@"",
- }
- });
- }
- }
- //
- //else if([@"useAlipayNative" isEqualToString:call.method]){
- // [_handler useAlipayNative:call result:result];
- //}
- #pragma mark --淘客登录
- -(void)taoKeLogin:(FlutterMethodCall *)call result:(FlutterResult)result{
- // 需要获取的数据
- // NSNumber *type1 = call.arguments[@"openType"];
- // AlibcOpenType openType = [self openType:[type1 intValue]];
- // BOOL isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] boolValue];
- // // 不用push了,没有nav,默认都present
- // // BOOL isNeedPush = [call.arguments[@"isNeedPush"] boolValue];
- // BOOL isNeedPush = YES;
- // NSNumber *failMode = call.arguments[@"nativeFailMode"];
- // AlibcNativeFailMode nativeFailMode = [self NativeFailMode:[failMode intValue]];
- // NSNumber *schemeType = call.arguments[@"schemeType"];
- // NSString *linkKey = [self schemeType:[schemeType intValue]];
- // NSString *url = call.arguments[@"url"];
- // AlibcTradeTaokeParams *taokeParam = [self getTaokeParams:call];
- // NSDictionary *trackParam = call.arguments[@"trackParam"];
- // NSString *backUrl = [FlutterAlibcTools changeType:call.arguments[@"backUrl"]];
- // // NSString *backUrl = [FlutterAlibcTools nullToNil:call.arguments[@"backUrl"]];
- //
- // UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
- //
- //
- // AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
- // showParam.openType = openType;
- // showParam.isNeedCustomNativeFailMode = isNeedCustomNativeFailMode;
- // showParam.isNeedPush=isNeedPush;
- // showParam.nativeFailMode=nativeFailMode;
- // showParam.linkKey=linkKey;
- // showParam.backUrl= backUrl;
- //
- // ALiTradeWebViewController* webviewVC = [[ALiTradeWebViewController alloc] init];
- //
- // NSInteger res = [[AlibcTradeSDK sharedInstance].tradeService
- // openByUrl:url
- // identity:@"trade"
- // webView:webviewVC.webView
- // parentController:rootViewController
- // showParams:showParam
- // taoKeParams:taokeParam
- // trackParam:trackParam tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable alibcTradeResult) {
- // // // 交易成功,判断是付款成功还是加入购物车
- // // if(alibcTradeResult.result == AlibcTradeResultTypePaySuccess){
- // // // 付款成功
- // // result(@{
- // // FlutterAlibcConstKey_ErrorCode:@"0",
- // // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
- // // FlutterAlibcConstKey_Data:@{
- // // @"type":@0,
- // // @"paySuccessOrders":[alibcTradeResult payResult].paySuccessOrders,
- // // @"payFailedOrders":[alibcTradeResult payResult].payFailedOrders,
- // // }
- // // });
- // // }else if(alibcTradeResult.result== AlibcTradeResultTypeAddCard){
- // // // 加入购物车
- // // result(@{
- // // FlutterAlibcConstKey_ErrorCode:@"0",
- // // FlutterAlibcConstKey_ErrorMessage:@"加入购物车成功",
- // // FlutterAlibcConstKey_Data:@{
- // // @"type":@1,
- // // }
- // // });
- // // }
- // } tradeProcessFailedCallback:^(NSError * _Nullable error) {
- // // result(@{
- // // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- // // FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
- // // });
- // }];
- //
- // if (res == 1) {
- // // 新建一个view
- // FlutterWxViewCtrlViewController *WxVC = [[FlutterWxViewCtrlViewController alloc] init];
- // WxVC.vc = webviewVC;
- // WxVC.accessBlock = ^(NSString * accessToken){
- // NSLog(@"accessToken = %@",accessToken);
- // if (accessToken) {
- // result(@{
- // @"accessToken":accessToken
- // });
- // }else{
- // result(@{
- // @"accessToken":@""
- // });
- // }
- //
- // };
- // UINavigationController *root = [[UINavigationController alloc] initWithRootViewController:WxVC];
- // [rootViewController presentViewController:root animated:NO completion:^{
- //
- // }];
- // }
-
- NSLog(@"淘客登录信息==%@",call.arguments);
-
-
-
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
-
- // [[AlibcTradeUltimateSDK sharedInstance] showLocalDebugTool:rootViewController];
-
-
-
-
-
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
- NSString *app_NameXT = [infoDictionary objectForKey:@"CFBundleName"];
-
- NSString *appLogo=@"app_icon";
- // [[AlibcTradeUltimateSDK sharedInstance].tradeService authorize4AppName:app_NameXT appLogo:[UIImage imageNamed:appLogo] currentVC:rootViewController callBack:^(NSError *error, NSString *accessToken, NSString *expire) {
- // NSLog(@"淘客登录accessToken==%@",accessToken);
- // NSLog(@"淘客登录expire==%@",expire);
- // NSLog(@"淘客登录error==%@",error);
- // NSLog(@"accessToken = %@",accessToken);
- // if (accessToken) {
- // result(@{
- // @"accessToken":accessToken
- // });
- // }else{
- // result(@{
- // @"accessToken":@""
- // });
- // }
- // }];
- //32271226
- NSString *AppKey=call.arguments[@"alibcAppKey"];
- NSString *appName = call.arguments[@"name"];
-
- [[AlibcTradeUltimateSDK sharedInstance].tradeService authorize4AppKey:AppKey appName:app_NameXT appLogo:[UIImage imageNamed:appLogo] currentVC:rootViewController callBack:^(NSError *error, NSString *accessToken, NSString *expire) {
- NSLog(@"淘客登录accessToken==%@",accessToken);
- NSLog(@"淘客登录expire==%@",expire);
- NSLog(@"淘客登录error==%@",error);
- NSLog(@"accessToken = %@",accessToken);
- if (accessToken) {
- result(@{
- @"accessToken":accessToken
- });
- }else{
- result(@{
- @"accessToken":@""
- });
- }
- }];
-
- }
- #pragma mark --退出登录
- - (void)loginOut{
- //[[ALBBSDK sharedInstance] logout];
- [[[AlibcTradeUltimateSDK sharedInstance] loginService] logout];
- }
- #pragma mark --通过url打开,包括h5,唤起手淘等
- - (void)openByUrl:(FlutterMethodCall *)call result:(FlutterResult)result{
- NSLog(@"h5MSG==%@",call.arguments);
- NSNumber *schemeType = call.arguments[@"schemeType"];
- NSString *linkKey = [self schemeType:[schemeType intValue]];
- NSString *url = call.arguments[@"url"];
- NSInteger isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] integerValue];
- //ALiTradeWebViewController* webviewVC = [[ALiTradeWebViewController alloc] init];
-
- AlibcTradeShowParams *showParams = [[AlibcTradeShowParams alloc] init];
- showParams.failMode = isNeedCustomNativeFailMode;//isNeedCustomNativeFailMode;//自定义唤端失败策略 0 打开下载页面 1自定义降级页打开 2不处理
- //AlibcOpenAliAppDownloadPage = 0,
- //AlibcOpenInAppByCustomerDegradeUrl = 1,
- //AlibcOpenDoNothing = 2
- showParams.isNeedOpenByAliApp = YES;
- showParams.isPushBCWebView = YES;
- showParams.linkKey = linkKey;
- //showParams.degradeUrl = url;//媒体自定义降级url
-
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
- //AlibcTradeTaokeParams *taokeParam = [self getTaokeParams:call];
- AlibcTradeTaokeParams *taokeParam = [AlibcTradeTaokeParams new];
- taokeParam.pid = [call.arguments valueForKey:@"pid"];
- taokeParam.unionId = [call.arguments valueForKey:@"unionId"];
- taokeParam.subPid = [call.arguments valueForKey:@"subPid"];
- taokeParam.relationId = [call.arguments valueForKey:@"relationId"];
- taokeParam.materialSourceUrl = [call.arguments valueForKey:@"materialSourceUrl"];
- taokeParam.extParams = [call.arguments valueForKey:@"extParams"];
- NSDictionary *trackParam = [call.arguments valueForKey:@"trackParam"];
-
- [[AlibcTradeUltimateSDK sharedInstance].tradeService openTradeUrl:url
- parentController:rootViewController
- showParams:showParams
- taoKeParams:taokeParam
- trackParam:trackParam
- openUrlCallBack:^(NSError *error, NSDictionary *dict) {
-
- NSLog(@"error==%@",error);
- NSLog(@"dict==%@",dict);
- if(error){
- result(@{
- FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
-
- });
- }else{
-
- }
-
- }];
-
-
-
- }
- #pragma mark --打开商品详情
- - (void)openItemDetail:(FlutterMethodCall *)call result:(FlutterResult)result{
- NSString *itemID = call.arguments[@"itemID"];
- NSLog(@"打开商品详情==%@",call.arguments);
- //id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage:itemID];
- //[self OpenPageByNewWay:page BizCode:@"detail" Call:call callback:result];
- [self OpenPageByNewWayNorpageBizCode:@"detail" Call:call callback:result];
- }
- #pragma mark --打开店铺
- - (void)openShop:(FlutterMethodCall *)call result:(FlutterResult)result{
- NSString *shopId = call.arguments[@"shopId"];
- NSLog(@"打开店铺==%@",call.arguments);
- //id<AlibcTradePage> page = [AlibcTradePageFactory shopPage:shopId];
- //[self OpenPageByNewWay:page BizCode:@"shop" Call:call callback:result];
- [self OpenPageByNewWayNorpageBizCode:@"shop" Call:call callback:result];
- }
- #pragma mark --打开我的购物车
- - (void)openCart:(FlutterMethodCall *)call result:(FlutterResult)result{
- NSLog(@"打开我的购物车==%@",call.arguments);
- //id<AlibcTradePage> page = [AlibcTradePageFactory myCartsPage];
- //[self OpenPageByNewWay:page BizCode:@"cart" Call:call callback:result];
- [self OpenPageByNewWayNorpageBizCode:@"cart" Call:call callback:result];
- }
- //
- #pragma mark --淘客打点
- - (void)syncForTaoke:(FlutterMethodCall *)call result:(FlutterResult)result{
- BOOL isSync = [call.arguments[@"isSync"] boolValue];
- //[[AlibcTradeSDK sharedInstance] setIsSyncForTaoke:isSync];
- }
- #pragma mark --设置是否需要 Native AliPay 接口
- - (void)useAlipayNative:(FlutterMethodCall *)call result:(FlutterResult)result{
- BOOL isNeed = [call.arguments[@"isNeed"] boolValue];
- //[[AlibcTradeSDK sharedInstance] setShouldUseAlizfNative:isNeed];
- }
-
- //获取udid
- - (void)getUdid:(FlutterMethodCall *)call result:(FlutterResult)result{
- NSUUID *identifierForVendor = [[UIDevice currentDevice] identifierForVendor];
- NSDictionary* map=@{@"udid" : [UTDevice utdid]};
- result(map);
- }
-
- #pragma mark - 不对flutter暴露
- #pragma mark --打开page
- //- (void)OpenPageByNewWay:(id<AlibcTradePage>)page BizCode:(NSString *)bizCode Call:(FlutterMethodCall *)call callback:(FlutterResult)callback{
- // AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
- // NSNumber *type1 = call.arguments[@"openType"];
- // AlibcOpenType openType = [self openType:[type1 intValue]];
- // BOOL isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] boolValue];
- // // 不用push了,没有nav,默认都present
- // // BOOL isNeedPush = [call.arguments[@"isNeedPush"] boolValue];
- // BOOL isNeedPush = NO;
- // // 不用绑定了,默认为没有,有的话flutter太难搞了
- // // BOOL isBindWebview = [call.arguments[@"isBindWebview"] boolValue];
- // NSNumber *failMode = call.arguments[@"nativeFailMode"];
- // AlibcNativeFailMode nativeFailMode = [self NativeFailMode:[failMode intValue]];
- // NSNumber *schemeType = call.arguments[@"schemeType"];
- // NSString *linkKey = [self schemeType:[schemeType intValue]];
- // AlibcTradeTaokeParams *taokeParam = [self getTaokeParams:call];
- // NSDictionary *trackParam = [FlutterAlibcTools nullToNil:call.arguments[@"trackParam"]];
- //
- // NSString *backUrl = [FlutterAlibcTools changeType:call.arguments[@"backUrl"]];
- // // 判断
- //
- // UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
- //
- // showParam.openType = openType;
- // showParam.isNeedPush = isNeedPush;
- // showParam.nativeFailMode = nativeFailMode;
- // showParam.isNeedCustomNativeFailMode = isNeedCustomNativeFailMode;
- // showParam.linkKey = linkKey;
- // showParam.backUrl = backUrl;
- //
- //
- // // if (isBindWebview) {
- // // ALiTradeWebViewController *viewCtrl = [[ALiTradeWebViewController alloc]init];
- // // NSInteger res = [[AlibcTradeSDK sharedInstance].tradeService openByBizCode:bizCode page:page webView:view.webView parentController:view showParams:showParam taoKeParams:[self taokeParam] trackParam:[self customParam] tradeProcessSuccessCallback:self.onTradeSuccess tradeProcessFaelseiledCallback:self.onTradeFailure];
- // // }else{
- // // if (isNeedPush) {
- // // [[AlibcTradeSDK sharedInstance].tradeService openByBizCode:bizCode page:page webView:nil parentController:rootViewController showParams:showParam taoKeParams:taokeParam trackParam:trackParam tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
- // //// 交易成功,判断是付款成功还是加入购物车
- // // if(result.result == AlibcTradeResultTypePaySuccess){
- // //// 付款成功
- // // callback(@{
- // // FlutterAlibcConstKey_ErrorCode:@"0",
- // // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
- // // FlutterAlibcConstKey_Data:@{
- // // @"type":@0,
- // // @"paySuccessOrders":[result payResult].paySuccessOrders,
- // // @"payFailedOrders":[result payResult].payFailedOrders,
- // // }
- // // });
- // // }else if(result.result== AlibcTradeResultTypeAddCard){
- // //// 加入购物车
- // // callback(@{
- // // FlutterAlibcConstKey_ErrorCode:@"0",
- // // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
- // // FlutterAlibcConstKey_Data:@{
- // // @"type":@1,
- // // }
- // // });
- // // }
- // // } tradeProcessFailedCallback:^(NSError * _Nullable error) {
- // //// 退出交易流程
- // // callback(@{
- // // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- // // FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
- // // FlutterAlibcConstKey_Data:@{
- // // @"orderIdList":[[error userInfo] objectForKey:@"orderIdList"],
- // // }
- // // });
- // // }];
- // // }else{
- // [[AlibcTradeSDK sharedInstance].tradeService openByBizCode:bizCode page:page webView:nil parentController:rootViewController showParams:showParam taoKeParams:taokeParam trackParam:trackParam tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
- // // 交易成功,判断是付款成功还是加入购物车
- // if(result.result == AlibcTradeResultTypePaySuccess){
- // // 付款成功
- // callback(@{
- // FlutterAlibcConstKey_ErrorCode:@"0",
- // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
- // FlutterAlibcConstKey_Data:@{
- // @"type":@0,
- // @"paySuccessOrders":[result payResult].paySuccessOrders,
- // @"payFailedOrders":[result payResult].payFailedOrders,
- // }
- // });
- // }else if(result.result== AlibcTradeResultTypeAddCard){
- // // 加入购物车
- // callback(@{
- // FlutterAlibcConstKey_ErrorCode:@"0",
- // FlutterAlibcConstKey_ErrorMessage:@"加入购物车成功",
- // FlutterAlibcConstKey_Data:@{
- // @"type":@1,
- // }
- // });
- // }
- // } tradeProcessFailedCallback:^(NSError * _Nullable error) {
- // // 退出交易流程
- // callback(@{
- // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- // FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
- // // Android没有,所以去掉
- // // FlutterAlibcConstKey_Data:@{
- // // @"orderIdList":[[error userInfo] objectForKey:@"orderIdList"],
- // // }
- // });
- // }];
- // // }
- // //}
- //}
- #pragma mark - 不对flutter暴露 旗舰版
- #pragma mark --打开page 无 AlibcTradePage page
- - (void)OpenPageByNewWayNorpageBizCode:(NSString *)bizCode Call:(FlutterMethodCall *)call callback:(FlutterResult)callback{
-
-
-
- AlibcTradeTaokeParams *taokeParam = [AlibcTradeTaokeParams new];
- NSDictionary *tParams = [call.arguments valueForKey:@"taokeParams"];
- if (tParams) {
- NSString *pid = [tParams valueForKey:@"pid"];
- NSString *unionId = [tParams valueForKey:@"unionId"];
- NSString *subPid = [tParams valueForKey:@"subPid"];
- NSString *materialSourceUrl = [tParams valueForKey:@"materialSourceUrl"];
- NSString *relationId = [tParams valueForKey:@"relationId"];
- NSDictionary *extParams = [tParams valueForKey:@"extParams"];
-
- taokeParam.pid = pid;
- taokeParam.unionId = unionId;
- taokeParam.subPid = subPid;
- taokeParam.materialSourceUrl = materialSourceUrl;
- taokeParam.relationId = relationId;
- taokeParam.extParams = extParams;
- }
- UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
-
-
- NSNumber *schemeType = call.arguments[@"schemeType"];
- NSString *linkKey = [self schemeType:[schemeType intValue]];
- NSString *url = call.arguments[@"url"];
- NSInteger isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] integerValue];
- AlibcTradeUrlParams *urlParams = [AlibcTradeUrlParams new];
- urlParams.id = [call.arguments valueForKey:@"id"];
- urlParams.shopId = [call.arguments valueForKey:@"shopId"];
-
- NSDictionary *bizExtMap = [call.arguments valueForKey:@"bizExtMap"];
- if (bizExtMap && [bizExtMap isKindOfClass:[NSDictionary class]]) {
- urlParams.bizExtMap = bizExtMap;
- }
- NSDictionary *trackParam = [FlutterAlibcTools nullToNil:call.arguments[@"trackParam"]];
-
- AlibcTradeShowParams *showParams = [[AlibcTradeShowParams alloc] init];
- showParams.failMode = 2;//isNeedCustomNativeFailMode;//自定义唤端失败策略 0 打开下载页面 1自定义降级页打开 2不处理
- showParams.isNeedOpenByAliApp = YES;
- showParams.isPushBCWebView = NO;
- showParams.linkKey = linkKey;
- showParams.degradeUrl = @"";//媒体自定义降级url
- [[AlibcTradeUltimateSDK sharedInstance].tradeService
- openTradePageByCode:bizCode
- parentController:rootViewController
- urlParams:urlParams
- showParams:showParams
- taoKeParams:taokeParam
- trackParam:trackParam
- openUrlCallBack:^(NSError *_Nonnull error, NSDictionary *dict) {
- NSLog(@"类型==%@",bizCode);
-
-
-
- if (error) {
- NSLog(@"类型error==%@",error);
- NSDictionary *errorUserInfo=error.userInfo;
- NSString *msgString=[errorUserInfo valueForKey:@"msg"];
- callback(@{
- FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
- FlutterAlibcConstKey_ErrorMessage:msgString,
- });
- } else {
-
-
- }
- }];
- }
- #pragma mark --设置淘客参数
- //- (AlibcTradeTaokeParams *)getTaokeParams:(FlutterMethodCall *)call{
- // AlibcTradeTaokeParams *taoke = [[AlibcTradeTaokeParams alloc] init];
- // if (call.arguments[@"taoKeParams"] == nil || [call.arguments[@"taoKeParams"] isKindOfClass:[NSNull class]]) {
- // return nil;
- // }
- // NSDictionary *taoKeParams = call.arguments[@"taoKeParams"];
- // //taoke.adzoneId = (taoKeParams[@"adzoneId"] == (id) [NSNull null]) ? nil : taoKeParams[@"adzoneId"];
- // taoke.pid = (taoKeParams[@"pid"] == (id) [NSNull null]) ? nil : taoKeParams[@"pid"];
- // //有adzoneId则pid失效
- // taoke.unionId = (taoKeParams[@"unionId"] == (id) [NSNull null]) ? nil : taoKeParams[@"unionId"];
- // taoke.subPid = (taoKeParams[@"subPid"] == (id) [NSNull null]) ? nil : taoKeParams[@"subPid"];
- // // 必须是dic
- // taoke.extParams = (taoKeParams[@"extParams"] == (id) [NSNull null]) ? nil : taoKeParams[@"extParams"];
- //
- // //新加 relationId materialSourceUrl 去掉 adzoneId
- // taoke.relationId = (taoKeParams[@"relationId"] == (id) [NSNull null]) ? nil : taoKeParams[@"relationId"];
- // taoke.materialSourceUrl = (taoKeParams[@"materialSourceUrl"] == (id) [NSNull null]) ? nil : taoKeParams[@"materialSourceUrl"];
- // // 判断这玩意是什么格式,dic就直接赋值,jsoÏn需要转dic
- // // if ([extParams isKindOfClass:[NSDictionary class]]) {
- // // taoke.extParams = extParams;
- // // }else{
- // // 解析字符串
- // // taoke.extParams = [FlutterAlibcTools dictionaryWithJsonString:extParams];
- // // }
- //
- // return taoke;
- //}
- #pragma mark - 转换
- #pragma mark --唤起端失败的策略转换
- //-(AlibcNativeFailMode )NativeFailMode:(int)mode{
- // AlibcNativeFailMode openType=AlibcNativeFailModeJumpH5;
- // switch (mode) {
- // case 0:
- // openType=AlibcNativeFailModeJumpH5;
- // break;
- // case 1:
- // openType=AlibcNativeFailModeJumpDownloadPage;
- // break;
- // case 2:
- // openType=AlibcNativeFailModeNone;
- // break;
- // default:
- // break;
- // }
- // return openType;
- //
- //}
- //唤起类型
- //- (AlibcOpenType)openType:(int)mode{
- //
- // AlibcOpenType openType=AlibcOpenTypeAuto;
- // switch (mode) {
- // case 0:
- // openType=AlibcOpenTypeAuto;
- // break;
- // case 1:
- // openType=AlibcOpenTypeNative;
- // break;
- // default:
- // break;
- // }
- // return openType;
- //}
-
- //打开类型
- -(NSString*)schemeType:(int)mode{
- NSString *linkKey=@"tmall";
- switch (mode) {
- case 0:
- linkKey=@"tmall";
- break;
- case 1:
- linkKey=@"taobao";
- break;
- default:
- break;
- }
- return linkKey;
- }
-
-
-
-
-
-
-
-
-
-
-
-
- /**
- 可设置的参数
- 1.是否同步淘客打点
- 2.是否使用Native支付宝
- 3.是否使用淘客参数(是,需要设置如下参数)
- adzoneId
- pid
- //有adzoneId则pid失效
- unionId
- subPid
- extParams{
- sellerId
- taokeAppkey
- }
- 4.页面打开方式
- 是否唤端 Auto/Native
- 唤起目标应用 淘宝/天猫
- 是否以push的方式打开页面
- 是否绑定webview
- 是否自定义唤端失败策略(若是:H5,DownLoad,None)
- 5.跟踪参数 customParams自定义
- */
- @end
|