智莺生活APP的阿里百川 Flutter 插件
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

190 lignes
7.3 KiB

  1. import 'dart:async';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:flutter_alibc/alibc_const_key.dart';
  5. import 'package:flutter_alibc/flutter_alibc.dart';
  6. import 'package:flutter_alibc/alibc_model.dart';
  7. void main() => runApp(MyApp());
  8. class MyApp extends StatefulWidget {
  9. @override
  10. _MyAppState createState() => _MyAppState();
  11. }
  12. class _MyAppState extends State<MyApp> {
  13. String _platformVersion = 'Unknown';
  14. @override
  15. void initState() {
  16. super.initState();
  17. // FlutterAlibc.responseFromShare.listen((data) {
  18. // debugPrint(data);
  19. // });
  20. initPlatformState();
  21. }
  22. // Platform messages are asynchronous, so we initialize in an async method.
  23. Future<void> initPlatformState() async {
  24. String platformVersion;
  25. // Platform messages may fail, so we use a try/catch PlatformException.
  26. try {
  27. platformVersion = await FlutterAlibc.platformVersion;
  28. } on PlatformException {
  29. platformVersion = 'Failed to get platform version.';
  30. }
  31. // If the widget was removed from the tree while the asynchronous platform
  32. // message was in flight, we want to discard the reply rather than calling
  33. // setState to update our non-existent appearance.
  34. if (!mounted) return;
  35. setState(() {
  36. _platformVersion = platformVersion;
  37. });
  38. /* try {
  39. var initRes = await FlutterAlibc.initAlibc();
  40. } on Exception {}*/
  41. try {
  42. // var waite3s = await FlutterAlibc.openItemDetail(itemID: "12345");
  43. var result = await FlutterAlibc.initAlibc();
  44. print(result);
  45. } on Exception {}
  46. }
  47. @override
  48. Widget build(BuildContext context) {
  49. return MaterialApp(
  50. home: Scaffold(
  51. appBar: AppBar(
  52. title: const Text('Plugin example app'),
  53. ),
  54. body: Center(
  55. child: Column(
  56. children: <Widget>[
  57. FlatButton(
  58. child: Text("初始化阿里百川"),
  59. onPressed: () async {
  60. try {
  61. // var waite3s = await FlutterAlibc.openItemDetail(itemID: "12345");
  62. // 如果什么都不给
  63. var result = await FlutterAlibc.initAlibc();
  64. print("--------------");
  65. print(result.errorMessage+"\n"+result.errorCode);
  66. print("--------------");
  67. } on Exception {}
  68. },
  69. ),
  70. FlatButton(
  71. child: Text("登录淘宝"),
  72. onPressed: () async {
  73. var result = await FlutterAlibc.loginTaoBao();
  74. print("登录淘宝 ${result.data.nick} ${result.data.topAccessToken}");
  75. },
  76. ),
  77. FlatButton(
  78. child: Text("登出淘宝"),
  79. onPressed: () {
  80. FlutterAlibc.loginOut();
  81. },
  82. ),
  83. FlatButton(
  84. child: Text("淘客登录,渠道授权"),
  85. onPressed: () async {
  86. var result = await FlutterAlibc.taoKeLogin(
  87. url:
  88. "https://oauth.taobao.com/authorize?response_type=token&client_id=27646673&state=1212&view=wap",
  89. openType: AlibcOpenType.AlibcOpenTypeNative,
  90. isNeedCustomNativeFailMode: true,
  91. nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  92. print("access token ${result["accessToken"]}");
  93. },
  94. ),
  95. FlatButton(
  96. child: Text("淘客登录,iOS新渠道授权"),
  97. onPressed: () async {
  98. var result = await FlutterAlibc.taoKeLoginNewIOS(
  99. "测试名字",
  100. "31333495"
  101. );
  102. print(result);
  103. print("iOSNEW access token ${result["accessToken"]}");
  104. },
  105. ),
  106. FlatButton(
  107. child: Text("淘客登录,新版渠道授权"),
  108. onPressed: () async {
  109. var result = await FlutterAlibc.taoKeLoginNew(
  110. "测试名字",
  111. "31333495"
  112. );
  113. print(result);
  114. print("access token ${result["accessToken"]}");
  115. },
  116. ),
  117. FlatButton(
  118. child: Text("唤起淘宝,openByUrl方式"),
  119. onPressed: () async {
  120. // var result = await FlutterAlibc.openByUrl(
  121. // url:
  122. // "https://uland.taobao.com/coupon/edetail?e=0I2EBL%2BTWswGQASttHIRqRXxIesJCFV0jSsDEwaP11URqogtr65NL3IIxArmwXZQtYdj3OrQBBwJkllDQLUC%2B79fwBwwUiqlvyfAqbG%2BQWkG6QT52O7rmXYefz8NXcoYTJnbK5InWzlFfSAQOJJoy8NEaV3mm%2FQSzjZt5gElMznom9kMiklcP0KJ92VgfYGd&traceId=0b0d82cf15669814548736276e3d95&union_lens=lensId:0b0b6466_0c0d_16cd75f7c39_528f&xId=6MboRwsAi2s8Glbqt3lJLAwSlyrPyBLCZ01KOk6QzKCNhw8C6RjXgA1bNbZdKzp30gOqd1J5j1k7ei7HYId1QZ&ut_sk=1.utdid_null_1566981455011.TaoPassword-Outside.taoketop&sp_tk=77+lTU5nMllrdHRqSVLvv6U=",
  123. // //backUrl: "tbopen27822502:https://h5.m.taobao.com",
  124. // isNeedCustomNativeFailMode: true,
  125. // nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  126. // print(result);
  127. var result = await FlutterAlibc.openByUrl(
  128. url:
  129. "https://uland.taobao.com/coupon/edetail?e=6DnQrsRPSREE%2BdAb1JoOOq5LjpWhUf47qRfSSxTsETSvx9VYatEri3k%2FkI4P9e8uminGuuGZJpzdRFQjbuovjv5bIHhv8SxDMSEmlRStydiXTYg7jmg8BVVrgdWhx1hjdj3Hchy1wJYuynEbLfMGNjwh43yW%2BFEDaXOtHj5%2BtxsJsGSNF2WC8n3fZUxdvIu5xX4GxHSKO2UqjLJXsGBxMA%3D%3D&traceId=0bb61d4d16186279869833901e8cc1&union_lens=lensId:TAPI@1618627987@212bf943_08cc_178ddbf0639_b2e3@01",
  130. //backUrl: "tbopen27822502:https://h5.m.taobao.com",
  131. isNeedCustomNativeFailMode: true,
  132. nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  133. print(result);
  134. },
  135. ),
  136. FlatButton(
  137. child: Text("唤起淘宝,openItemDetail方式"),
  138. onPressed: () async {
  139. var result = await FlutterAlibc.openItemDetail(
  140. itemID: "575688730394",
  141. schemeType: AlibcSchemeType.AlibcSchemeTaoBao,
  142. isNeedCustomNativeFailMode: true,
  143. nativeFailMode: AlibcNativeFailMode.AlibcNativeFailModeJumpH5);
  144. print(result);
  145. },
  146. ),
  147. FlatButton(
  148. child: Text("打开店铺,openShop方式"),
  149. onPressed: () async {
  150. var result = await FlutterAlibc.openShop(shopId: "71955116");
  151. print(result);
  152. },
  153. ),
  154. FlatButton(
  155. child: Text("打开购物车,openCart方式"),
  156. onPressed: () async {
  157. var result = await FlutterAlibc.openCart();
  158. print(result);
  159. },
  160. ),
  161. FlatButton(
  162. child: Text("允许打点"),
  163. onPressed: () {
  164. FlutterAlibc.syncForTaoke(true);
  165. },
  166. ),
  167. FlatButton(
  168. child: Text("使用native Alipay"),
  169. onPressed: () {
  170. FlutterAlibc.useAlipayNative(true);
  171. },
  172. ),
  173. ],
  174. )),
  175. ),
  176. );
  177. }
  178. }