基础库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

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