智莺生活APP的阿里百川 Flutter 插件
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

758 lines
34 KiB

  1. //
  2. // FlutterAlibcHandle.m
  3. // flutter_alibc
  4. //
  5. // Created by 吴兴 on 2019/8/28.
  6. //
  7. #import "FlutterAlibcHandle.h"
  8. #import "FlutterAlibcTools.h"
  9. #import "FlutterAlibcConstKey.h"
  10. //#import <AlibcTradeSDK/AlibcTradeSDK.h>
  11. //#import <AlibabaAuthSDK/albbsdk.h>
  12. #import "ALiTradeWebViewController.h"
  13. #import "FlutterWxViewCtrlViewController.h"
  14. //#import <AlibabaAuthEntrance/ALBBSDK.h>
  15. //#import <AlibabaAuthEntrance/ALBBCompatibleSession.h>
  16. #import "UTDID/UTDevice.h"
  17. //旗舰版
  18. #import <AlibcTradeUltimateSDK/AlibcTradeUltimateSDK.h>
  19. //// 媒体电商套件图片库协议实现
  20. //#import "ALITradeDemoImageLoader.h"
  21. //#import <WindmillWeaver/WMLHandlerFactory.h>
  22. //// 电商套件外跳媒体页面实现
  23. //
  24. //#import <AlibcTradeContainer/AlibcTradeMiniAppURLRouter.h>
  25. //
  26. //#import <AlibcTradeUltimateBizSDK/AlibcTradeShowParams.h>
  27. //#import <AlibcTradeUltimateSDK/AlibcTradeUltimateSDKService.h>
  28. //#import <AlibcTradeUltimateBizSDK/AlibcTradeUrlParams.h>
  29. //
  30. //
  31. //#import <AlibcTradeUltimateBizSDK/AlibcTradeTaokeParams.h>
  32. #import <AlibcTradeContainer/AlibcTradeContainer.h>
  33. #import <WindmillWeaver/WMLImageLoaderProtocol.h>
  34. #import <WindmillWeaver/WMLHandlerFactory.h>
  35. #import <WindmillWeaver/TRVZipArchiveProtocol.h>
  36. #import <WindmillWeaver/WMLHandlerFactory.h>
  37. #import <WindmillWeaver/TRVZipArchiveProtocol.h>
  38. #import "FNALITradeZipArchiver.h"
  39. @interface FlutterAlibcHandle ()
  40. //// 图片库实现
  41. //@property (nonatomic,strong)ALITradeDemoImageLoader *imageLoaderImp;
  42. //
  43. //// 外跳路由协议实现
  44. //@property (nonatomic,strong)ALiTradeDemoURLHandler *urlHandlerImp;
  45. @end
  46. @implementation FlutterAlibcHandle
  47. FlutterMethodChannel *_flutterAlibcChannel = nil;
  48. - (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar methodChannel:(FlutterMethodChannel *)flutterMethodChannel {
  49. self = [super init];
  50. if (self) {
  51. _flutterAlibcChannel = flutterMethodChannel;
  52. }
  53. return self;
  54. }
  55. #pragma mark- 对flutter暴露的方法
  56. #pragma mark -- 初始化阿里百川
  57. - (void)initAlibc:(FlutterMethodCall *)call result:(FlutterResult)result {
  58. // 百川平台基础SDK初始化,加载并初始化各个业务能力插件
  59. NSString *version = call.arguments[@"version"];
  60. NSString *appName = call.arguments[@"appName"];
  61. // 判断是否为空
  62. // if(![FlutterAlibcTools isNil:version]){
  63. // [[AlibcTradeSDK sharedInstance] setIsvVersion:version]; //设置三方App版本,可用于标识App版本
  64. // }
  65. // if(![FlutterAlibcTools isNil:appName]){
  66. // [[AlibcTradeSDK sharedInstance] setIsvAppName:appName]; //设置三方App名称,可用于标识App
  67. // }
  68. // [[AlibcTradeSDK sharedInstance] setDebugLogOpen:YES];//开发阶段打开日志开关,方便排查错误信息
  69. // [[AlibcTradeSDK sharedInstance] setEnv:AlibcEnvironmentRelease];//线上环境
  70. //
  71. //
  72. // [[AlibcTradeSDK sharedInstance] asyncInitWithSuccess:^{
  73. // // 告诉flutter,初始化完成
  74. // result(@{FlutterAlibcConstKey_ErrorCode:@"0",FlutterAlibcConstKey_ErrorMessage:@"success"});
  75. // } failure:^(NSError *error) {
  76. // NSLog(@"Init failed: %@", error.description);
  77. // result(@{FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],FlutterAlibcConstKey_ErrorMessage:error.description});
  78. // }];
  79. __weak typeof(self) weakSelf = self;
  80. // // 打开日志开关
  81. [[AlibcTradeUltimateSDK sharedInstance] setDebugLogOpen:YES];
  82. [[AlibcTradeUltimateSDK sharedInstance] asyncInitWithSuccess:^{
  83. NSLog(@"百川初始化成功");
  84. __strong typeof(self) self = weakSelf;
  85. [[AlibcTradeUltimateSDK sharedInstance] setDebugLogOpen:YES];
  86. [[AlibcTradeMiniAppURLRouter sharedInstance] addMiniAppRouterListener:self];
  87. [WMLHandlerFactory registerHandler:self withProtocol:@protocol(WMLImageLoaderProtocol)];
  88. [WMLHandlerFactory registerHandler:[FNALITradeZipArchiver new] withProtocol:@protocol(TRVZipArchiveProtocol)];
  89. #ifdef DEBUG
  90. //必须在百川初始化成功之后调用,开启自检工具的悬浮入口
  91. [[AlibcTradeUltimateSDK sharedInstance] enableAutoShowDebug:YES];
  92. [[AlibcTradeUltimateSDK sharedInstance] setDebugLogOpen:YES];
  93. #endif
  94. } failure:^(NSError * _Nonnull error) {
  95. NSLog(@"百川初始化失败");
  96. }];
  97. }
  98. #pragma mark --淘宝登录
  99. - (void)loginTaoBao:(FlutterMethodCall *)call result:(FlutterResult)result{
  100. // if(![[ALBBCompatibleSession sharedInstance] isLogin]) {
  101. // UIViewController *rootViewController =
  102. // [UIApplication sharedApplication].delegate.window.rootViewController;
  103. // [[ALBBSDK sharedInstance] setH5Only:NO];
  104. // [[ALBBSDK sharedInstance] auth:rootViewController successCallback:^{
  105. // ALBBUser *userInfo =[[ALBBCompatibleSession sharedInstance] getUser];
  106. // // 登录成功
  107. // result(@{
  108. // FlutterAlibcConstKey_ErrorCode:@"0",
  109. // FlutterAlibcConstKey_ErrorMessage:@"success",
  110. // FlutterAlibcConstKey_Data:@{
  111. // // 昵称
  112. // @"nick":userInfo.nick,
  113. // // 头像地址
  114. // @"avatarUrl":userInfo.avatarUrl,
  115. // @"openId":userInfo.openId,
  116. // @"openSid":userInfo.openSid,
  117. // @"topAccessToken":userInfo.topAccessToken,
  118. // @"topAuthCode":userInfo.topAuthCode,
  119. // }
  120. // });
  121. // } failureCallback:^(NSError *error) {
  122. // // 登录失败
  123. // result(@{
  124. // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  125. // FlutterAlibcConstKey_ErrorMessage:error.localizedDescription,
  126. // FlutterAlibcConstKey_Data:@{}
  127. // });
  128. // }];
  129. //
  130. // } else {
  131. // ALBBUser *userInfo =[[ALBBCompatibleSession sharedInstance] getUser];
  132. // // 登录成功
  133. // result(@{
  134. // FlutterAlibcConstKey_ErrorCode:@"0",
  135. // FlutterAlibcConstKey_ErrorMessage:@"success",
  136. // FlutterAlibcConstKey_Data:@{
  137. // // 昵称
  138. // @"nick":userInfo.nick,
  139. // // 头像地址
  140. // @"avatarUrl":userInfo.avatarUrl,
  141. // @"openId":userInfo.openId,
  142. // @"openSid":userInfo.openSid,
  143. // @"topAccessToken":userInfo.topAccessToken,
  144. // @"topAuthCode":userInfo.topAuthCode,
  145. // }
  146. // });
  147. // }
  148. NSLog(@"授权登录信息==%@",call.arguments);
  149. if (![[[AlibcTradeUltimateSDK sharedInstance] loginService] isLogin]) {
  150. UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  151. [[[AlibcTradeUltimateSDK sharedInstance] loginService] setH5Only:NO];
  152. [[[AlibcTradeUltimateSDK sharedInstance] loginService] auth:rootViewController success:^(AlibcUser *user) {
  153. NSLog(@"登录成功");
  154. result(@{FlutterAlibcConstKey_ErrorCode:@"0",
  155. FlutterAlibcConstKey_ErrorMessage:@"success",
  156. FlutterAlibcConstKey_Data:@{
  157. // 昵称
  158. @"nick":user.nick,
  159. // 头像地址
  160. @"avatarUrl":user.avatarUrl,
  161. @"openId":user.openId,
  162. @"openSid":user.openSid,
  163. @"topAccessToken":@"",
  164. @"topAuthCode":@"",
  165. }
  166. });
  167. //无 topAccessToken topAuthCode
  168. } failure:^(NSError *error) {
  169. NSLog(@"登录失败");
  170. result(@{
  171. FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  172. FlutterAlibcConstKey_ErrorMessage:error.localizedDescription,
  173. FlutterAlibcConstKey_Data:@{}
  174. });
  175. }];
  176. } else {
  177. AlibcUser *user = [[[AlibcTradeUltimateSDK sharedInstance] loginService] getUser];
  178. NSLog(@"已登录");
  179. result(@{
  180. FlutterAlibcConstKey_ErrorCode:@"0",
  181. FlutterAlibcConstKey_ErrorMessage:@"success",
  182. FlutterAlibcConstKey_Data:@{
  183. @"nick":user.nick,
  184. @"avatarUrl":user.avatarUrl,
  185. @"openId":user.openId,
  186. @"openSid":user.openSid,
  187. @"topAccessToken":@"",
  188. @"topAuthCode":@"",
  189. }
  190. });
  191. }
  192. }
  193. //
  194. //else if([@"useAlipayNative" isEqualToString:call.method]){
  195. // [_handler useAlipayNative:call result:result];
  196. //}
  197. #pragma mark --淘客登录
  198. -(void)taoKeLogin:(FlutterMethodCall *)call result:(FlutterResult)result{
  199. // 需要获取的数据
  200. // NSNumber *type1 = call.arguments[@"openType"];
  201. // AlibcOpenType openType = [self openType:[type1 intValue]];
  202. // BOOL isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] boolValue];
  203. // // 不用push了,没有nav,默认都present
  204. // // BOOL isNeedPush = [call.arguments[@"isNeedPush"] boolValue];
  205. // BOOL isNeedPush = YES;
  206. // NSNumber *failMode = call.arguments[@"nativeFailMode"];
  207. // AlibcNativeFailMode nativeFailMode = [self NativeFailMode:[failMode intValue]];
  208. // NSNumber *schemeType = call.arguments[@"schemeType"];
  209. // NSString *linkKey = [self schemeType:[schemeType intValue]];
  210. // NSString *url = call.arguments[@"url"];
  211. // AlibcTradeTaokeParams *taokeParam = [self getTaokeParams:call];
  212. // NSDictionary *trackParam = call.arguments[@"trackParam"];
  213. // NSString *backUrl = [FlutterAlibcTools changeType:call.arguments[@"backUrl"]];
  214. // // NSString *backUrl = [FlutterAlibcTools nullToNil:call.arguments[@"backUrl"]];
  215. //
  216. // UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  217. //
  218. //
  219. // AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  220. // showParam.openType = openType;
  221. // showParam.isNeedCustomNativeFailMode = isNeedCustomNativeFailMode;
  222. // showParam.isNeedPush=isNeedPush;
  223. // showParam.nativeFailMode=nativeFailMode;
  224. // showParam.linkKey=linkKey;
  225. // showParam.backUrl= backUrl;
  226. //
  227. // ALiTradeWebViewController* webviewVC = [[ALiTradeWebViewController alloc] init];
  228. //
  229. // NSInteger res = [[AlibcTradeSDK sharedInstance].tradeService
  230. // openByUrl:url
  231. // identity:@"trade"
  232. // webView:webviewVC.webView
  233. // parentController:rootViewController
  234. // showParams:showParam
  235. // taoKeParams:taokeParam
  236. // trackParam:trackParam tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable alibcTradeResult) {
  237. // // // 交易成功,判断是付款成功还是加入购物车
  238. // // if(alibcTradeResult.result == AlibcTradeResultTypePaySuccess){
  239. // // // 付款成功
  240. // // result(@{
  241. // // FlutterAlibcConstKey_ErrorCode:@"0",
  242. // // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
  243. // // FlutterAlibcConstKey_Data:@{
  244. // // @"type":@0,
  245. // // @"paySuccessOrders":[alibcTradeResult payResult].paySuccessOrders,
  246. // // @"payFailedOrders":[alibcTradeResult payResult].payFailedOrders,
  247. // // }
  248. // // });
  249. // // }else if(alibcTradeResult.result== AlibcTradeResultTypeAddCard){
  250. // // // 加入购物车
  251. // // result(@{
  252. // // FlutterAlibcConstKey_ErrorCode:@"0",
  253. // // FlutterAlibcConstKey_ErrorMessage:@"加入购物车成功",
  254. // // FlutterAlibcConstKey_Data:@{
  255. // // @"type":@1,
  256. // // }
  257. // // });
  258. // // }
  259. // } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  260. // // result(@{
  261. // // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  262. // // FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
  263. // // });
  264. // }];
  265. //
  266. // if (res == 1) {
  267. // // 新建一个view
  268. // FlutterWxViewCtrlViewController *WxVC = [[FlutterWxViewCtrlViewController alloc] init];
  269. // WxVC.vc = webviewVC;
  270. // WxVC.accessBlock = ^(NSString * accessToken){
  271. // NSLog(@"accessToken = %@",accessToken);
  272. // if (accessToken) {
  273. // result(@{
  274. // @"accessToken":accessToken
  275. // });
  276. // }else{
  277. // result(@{
  278. // @"accessToken":@""
  279. // });
  280. // }
  281. //
  282. // };
  283. // UINavigationController *root = [[UINavigationController alloc] initWithRootViewController:WxVC];
  284. // [rootViewController presentViewController:root animated:NO completion:^{
  285. //
  286. // }];
  287. // }
  288. NSLog(@"淘客登录信息==%@",call.arguments);
  289. UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  290. // [[AlibcTradeUltimateSDK sharedInstance] showLocalDebugTool:rootViewController];
  291. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  292. NSString *app_NameXT = [infoDictionary objectForKey:@"CFBundleName"];
  293. NSString *appLogo=@"app_icon";
  294. // [[AlibcTradeUltimateSDK sharedInstance].tradeService authorize4AppName:app_NameXT appLogo:[UIImage imageNamed:appLogo] currentVC:rootViewController callBack:^(NSError *error, NSString *accessToken, NSString *expire) {
  295. // NSLog(@"淘客登录accessToken==%@",accessToken);
  296. // NSLog(@"淘客登录expire==%@",expire);
  297. // NSLog(@"淘客登录error==%@",error);
  298. // NSLog(@"accessToken = %@",accessToken);
  299. // if (accessToken) {
  300. // result(@{
  301. // @"accessToken":accessToken
  302. // });
  303. // }else{
  304. // result(@{
  305. // @"accessToken":@""
  306. // });
  307. // }
  308. // }];
  309. //32271226
  310. NSString *AppKey=call.arguments[@"alibcAppKey"];
  311. NSString *appName = call.arguments[@"name"];
  312. [[AlibcTradeUltimateSDK sharedInstance].tradeService authorize4AppKey:AppKey appName:app_NameXT appLogo:[UIImage imageNamed:appLogo] currentVC:rootViewController callBack:^(NSError *error, NSString *accessToken, NSString *expire) {
  313. NSLog(@"淘客登录accessToken==%@",accessToken);
  314. NSLog(@"淘客登录expire==%@",expire);
  315. NSLog(@"淘客登录error==%@",error);
  316. NSLog(@"accessToken = %@",accessToken);
  317. if (accessToken) {
  318. result(@{
  319. @"accessToken":accessToken
  320. });
  321. }else{
  322. result(@{
  323. @"accessToken":@""
  324. });
  325. }
  326. }];
  327. }
  328. #pragma mark --退出登录
  329. - (void)loginOut{
  330. //[[ALBBSDK sharedInstance] logout];
  331. [[[AlibcTradeUltimateSDK sharedInstance] loginService] logout];
  332. }
  333. #pragma mark --通过url打开,包括h5,唤起手淘等
  334. - (void)openByUrl:(FlutterMethodCall *)call result:(FlutterResult)result{
  335. NSLog(@"h5MSG==%@",call.arguments);
  336. NSNumber *schemeType = call.arguments[@"schemeType"];
  337. NSString *linkKey = [self schemeType:[schemeType intValue]];
  338. NSString *url = call.arguments[@"url"];
  339. NSInteger isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] integerValue];
  340. //ALiTradeWebViewController* webviewVC = [[ALiTradeWebViewController alloc] init];
  341. AlibcTradeShowParams *showParams = [[AlibcTradeShowParams alloc] init];
  342. showParams.failMode = isNeedCustomNativeFailMode;//isNeedCustomNativeFailMode;//自定义唤端失败策略 0 打开下载页面 1自定义降级页打开 2不处理
  343. //AlibcOpenAliAppDownloadPage = 0,
  344. //AlibcOpenInAppByCustomerDegradeUrl = 1,
  345. //AlibcOpenDoNothing = 2
  346. showParams.isNeedOpenByAliApp = YES;
  347. showParams.isPushBCWebView = YES;
  348. showParams.linkKey = linkKey;
  349. //showParams.degradeUrl = url;//媒体自定义降级url
  350. UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  351. //AlibcTradeTaokeParams *taokeParam = [self getTaokeParams:call];
  352. AlibcTradeTaokeParams *taokeParam = [AlibcTradeTaokeParams new];
  353. taokeParam.pid = [call.arguments valueForKey:@"pid"];
  354. taokeParam.unionId = [call.arguments valueForKey:@"unionId"];
  355. taokeParam.subPid = [call.arguments valueForKey:@"subPid"];
  356. taokeParam.relationId = [call.arguments valueForKey:@"relationId"];
  357. taokeParam.materialSourceUrl = [call.arguments valueForKey:@"materialSourceUrl"];
  358. taokeParam.extParams = [call.arguments valueForKey:@"extParams"];
  359. NSDictionary *trackParam = [call.arguments valueForKey:@"trackParam"];
  360. [[AlibcTradeUltimateSDK sharedInstance].tradeService openTradeUrl:url
  361. parentController:rootViewController
  362. showParams:showParams
  363. taoKeParams:taokeParam
  364. trackParam:trackParam
  365. openUrlCallBack:^(NSError *error, NSDictionary *dict) {
  366. NSLog(@"error==%@",error);
  367. NSLog(@"dict==%@",dict);
  368. if(error){
  369. result(@{
  370. FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  371. FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
  372. });
  373. }else{
  374. }
  375. }];
  376. }
  377. #pragma mark --打开商品详情
  378. - (void)openItemDetail:(FlutterMethodCall *)call result:(FlutterResult)result{
  379. NSString *itemID = call.arguments[@"itemID"];
  380. NSLog(@"打开商品详情==%@",call.arguments);
  381. //id<AlibcTradePage> page = [AlibcTradePageFactory itemDetailPage:itemID];
  382. //[self OpenPageByNewWay:page BizCode:@"detail" Call:call callback:result];
  383. [self OpenPageByNewWayNorpageBizCode:@"detail" Call:call callback:result];
  384. }
  385. #pragma mark --打开店铺
  386. - (void)openShop:(FlutterMethodCall *)call result:(FlutterResult)result{
  387. NSString *shopId = call.arguments[@"shopId"];
  388. NSLog(@"打开店铺==%@",call.arguments);
  389. //id<AlibcTradePage> page = [AlibcTradePageFactory shopPage:shopId];
  390. //[self OpenPageByNewWay:page BizCode:@"shop" Call:call callback:result];
  391. [self OpenPageByNewWayNorpageBizCode:@"shop" Call:call callback:result];
  392. }
  393. #pragma mark --打开我的购物车
  394. - (void)openCart:(FlutterMethodCall *)call result:(FlutterResult)result{
  395. NSLog(@"打开我的购物车==%@",call.arguments);
  396. //id<AlibcTradePage> page = [AlibcTradePageFactory myCartsPage];
  397. //[self OpenPageByNewWay:page BizCode:@"cart" Call:call callback:result];
  398. [self OpenPageByNewWayNorpageBizCode:@"cart" Call:call callback:result];
  399. }
  400. //
  401. #pragma mark --淘客打点
  402. - (void)syncForTaoke:(FlutterMethodCall *)call result:(FlutterResult)result{
  403. BOOL isSync = [call.arguments[@"isSync"] boolValue];
  404. //[[AlibcTradeSDK sharedInstance] setIsSyncForTaoke:isSync];
  405. }
  406. #pragma mark --设置是否需要 Native AliPay 接口
  407. - (void)useAlipayNative:(FlutterMethodCall *)call result:(FlutterResult)result{
  408. BOOL isNeed = [call.arguments[@"isNeed"] boolValue];
  409. //[[AlibcTradeSDK sharedInstance] setShouldUseAlizfNative:isNeed];
  410. }
  411. //获取udid
  412. - (void)getUdid:(FlutterMethodCall *)call result:(FlutterResult)result{
  413. NSUUID *identifierForVendor = [[UIDevice currentDevice] identifierForVendor];
  414. NSDictionary* map=@{@"udid" : [UTDevice utdid]};
  415. result(map);
  416. }
  417. #pragma mark - 不对flutter暴露
  418. #pragma mark --打开page
  419. //- (void)OpenPageByNewWay:(id<AlibcTradePage>)page BizCode:(NSString *)bizCode Call:(FlutterMethodCall *)call callback:(FlutterResult)callback{
  420. // AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
  421. // NSNumber *type1 = call.arguments[@"openType"];
  422. // AlibcOpenType openType = [self openType:[type1 intValue]];
  423. // BOOL isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] boolValue];
  424. // // 不用push了,没有nav,默认都present
  425. // // BOOL isNeedPush = [call.arguments[@"isNeedPush"] boolValue];
  426. // BOOL isNeedPush = NO;
  427. // // 不用绑定了,默认为没有,有的话flutter太难搞了
  428. // // BOOL isBindWebview = [call.arguments[@"isBindWebview"] boolValue];
  429. // NSNumber *failMode = call.arguments[@"nativeFailMode"];
  430. // AlibcNativeFailMode nativeFailMode = [self NativeFailMode:[failMode intValue]];
  431. // NSNumber *schemeType = call.arguments[@"schemeType"];
  432. // NSString *linkKey = [self schemeType:[schemeType intValue]];
  433. // AlibcTradeTaokeParams *taokeParam = [self getTaokeParams:call];
  434. // NSDictionary *trackParam = [FlutterAlibcTools nullToNil:call.arguments[@"trackParam"]];
  435. //
  436. // NSString *backUrl = [FlutterAlibcTools changeType:call.arguments[@"backUrl"]];
  437. // // 判断
  438. //
  439. // UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  440. //
  441. // showParam.openType = openType;
  442. // showParam.isNeedPush = isNeedPush;
  443. // showParam.nativeFailMode = nativeFailMode;
  444. // showParam.isNeedCustomNativeFailMode = isNeedCustomNativeFailMode;
  445. // showParam.linkKey = linkKey;
  446. // showParam.backUrl = backUrl;
  447. //
  448. //
  449. // // if (isBindWebview) {
  450. // // ALiTradeWebViewController *viewCtrl = [[ALiTradeWebViewController alloc]init];
  451. // // 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];
  452. // // }else{
  453. // // if (isNeedPush) {
  454. // // [[AlibcTradeSDK sharedInstance].tradeService openByBizCode:bizCode page:page webView:nil parentController:rootViewController showParams:showParam taoKeParams:taokeParam trackParam:trackParam tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  455. // //// 交易成功,判断是付款成功还是加入购物车
  456. // // if(result.result == AlibcTradeResultTypePaySuccess){
  457. // //// 付款成功
  458. // // callback(@{
  459. // // FlutterAlibcConstKey_ErrorCode:@"0",
  460. // // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
  461. // // FlutterAlibcConstKey_Data:@{
  462. // // @"type":@0,
  463. // // @"paySuccessOrders":[result payResult].paySuccessOrders,
  464. // // @"payFailedOrders":[result payResult].payFailedOrders,
  465. // // }
  466. // // });
  467. // // }else if(result.result== AlibcTradeResultTypeAddCard){
  468. // //// 加入购物车
  469. // // callback(@{
  470. // // FlutterAlibcConstKey_ErrorCode:@"0",
  471. // // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
  472. // // FlutterAlibcConstKey_Data:@{
  473. // // @"type":@1,
  474. // // }
  475. // // });
  476. // // }
  477. // // } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  478. // //// 退出交易流程
  479. // // callback(@{
  480. // // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  481. // // FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
  482. // // FlutterAlibcConstKey_Data:@{
  483. // // @"orderIdList":[[error userInfo] objectForKey:@"orderIdList"],
  484. // // }
  485. // // });
  486. // // }];
  487. // // }else{
  488. // [[AlibcTradeSDK sharedInstance].tradeService openByBizCode:bizCode page:page webView:nil parentController:rootViewController showParams:showParam taoKeParams:taokeParam trackParam:trackParam tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
  489. // // 交易成功,判断是付款成功还是加入购物车
  490. // if(result.result == AlibcTradeResultTypePaySuccess){
  491. // // 付款成功
  492. // callback(@{
  493. // FlutterAlibcConstKey_ErrorCode:@"0",
  494. // FlutterAlibcConstKey_ErrorMessage:@"付款成功",
  495. // FlutterAlibcConstKey_Data:@{
  496. // @"type":@0,
  497. // @"paySuccessOrders":[result payResult].paySuccessOrders,
  498. // @"payFailedOrders":[result payResult].payFailedOrders,
  499. // }
  500. // });
  501. // }else if(result.result== AlibcTradeResultTypeAddCard){
  502. // // 加入购物车
  503. // callback(@{
  504. // FlutterAlibcConstKey_ErrorCode:@"0",
  505. // FlutterAlibcConstKey_ErrorMessage:@"加入购物车成功",
  506. // FlutterAlibcConstKey_Data:@{
  507. // @"type":@1,
  508. // }
  509. // });
  510. // }
  511. // } tradeProcessFailedCallback:^(NSError * _Nullable error) {
  512. // // 退出交易流程
  513. // callback(@{
  514. // FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  515. // FlutterAlibcConstKey_ErrorMessage:[error localizedDescription],
  516. // // Android没有,所以去掉
  517. // // FlutterAlibcConstKey_Data:@{
  518. // // @"orderIdList":[[error userInfo] objectForKey:@"orderIdList"],
  519. // // }
  520. // });
  521. // }];
  522. // // }
  523. // //}
  524. //}
  525. #pragma mark - 不对flutter暴露 旗舰版
  526. #pragma mark --打开page 无 AlibcTradePage page
  527. - (void)OpenPageByNewWayNorpageBizCode:(NSString *)bizCode Call:(FlutterMethodCall *)call callback:(FlutterResult)callback{
  528. AlibcTradeTaokeParams *taokeParam = [AlibcTradeTaokeParams new];
  529. NSDictionary *tParams = [call.arguments valueForKey:@"taokeParams"];
  530. if (tParams) {
  531. NSString *pid = [tParams valueForKey:@"pid"];
  532. NSString *unionId = [tParams valueForKey:@"unionId"];
  533. NSString *subPid = [tParams valueForKey:@"subPid"];
  534. NSString *materialSourceUrl = [tParams valueForKey:@"materialSourceUrl"];
  535. NSString *relationId = [tParams valueForKey:@"relationId"];
  536. NSDictionary *extParams = [tParams valueForKey:@"extParams"];
  537. taokeParam.pid = pid;
  538. taokeParam.unionId = unionId;
  539. taokeParam.subPid = subPid;
  540. taokeParam.materialSourceUrl = materialSourceUrl;
  541. taokeParam.relationId = relationId;
  542. taokeParam.extParams = extParams;
  543. }
  544. UIViewController *rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
  545. NSNumber *schemeType = call.arguments[@"schemeType"];
  546. NSString *linkKey = [self schemeType:[schemeType intValue]];
  547. NSString *url = call.arguments[@"url"];
  548. NSInteger isNeedCustomNativeFailMode = [call.arguments[@"isNeedCustomNativeFailMode"] integerValue];
  549. AlibcTradeUrlParams *urlParams = [AlibcTradeUrlParams new];
  550. urlParams.id = [call.arguments valueForKey:@"id"];
  551. urlParams.shopId = [call.arguments valueForKey:@"shopId"];
  552. NSDictionary *bizExtMap = [call.arguments valueForKey:@"bizExtMap"];
  553. if (bizExtMap && [bizExtMap isKindOfClass:[NSDictionary class]]) {
  554. urlParams.bizExtMap = bizExtMap;
  555. }
  556. NSDictionary *trackParam = [FlutterAlibcTools nullToNil:call.arguments[@"trackParam"]];
  557. AlibcTradeShowParams *showParams = [[AlibcTradeShowParams alloc] init];
  558. showParams.failMode = 2;//isNeedCustomNativeFailMode;//自定义唤端失败策略 0 打开下载页面 1自定义降级页打开 2不处理
  559. showParams.isNeedOpenByAliApp = YES;
  560. showParams.isPushBCWebView = NO;
  561. showParams.linkKey = linkKey;
  562. showParams.degradeUrl = @"";//媒体自定义降级url
  563. [[AlibcTradeUltimateSDK sharedInstance].tradeService
  564. openTradePageByCode:bizCode
  565. parentController:rootViewController
  566. urlParams:urlParams
  567. showParams:showParams
  568. taoKeParams:taokeParam
  569. trackParam:trackParam
  570. openUrlCallBack:^(NSError *_Nonnull error, NSDictionary *dict) {
  571. NSLog(@"类型==%@",bizCode);
  572. if (error) {
  573. NSLog(@"类型error==%@",error);
  574. NSDictionary *errorUserInfo=error.userInfo;
  575. NSString *msgString=[errorUserInfo valueForKey:@"msg"];
  576. callback(@{
  577. FlutterAlibcConstKey_ErrorCode:[NSString stringWithFormat: @"%ld", (long)error.code],
  578. FlutterAlibcConstKey_ErrorMessage:msgString,
  579. });
  580. } else {
  581. }
  582. }];
  583. }
  584. #pragma mark --设置淘客参数
  585. //- (AlibcTradeTaokeParams *)getTaokeParams:(FlutterMethodCall *)call{
  586. // AlibcTradeTaokeParams *taoke = [[AlibcTradeTaokeParams alloc] init];
  587. // if (call.arguments[@"taoKeParams"] == nil || [call.arguments[@"taoKeParams"] isKindOfClass:[NSNull class]]) {
  588. // return nil;
  589. // }
  590. // NSDictionary *taoKeParams = call.arguments[@"taoKeParams"];
  591. // //taoke.adzoneId = (taoKeParams[@"adzoneId"] == (id) [NSNull null]) ? nil : taoKeParams[@"adzoneId"];
  592. // taoke.pid = (taoKeParams[@"pid"] == (id) [NSNull null]) ? nil : taoKeParams[@"pid"];
  593. // //有adzoneId则pid失效
  594. // taoke.unionId = (taoKeParams[@"unionId"] == (id) [NSNull null]) ? nil : taoKeParams[@"unionId"];
  595. // taoke.subPid = (taoKeParams[@"subPid"] == (id) [NSNull null]) ? nil : taoKeParams[@"subPid"];
  596. // // 必须是dic
  597. // taoke.extParams = (taoKeParams[@"extParams"] == (id) [NSNull null]) ? nil : taoKeParams[@"extParams"];
  598. //
  599. // //新加 relationId materialSourceUrl 去掉 adzoneId
  600. // taoke.relationId = (taoKeParams[@"relationId"] == (id) [NSNull null]) ? nil : taoKeParams[@"relationId"];
  601. // taoke.materialSourceUrl = (taoKeParams[@"materialSourceUrl"] == (id) [NSNull null]) ? nil : taoKeParams[@"materialSourceUrl"];
  602. // // 判断这玩意是什么格式,dic就直接赋值,jsoÏn需要转dic
  603. // // if ([extParams isKindOfClass:[NSDictionary class]]) {
  604. // // taoke.extParams = extParams;
  605. // // }else{
  606. // // 解析字符串
  607. // // taoke.extParams = [FlutterAlibcTools dictionaryWithJsonString:extParams];
  608. // // }
  609. //
  610. // return taoke;
  611. //}
  612. #pragma mark - 转换
  613. #pragma mark --唤起端失败的策略转换
  614. //-(AlibcNativeFailMode )NativeFailMode:(int)mode{
  615. // AlibcNativeFailMode openType=AlibcNativeFailModeJumpH5;
  616. // switch (mode) {
  617. // case 0:
  618. // openType=AlibcNativeFailModeJumpH5;
  619. // break;
  620. // case 1:
  621. // openType=AlibcNativeFailModeJumpDownloadPage;
  622. // break;
  623. // case 2:
  624. // openType=AlibcNativeFailModeNone;
  625. // break;
  626. // default:
  627. // break;
  628. // }
  629. // return openType;
  630. //
  631. //}
  632. //唤起类型
  633. //- (AlibcOpenType)openType:(int)mode{
  634. //
  635. // AlibcOpenType openType=AlibcOpenTypeAuto;
  636. // switch (mode) {
  637. // case 0:
  638. // openType=AlibcOpenTypeAuto;
  639. // break;
  640. // case 1:
  641. // openType=AlibcOpenTypeNative;
  642. // break;
  643. // default:
  644. // break;
  645. // }
  646. // return openType;
  647. //}
  648. //打开类型
  649. -(NSString*)schemeType:(int)mode{
  650. NSString *linkKey=@"tmall";
  651. switch (mode) {
  652. case 0:
  653. linkKey=@"tmall";
  654. break;
  655. case 1:
  656. linkKey=@"taobao";
  657. break;
  658. default:
  659. break;
  660. }
  661. return linkKey;
  662. }
  663. /**
  664. 可设置的参数
  665. 1.是否同步淘客打点
  666. 2.是否使用Native支付宝
  667. 3.是否使用淘客参数(是,需要设置如下参数)
  668. adzoneId
  669. pid
  670. //有adzoneId则pid失效
  671. unionId
  672. subPid
  673. extParams{
  674. sellerId
  675. taokeAppkey
  676. }
  677. 4.页面打开方式
  678. 是否唤端 Auto/Native
  679. 唤起目标应用 淘宝/天猫
  680. 是否以push的方式打开页面
  681. 是否绑定webview
  682. 是否自定义唤端失败策略(若是:H5,DownLoad,None)
  683. 5.跟踪参数 customParams自定义
  684. */
  685. @end