基础库
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

215 lines
7.4 KiB

  1. import 'package:dio/dio.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_alibc/flutter_alibc.dart';
  4. import 'package:jdsdk/jdsdk.dart';
  5. import 'package:url_launcher/url_launcher.dart';
  6. import 'package:zhiying_comm/register.dart';
  7. import 'package:zhiying_comm/util/shared_prefe_util.dart';
  8. import 'package:zhiying_comm/zhiying_comm.dart';
  9. import 'taobao_image_viewer.dart';
  10. void main() => runApp(MyApp());
  11. class MyApp extends StatefulWidget {
  12. @override
  13. _MyAppState createState() => _MyAppState();
  14. }
  15. class _MyAppState extends State<MyApp> {
  16. @override
  17. void initState() {
  18. BaseWidgetRegister.init();
  19. Jdsdk.init(
  20. appKey: '9fc3dec00b9b40cc950dfba5262cd6d3',
  21. appSecret: 'f785613e5fd54a129d0f0359a4e25c23')
  22. .then((result) {
  23. Logger.debug('京东初始化:${result.toString()}');
  24. });
  25. FlutterAlibc.initAlibc(version: "", appName: "").then((result) {
  26. Logger.debug('${result.errorCode} ${result.errorMessage}');
  27. });
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return MaterialApp(
  33. home: HomePage(),
  34. );
  35. }
  36. }
  37. class HomePage extends StatelessWidget {
  38. netPost() async {
  39. dynamic result =
  40. await NetUtil.post('/api/v1/rec/featured?page=1', params: null);
  41. print("result === ${result?.toString()}");
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. return Scaffold(
  46. appBar: AppBar(
  47. title: const Text('智莺-基础库'),
  48. ),
  49. body: SingleChildScrollView(
  50. child: Center(
  51. child: Wrap(
  52. spacing: 10,
  53. children: <Widget>[
  54. RaisedButton(
  55. onPressed: () {
  56. // d75d2fc6592f4526e297643446416581bd89e837
  57. // cc455e0c0b6a75ff09aeb966c211fb967d69b63d
  58. SharedPreferencesUtil.setStringValue(
  59. GlobalConfig.SHARED_KEY_TOKEN,
  60. 'd75d2fc6592f4526e297643446416581bd89e837');
  61. },
  62. child: Text('登录'),
  63. ),
  64. RaisedButton(
  65. onPressed: () {
  66. SharedPreferencesUtil.setStringValue(
  67. GlobalConfig.SHARED_KEY_TOKEN, '');
  68. },
  69. child: Text('退出登录'),
  70. ),
  71. RaisedButton(
  72. onPressed: () {
  73. NetUtil.request('/api/v1/rec/featured?page=1', params: null,
  74. onError: (msg) {
  75. print('onERROR = ${msg?.toString() ?? 'onError'}');
  76. }, onSuccess: (json) {
  77. print('onSuccess = ${json?.toString() ?? 'onSuccess'}');
  78. }, onCache: (json) {
  79. print('onCache = ${json?.toString() ?? 'onCache'}');
  80. });
  81. },
  82. child: Text('网络异步请求(带缓存)'),
  83. ),
  84. RaisedButton(
  85. onPressed: () {
  86. netPost();
  87. },
  88. child: Text('网络同步请求(无缓存)'),
  89. ),
  90. RaisedButton(
  91. onPressed: () {
  92. // LogUtil.test();
  93. },
  94. child: Text('显示日志'),
  95. ),
  96. RaisedButton(
  97. onPressed: () {
  98. Navigator.push(context, MaterialPageRoute(builder: (_) {
  99. return Logger();
  100. }));
  101. },
  102. child: Text('打开日志视图'),
  103. ),
  104. RaisedButton(
  105. onPressed: () {
  106. // NetUtil.request('/api/v1/mod', params: {'ids': [6] } ,method: NetMethod.POST,
  107. // onSuccess: (params){
  108. // Logger.log("onSuccess#$params");
  109. // },
  110. // onCache: (params){
  111. // Logger.log("onCache#$params");
  112. // });
  113. testPost();
  114. },
  115. child: Text('测试接口'),
  116. ),
  117. RaisedButton(
  118. onPressed: () {
  119. Navigator.push(context, MaterialPageRoute(builder: (_) {
  120. return TaobaoImageView();
  121. }));
  122. },
  123. child: Text('抓淘宝图片'),
  124. ),
  125. RaisedButton(
  126. onPressed: () {
  127. TaobaoAuth.auth(context);
  128. },
  129. child: Text('淘宝授权'),
  130. ),
  131. RaisedButton(
  132. onPressed: () {
  133. //
  134. Dio dio = Dio();
  135. dio.get(
  136. 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html')
  137. .then((value) {
  138. Logger.debug(value.realUri.toString());
  139. });
  140. },
  141. child: Text('获取重定向地址'),
  142. ),
  143. RaisedButton(
  144. onPressed: () {
  145. Jdsdk.openUrl(
  146. url: 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html');
  147. },
  148. child: Text('打开京东详情'),
  149. ),
  150. RaisedButton(
  151. onPressed: () async {
  152. // String detailUrl = 'http://www.hairuyi.com/?mod=appapi&act=gotojingdong&gid=60291609161&yhq_url=http%3A%2F%2Fcoupon.m.jd.com%2Fcoupons%2Fshow.action%3Fkey%3Dd97e1472a8a24c39a9463dbe72b3fa32%26roleId%3D38088450%26to%3Ditem.jd.com%2F60291609161.html';
  153. // String baseUrl = detailUrl.getBaseUrl();
  154. // if (!baseUrl.contains('jd.com')) {
  155. // Dio dio = Dio();
  156. // var responds = await dio.get(detailUrl);
  157. // detailUrl = responds.realUri.toString();
  158. // }
  159. // Logger.debug(detailUrl);
  160. // Jdsdk.openUrl(
  161. // url
  162. // :
  163. // detailUrl
  164. // );
  165. },
  166. child: Text('嗨如意转链打开京东'),
  167. ),
  168. RaisedButton(
  169. onPressed: () async {
  170. const url = 'weixin://';
  171. if (await canLaunch(url)) {
  172. await launch(url);
  173. } else {
  174. throw 'Could not launch $url';
  175. }
  176. },
  177. child: Text('url scheme打开app'),
  178. ),
  179. RaisedButton(
  180. onPressed: () async {
  181. Logger.error('打印日志测试');
  182. },
  183. child: Text('打印日志'),
  184. ),
  185. ],
  186. ),
  187. ),
  188. ),
  189. );
  190. }
  191. void testPost() async {
  192. var cached = await NetUtil.getRequestCachedData('/api/v1/mod', params: {
  193. 'ids': [7]
  194. });
  195. print("cahced ${cached?.toString()}");
  196. var param = await NetUtil.post('/api/v1/mod',
  197. params: {
  198. 'ids': [7]
  199. },
  200. method: NetMethod.POST);
  201. print('apapapsdjfdsjf: ${param?.toString()}');
  202. }
  203. }