智莺生活APP的阿里百川 Flutter 插件
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

265 рядки
8.3 KiB

  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_alibc/albc_tools.dart';
  5. import 'package:flutter_alibc/alibc_const_key.dart';
  6. import 'package:flutter_alibc/alibc_model.dart';
  7. class FlutterAlibc {
  8. // static StreamController<String> _responseTaoKeLoginController = new StreamController.broadcast();
  9. // static Stream<String> get responseFromShare =>
  10. // _responseTaoKeLoginController.stream;
  11. // static Future<dynamic> _handler(MethodCall methodCall) {
  12. // if ("taoKeLogin" == methodCall.method) {
  13. // _responseTaoKeLoginController.sink.add(methodCall.arguments);
  14. // }
  15. // return Future.value(true);
  16. // }
  17. // 通信的桥接类
  18. static final MethodChannel _channel = const MethodChannel("flutter_alibc");
  19. // ..setMethodCallHandler(_handler);
  20. static Future<String> get platformVersion async {
  21. final String version = await _channel.invokeMethod('getPlatformVersion');
  22. return version;
  23. }
  24. ///初始化
  25. ///version:当前app版本
  26. ///appName:当前app名称
  27. ///result:{
  28. /// errorCode, //0为初始化成功,其他为失败
  29. /// errorMessage, //message
  30. ///}
  31. static Future<InitModel> initAlibc({String version, String appName}) async {
  32. Map result = await _channel
  33. .invokeMethod("initAlibc", {"version": version, "appName": appName});
  34. return InitModel(
  35. result[AlibcConstKey.errorCode], result[AlibcConstKey.errorMessage]);
  36. }
  37. ///
  38. /// @description: 登录淘宝
  39. ///
  40. /// @return: 成功则返回的data为用户信息,失败则没有data
  41. ///
  42. static Future<LoginModel> loginTaoBao() async {
  43. Map result = await _channel.invokeMethod("loginTaoBao");
  44. // 判断成功还是失败
  45. if (result[AlibcConstKey.errorCode] != "0") {
  46. return LoginModel(
  47. result[AlibcConstKey.errorCode],
  48. result[AlibcConstKey.errorMessage],
  49. );
  50. }
  51. return LoginModel(
  52. result[AlibcConstKey.errorCode], result[AlibcConstKey.errorMessage],
  53. data: UserModel(
  54. result[AlibcConstKey.data]["nick"],
  55. result[AlibcConstKey.data]["avatarUrl"],
  56. result[AlibcConstKey.data]["openId"],
  57. result[AlibcConstKey.data]["openSid"],
  58. result[AlibcConstKey.data]["topAccessToken"],
  59. result[AlibcConstKey.data]["topAuthCode"]));
  60. }
  61. ///
  62. /// @description: 退出淘宝登录
  63. /// @param {type}
  64. /// @return:
  65. ///
  66. static loginOut() {
  67. _channel.invokeMethod("loginOut");
  68. }
  69. ///
  70. /// @description: 渠道授权,获取access_token
  71. /// @param {type}
  72. /// @return:
  73. /// Map<String,String>
  74. static Future<Map<dynamic, dynamic>> taoKeLogin({
  75. @required String url,
  76. AlibcOpenType openType = AlibcOpenType.AlibcOpenTypeAuto,
  77. bool isNeedCustomNativeFailMode = false,
  78. AlibcNativeFailMode nativeFailMode =
  79. AlibcNativeFailMode.AlibcNativeFailModeNone,
  80. AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTaoBao,
  81. TaokeParams taokeParams,
  82. String backUrl,
  83. }) async {
  84. Map taoKe = AlibcTools.getTaokeMap(taokeParams);
  85. Map result = await _channel.invokeMethod("taoKeLogin", {
  86. "url": url,
  87. "openType": openType.index,
  88. "isNeedCustomNativeFailMode": isNeedCustomNativeFailMode,
  89. "nativeFailMode": nativeFailMode.index,
  90. "schemeType": schemeType.index,
  91. "taokeParams": taoKe,
  92. "backUrl": backUrl
  93. });
  94. return result;
  95. }
  96. ///
  97. /// @description: 通过url打开,包括h5,唤起手淘等
  98. /// @param
  99. /// url:目标url
  100. /// openType:打开类型
  101. /// isNeedCustomNativeFailMode:是否需要设置唤端失败策略
  102. /// nativeFailMode:唤端失败策略
  103. /// schemeType:唤起哪个端
  104. /// taokeParams:淘客数据
  105. /// backUrl: 跳转回来的url
  106. /// @return:
  107. ///
  108. static Future<TradeResult> openByUrl({
  109. @required String url,
  110. AlibcOpenType openType = AlibcOpenType.AlibcOpenTypeAuto,
  111. bool isNeedCustomNativeFailMode = false,
  112. AlibcNativeFailMode nativeFailMode =
  113. AlibcNativeFailMode.AlibcNativeFailModeNone,
  114. AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTmall,
  115. TaokeParams taokeParams,
  116. String backUrl,
  117. bool isAuth=false
  118. }) async {
  119. Map taoKe = AlibcTools.getTaokeMap(taokeParams);
  120. Map result = await _channel.invokeMethod("openByUrl", {
  121. "url": url,
  122. "openType": openType.index,
  123. "isNeedCustomNativeFailMode": isNeedCustomNativeFailMode,
  124. "nativeFailMode": nativeFailMode.index,
  125. "schemeType": schemeType.index,
  126. "taokeParams": taoKe,
  127. "backUrl": backUrl,
  128. "auth":isAuth
  129. });
  130. TradeResult tradeResult = AlibcTools.getTradeResult(result);
  131. return tradeResult;
  132. }
  133. ///
  134. /// @description: 打开商品详情
  135. /// @param
  136. /// 同上
  137. /// itemID 商品id,可以是真实的也可以是混淆的
  138. /// isNeedPush iOS独占
  139. /// @return:
  140. ///
  141. static Future<TradeResult> openItemDetail({
  142. @required String itemID,
  143. // iOS独占
  144. // bool isNeedPush = false,
  145. AlibcOpenType openType = AlibcOpenType.AlibcOpenTypeAuto,
  146. bool isNeedCustomNativeFailMode = false,
  147. AlibcNativeFailMode nativeFailMode =
  148. AlibcNativeFailMode.AlibcNativeFailModeNone,
  149. AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTmall,
  150. TaokeParams taokeParams,
  151. // 额外需要追踪的业务数据
  152. Map trackParam,
  153. String backUrl,
  154. }) async {
  155. Map taoKe = AlibcTools.getTaokeMap(taokeParams);
  156. Map result = await _channel.invokeMethod("openItemDetail", {
  157. "itemID": itemID,
  158. // "isNeedPush": isNeedPush,
  159. "openType": openType.index,
  160. "isNeedCustomNativeFailMode": isNeedCustomNativeFailMode,
  161. "nativeFailMode": nativeFailMode.index,
  162. "schemeType": schemeType.index,
  163. "taokeParams": taoKe,
  164. "trackParam": trackParam,
  165. "backUrl": backUrl
  166. });
  167. TradeResult tradeResult = AlibcTools.getTradeResult(result);
  168. return tradeResult;
  169. }
  170. ///
  171. /// @description: 打开店铺
  172. /// @param {type}
  173. /// shopId 店铺id
  174. /// @return:
  175. ///
  176. static Future<TradeResult> openShop({
  177. @required String shopId,
  178. // iOS独占
  179. // bool isNeedPush = false,
  180. AlibcOpenType openType = AlibcOpenType.AlibcOpenTypeAuto,
  181. bool isNeedCustomNativeFailMode = false,
  182. AlibcNativeFailMode nativeFailMode =
  183. AlibcNativeFailMode.AlibcNativeFailModeNone,
  184. AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTmall,
  185. TaokeParams taokeParams,
  186. // 额外需要追踪的业务数据
  187. Map trackParam,
  188. String backUrl,
  189. }) async {
  190. Map taoKe = AlibcTools.getTaokeMap(taokeParams);
  191. Map result = await _channel.invokeMethod("openShop", {
  192. "shopId": shopId,
  193. // "isNeedPush": isNeedPush,
  194. "openType": openType.index,
  195. "isNeedCustomNativeFailMode": isNeedCustomNativeFailMode,
  196. "nativeFailMode": nativeFailMode.index,
  197. "schemeType": schemeType.index,
  198. "taokeParams": taoKe,
  199. "trackParam": trackParam,
  200. "backUrl": backUrl
  201. });
  202. TradeResult tradeResult = AlibcTools.getTradeResult(result);
  203. return tradeResult;
  204. }
  205. ///
  206. /// @description: 打开购物车
  207. /// @param {type}
  208. /// @return:
  209. ///
  210. static Future<TradeResult> openCart({
  211. // iOS独占
  212. // bool isNeedPush = false,
  213. AlibcOpenType openType = AlibcOpenType.AlibcOpenTypeAuto,
  214. bool isNeedCustomNativeFailMode = false,
  215. AlibcNativeFailMode nativeFailMode =
  216. AlibcNativeFailMode.AlibcNativeFailModeNone,
  217. AlibcSchemeType schemeType = AlibcSchemeType.AlibcSchemeTmall,
  218. TaokeParams taokeParams,
  219. // 额外需要追踪的业务数据
  220. Map trackParam,
  221. String backUrl,
  222. }) async {
  223. Map taoKe = AlibcTools.getTaokeMap(taokeParams);
  224. Map result = await _channel.invokeMethod("openCart", {
  225. // "isNeedPush": isNeedPush,
  226. "openType": openType.index,
  227. "isNeedCustomNativeFailMode": isNeedCustomNativeFailMode,
  228. "nativeFailMode": nativeFailMode.index,
  229. "schemeType": schemeType.index,
  230. "taokeParams": taoKe,
  231. "trackParam": trackParam,
  232. "backUrl": backUrl
  233. });
  234. TradeResult tradeResult = AlibcTools.getTradeResult(result);
  235. return tradeResult;
  236. }
  237. // 是否需要设置打点
  238. static syncForTaoke(bool isSync) {
  239. _channel.invokeMethod("syncForTaoke", {"isSync": isSync});
  240. }
  241. // 是否需要 Native AliPay 接口
  242. static useAlipayNative(bool isNeed) {
  243. _channel.invokeMethod("useAlipayNative", {"isNeed": isNeed});
  244. }
  245. }